LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DictionaryEntry.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
16// <dictionaryEntry> ::= <Len0> <infos>
17// <infos> ::= <lingInfo> [<accented> [<idiomatic> [<hyphenLingInfo>
18// [<concatenated> [<byDefault> ]]]]]
19// <byDefault> ::= <LingPropertiesOffset>
20// <concatenated> ::= <Len3> { <concatenatedEntry> }
21// <concatenatedEntry> ::= <Len9> { <Component> <dictionaryEntry> }
22// <lingInfo> ::= <Len1> { <lingInfoEntry> }
23// <hyphenLingInfo> ::= <Len1> { <lingInfoEntry> }
24// <lingInfoEntry> ::= <Len4> <lemma> <normalized> <LingPropertiesOffset>
25// <lemma> ::= <0> | <StringOffset>
26// <normalized> ::= <0> | <StringOffset>
27// <accented> ::= <Len2> { <accentedEntry> }
28// <accentedEntry> ::= <StringOffset>
29// <idiomatic> ::= <len11> { <IdiomaticEntry> }
30// <lingProperties> ::= <Len7> { <LingPropertyEntry> }
32
33#include "DictionaryEntry.h"
34
36#include <memory.h>
37#include <iostream>
38
39using namespace Lima::Common::Misc;
40
41namespace Lima {
42namespace LinguisticProcessing {
43namespace Dictionary {
44
45
49 m_key(),
50 m_stringStartAddr(NULL),
51 m_lingPropertiesStartAddr(NULL),
52 m_startAddr(NULL),
53 m_endAddr(NULL),
54 m_lingInfo(NULL),
55 m_endLingInfo(NULL),
56 m_accented(NULL),
57 m_endAccented(NULL),
58 m_idiomatic(NULL),
59 m_endIdiomatic(NULL),
60 m_hyphenLingInfo(NULL),
61 m_endHyphenLingInfo(NULL),
62 m_concatenated(NULL),
63 m_endConcatenated(NULL),
64 m_byDefault(NULL),
65 m_endByDefault(NULL),
66 m_hasLingInfo(false),
67 m_hasAccented(false),
68 m_hasIdiomatic(false),
69 m_hasHyphenLingInfo(false),
70 m_hasConcatenated(false),
71 m_hasDefaultProperty(false)
72{
73}
74
80 m_key(entry.m_key),
81 m_stringStartAddr(entry.m_stringStartAddr),
82 m_lingPropertiesStartAddr(entry.m_lingPropertiesStartAddr),
83 m_startAddr(NULL),
84 m_endAddr(NULL),
85 m_lingInfo(NULL),
86 m_endLingInfo(NULL),
87 m_accented(NULL),
88 m_endAccented(NULL),
89 m_idiomatic(NULL),
90 m_endIdiomatic(NULL),
91 m_hyphenLingInfo(NULL),
92 m_endHyphenLingInfo(NULL),
93 m_concatenated(NULL),
94 m_endConcatenated(NULL),
95 m_byDefault(NULL),
96 m_endByDefault(NULL),
97 m_hasLingInfo(false),
98 m_hasAccented(false),
99 m_hasIdiomatic(false),
100 m_hasHyphenLingInfo(false),
101 m_hasConcatenated(false),
102 m_hasDefaultProperty(false)
103{
104 if (entry.m_startAddr != NULL) {
105 uint64_t entrySize = entry.m_endAddr - entry.m_startAddr;
106 m_startAddr = new unsigned char[entrySize];
107 memcpy(m_startAddr, entry.m_startAddr, entrySize);
108 reset();
109 }
110}
111
113 unsigned char *stringStartAddr,
114 unsigned char *lingPropertiesStartAddr,
115 unsigned char *startAddr) :
116 BinaryEntry(),
117 m_key(key),
118 m_stringStartAddr(stringStartAddr),
119 m_lingPropertiesStartAddr(lingPropertiesStartAddr),
120 m_startAddr(NULL),
121 m_endAddr(NULL),
122 m_lingInfo(NULL),
123 m_endLingInfo(NULL),
124 m_accented(NULL),
125 m_endAccented(NULL),
126 m_idiomatic(NULL),
127 m_endIdiomatic(NULL),
128 m_hyphenLingInfo(NULL),
129 m_endHyphenLingInfo(NULL),
130 m_concatenated(NULL),
131 m_endConcatenated(NULL),
132 m_byDefault(NULL),
133 m_endByDefault(NULL),
134 m_hasLingInfo(false),
135 m_hasAccented(false),
136 m_hasIdiomatic(false),
137 m_hasHyphenLingInfo(false),
138 m_hasConcatenated(false),
139 m_hasDefaultProperty(false)
140{
141 if (startAddr != NULL) {
142 unsigned char *ptr = startAddr;
143 uint64_t num = getEncodedNumber(ptr);
144 unsigned char *endAddr = num + ptr;
145 uint64_t entrySize = endAddr - startAddr;
146 m_startAddr = new unsigned char[entrySize];
147 memcpy(m_startAddr, startAddr, entrySize);
148 reset();
149 }
150}
151
155{
156 delete[] m_startAddr;
157}
158
164 BinaryEntry::operator=(dictionaryEntry);
165 m_key = dictionaryEntry.m_key;
166 m_stringStartAddr = dictionaryEntry.m_stringStartAddr;
167 m_lingPropertiesStartAddr = dictionaryEntry.m_lingPropertiesStartAddr;
168 delete[] m_startAddr;
169 m_startAddr = NULL;
170 if (dictionaryEntry.m_startAddr != NULL)
171{
172 uint64_t entrySize = dictionaryEntry.m_endAddr - dictionaryEntry.m_startAddr;
173 m_startAddr = new unsigned char[entrySize];
174 memcpy(m_startAddr, dictionaryEntry.m_startAddr, entrySize);
175 reset();
176 }
177 return *this;
178}
179
185{
186 m_endAddr = NULL;
187 m_lingInfo = NULL;
188 m_endLingInfo = NULL;
189 m_accented = NULL;
190 m_endAccented = NULL;
191 m_idiomatic = NULL;
192 m_endIdiomatic = NULL;
193 m_hyphenLingInfo = NULL;
194 m_endHyphenLingInfo = NULL;
195 m_concatenated = NULL;
196 m_endConcatenated = NULL;
197 m_byDefault = NULL;
198 m_endByDefault = NULL;
199 m_hasLingInfo = false;
200 m_hasAccented = false;
201 m_hasIdiomatic = false;
202 m_hasHyphenLingInfo = false;
203 m_hasConcatenated = false;
204 m_hasDefaultProperty = false;
205 if (m_startAddr != NULL) {
206 unsigned char *ptr = m_startAddr;
207 uint64_t num = getEncodedNumber(ptr);
208 m_endAddr = num + ptr; // <Len0>
209 if (ptr < m_endAddr) {
210 uint64_t num = getEncodedNumber(ptr);
211 m_endLingInfo = num + ptr; // <Len1>
212 m_lingInfo = ptr;
213 m_hasLingInfo = (m_endLingInfo > m_lingInfo);
214 ptr = m_endLingInfo;
215 if (ptr < m_endAddr) {
216 uint64_t num = getEncodedNumber(ptr);
217 m_endAccented = num + ptr; // <Len2>
218 m_accented = ptr;
219 m_hasAccented = (m_endAccented > m_accented);
220 ptr = m_endAccented;
221 if (ptr < m_endAddr) {
222 uint64_t num = getEncodedNumber(ptr);
223 m_endIdiomatic = num + ptr; // <Len11>
224 m_idiomatic = ptr;
225 m_hasIdiomatic = (m_endIdiomatic > m_idiomatic);
226 ptr = m_endIdiomatic;
227 if (ptr < m_endAddr) {
228 uint64_t num = getEncodedNumber(ptr);
229 m_endHyphenLingInfo = num + ptr;// <Len1>
230 m_hyphenLingInfo = ptr;
231 m_hasHyphenLingInfo = (m_endHyphenLingInfo > m_hyphenLingInfo);
232 ptr = m_endHyphenLingInfo;
233 if (ptr < m_endAddr) {
234 uint64_t num = getEncodedNumber(ptr);
235 m_endConcatenated = num + ptr;// <Len3>
236 m_concatenated = ptr;
237 m_hasConcatenated = (m_endConcatenated > m_concatenated);
238 ptr = m_endConcatenated;
239 if (ptr < m_endAddr) {
240 uint64_t offset = getEncodedNumber(ptr); //<LingPropertiesOffset>
241 ptr = m_lingPropertiesStartAddr + offset;
242 if (offset == 0) // when no ling properties
243 {
244 m_endByDefault = ptr;
245 }
246 else
247 {
248 uint64_t num = getEncodedNumber(ptr);
249 m_endByDefault = num + ptr; //<Len7>
250 }
251 m_byDefault = ptr;
252 m_hasDefaultProperty = (m_endByDefault > m_byDefault);
253 }
254 }
255 }
256 }
257 }
258 }
259 }
260 return *this;
261}
262
266 return (m_startAddr == NULL);
267}
268
274 if (m_startAddr == NULL) throw EmptyEntryException();
275 if (m_lingInfo < m_endLingInfo) {
276 unsigned char *lingInfo = m_lingInfo;
277 nextField(m_lingInfo);
278 return LingInfoEntry(m_key, m_stringStartAddr, m_lingPropertiesStartAddr, lingInfo);
279 }
280 else
281 return LingInfoEntry();
282}
283
289 if (m_startAddr == NULL) throw EmptyEntryException();
290 if (m_accented < m_endAccented) {
291 return getUtf8StringNoMove(m_stringStartAddr + getEncodedNumber(m_accented));
292 }
293 else
294 return Lima::LimaString();
295}
296
302 if (m_startAddr == NULL) throw EmptyEntryException();
303 if (m_idiomatic < m_endIdiomatic)
304 return getEncodedNumber(m_idiomatic) + 1; // 0 is prohibited
305 else
306 return 0;
307}
308
314 if (m_startAddr == NULL) throw EmptyEntryException();
315 if (m_hyphenLingInfo < m_endHyphenLingInfo) {
316 unsigned char *hyphenLingInfo = m_hyphenLingInfo;
317 nextField(m_hyphenLingInfo);
318 return LingInfoEntry(m_key, m_stringStartAddr, m_lingPropertiesStartAddr, hyphenLingInfo);
319 }
320 else
321 return LingInfoEntry();
322}
323
329 if (m_startAddr == NULL) throw EmptyEntryException();
330 if (m_concatenated < m_endConcatenated)
331 {
332 unsigned char *concatenated = m_concatenated;
333 nextField(m_concatenated);
334 return ConcatenatedEntry(concatenated, m_stringStartAddr);
335 }
336 else
337 {
338 return ConcatenatedEntry();
339 }
340}
341
347{
348 if (m_startAddr == NULL)
349 {
350 throw EmptyEntryException();
351 }
352 if (m_byDefault < m_endByDefault)
353 {
355 }
356 else
357 {
358 return LingPropertyEntry();
359 }
360}
361
362} //closing namespace Dictionary
363} //closing namespace LinguisticProcessing
364} //closing namespace Lima
static LinguisticCode decodeFromBinary(std::istream &is)
Definition StdBitset.h:197
uint64_t getEncodedNumber(unsigned char *&ptr) const
BinaryEntry & operator=(const BinaryEntry &entry)
unsigned char * nextField(unsigned char *&ptr) const
Lima::LimaString getUtf8StringNoMove(unsigned char *ptr) const
LingInfoEntry nextHyphenLingInfo()
Gets the next hyphen LingInfoEntry if exists This call "increments" the internal hyphen LingInfoEntry...
DictionaryEntry & operator=(const DictionaryEntry &)
Assignment operator.
DictionaryEntry & reset()
Reset internal iteration pointers of self.
ConcatenatedEntry nextConcatenated()
Gets the next ConcatenatedEntry if exists This call "increments" the internal ConcatenatedEntry point...
LingPropertyEntry nextLingProperty()
Gets the next LingPropertyEntry if exists This call "increments" the internal LingPropertyEntry point...
uint64_t nextIdiomatic()
Gets the next idiomatic entry if exists This call "increments" the internal idiomatic entry pointer.
Lima::LimaString nextAccented()
Gets the next accented entry if exists This call "increments" the internal accented entry pointer.
LingInfoEntry nextLingInfo()
Gets the next LingInfoEntry if exists This call "increments" the internal LingInfoEntry pointer.
bool isEmpty() const
Returns true if self is empty.
NAUTITIA.
QString LimaString
Definition LimaString.h:33