31namespace LinguisticProcessing
44 std::shared_ptr<Lima::Common::AbstractAccessByString>
keys;
63 std::vector<LevelDico> m_dicos;
65 uint64_t m_mainKeySize;
87 LINFO <<
"init MultiLevelAnalysisDictionary";
88 auto language = manager->getInitializationParameters().language;
90 m_d->m_mainKeySize = 0;
95 if (accesses.size() != data.size())
98 QTextStream qts(&errorString);
99 qts <<
"accessKeys and dictionaryValuesFiles do not have the same number of entries for language "
104 auto keyIt = accesses.cbegin(), dataIt = data.cbegin();
105 auto hasMainKeys =
false;
106 for (; keyIt!=accesses.end() && dataIt!=data.end();)
108 LINFO <<
"load LevelDictionary : key=" << *keyIt <<
" data=" << *dataIt;
110 auto aar = std::dynamic_pointer_cast<AbstractAccessResource>(res);
113 ldico.
keys = aar->getAccessByString();
115 if (aar->isMainKeys())
118 m_d->m_mainKeySize = ldico.
keys->getSize();
124 m_d->m_dicos.push_back(ldico);
128 if ((keyIt!=accesses.end()) || (dataIt!=data.end()))
131 QTextStream qts(&errorString);
132 qts <<
"missing keys or data in configuration for MultiLevelAnalysisDictionary ! for language "
140 QTextStream qts(&errorString);
141 qts <<
"no accessKeys are main keys (stringspool keys) in MultiLevelAnalysisDictionary for language "
150 QTextStream qts(&errorString);
151 qts <<
"no param 'accessKeys' in MultiLevelAnalysisDictionary group for language "
160 StringsPoolIndex form(0);
161 std::vector<uint64_t> indexes;
162 for (
const auto& dico: m_d->m_dicos)
164 indexes.push_back(dico.keys->getIndex(word));
175 const auto& csp = *m_d->m_sp;
183 std::vector<uint64_t> indexes;
184 for (
const auto& dico : m_d->m_dicos)
188 if (wordId < m_d->m_mainKeySize)
190 indexes.push_back(wordId);
194 indexes.push_back(0);
199 indexes.push_back(dico.keys->getIndex(word));
208 LDEBUG <<
"MultiLevelAnalysisDictionary::getEntry" << indexes.size();
209 auto indexItr = indexes.cbegin();
210 for (
auto dicoItr = m_d->m_dicos.cbegin();
211 (indexItr != indexes.cend()) && (dicoItr != m_d->m_dicos.cend());
212 indexItr++, dicoItr++)
214 if (dicoItr->mainKeys)
219 Q_ASSERT(indexItr!=indexes.end());
222 return getEntry(
static_cast<StringsPoolIndex
>(*indexItr), indexes);
225 indexItr = indexes.cbegin();
226 StringsPoolIndex form(0);
227 for (
auto dicoItr = m_d->m_dicos.cbegin();
228 (indexItr != indexes.end()) && (dicoItr != m_d->m_dicos.end());
229 indexItr++, dicoItr++)
233 form = (*m_d->m_sp)[dicoItr->keys->getSpelling(*indexItr)];
241 const std::vector<uint64_t>& indexes)
const
246 std::vector<MultiLevelAnalysisDictionaryEntry::LevelData> entryData;
250 auto hasLing =
false;
251 auto hasAccented =
false;
252 auto hasConcat =
false;
254 auto indexIt = indexes.cbegin();
255 auto dicoIt = m_d->m_dicos.cbegin();
257 for (;indexIt != indexes.end() && dicoIt != m_d->m_dicos.end() && !
final;
260 LDEBUG <<
"read level " << dicoIt->id <<
" : entry index = " << *indexIt;
261 auto p = dicoIt->data->getEntryAddr(*indexIt);
263 LDEBUG <<
"read " << read;
273 LDEBUG <<
"entry is empty";
278 LDEBUG <<
"entry has length " << read;
286 LDEBUG <<
"info length = " << read;
291 LDEBUG <<
"accented length = " << read;
300 LDEBUG <<
"concat length = " << read;
311 data.
keys = dicoIt->keys;
313 entryData.push_back(data);
315 return DictionaryEntry(std::make_shared<MultiLevelAnalysisDictionaryEntry>(form,
326 const int offset,
const LimaString& key)
const
329 std::vector<std::pair<Common::AccessSubWordIterator,Common::AccessSubWordIterator> > accessItrs;
330 for (
const auto& dico : m_d->m_dicos)
332 accessItrs.push_back(dico.keys->getSubWords(offset, key));
336 std::vector<std::pair<Common::AccessSubWordIterator,Common::AccessSubWordIterator> > accessItrsEnd(accessItrs);
337 for (
auto& accessItr : accessItrsEnd)
339 accessItr.first = accessItr.second;
342 return std::pair< DictionarySubWordIterator, DictionarySubWordIterator >(
352 std::cerr <<
"unimplemented method at "<<__FILE__<<
", line "<<__LINE__<< std::endl;
360 std::cerr <<
"unimplemented method at "<<__FILE__<<
", line "<<__LINE__<< std::endl;
367 return m_d->m_dicos.size();
#define ANALYSISDICTLOGINIT
#define MULTILEVELANALYSISDICTIONARY_CLASSID
Defines a Factory to create Object of type Base.
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'list' was not found
Use this exception to signal an error in one of the configuration files.
interface for analysis dictionary
static uint64_t readCodedInt(unsigned char *&p)
void loadBinaryFile(const std::string &file)
virtual ~MultiLevelAnalysisDictionary()
virtual std::pair< DictionarySuperWordIterator, DictionarySuperWordIterator > getSuperWordEntries(const LimaString &key) const override
return superword entries A superword entry is an entry that begins with the given key
uint64_t getDictionaryCount() const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
virtual std::pair< DictionarySubWordIterator, DictionarySubWordIterator > getSubWordEntries(const int offset, const LimaString &key) const override
return subword entries A subword entry is a word in the key string that begin at the given offset.
virtual DictionaryEntry getEntry(const Lima::LimaString &word) const override
get dictionary entry for a word
virtual uint64_t getSize() const override
return number of keys in dictionary
MultiLevelAnalysisDictionary()
static const LinguisticResources & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
QString findFileInPaths(const QString &paths, const QString &fileName, const QChar &separator)
Find the given file in the given paths.
SimpleFactory< AbstractResource, MultiLevelAnalysisDictionary > multiLevelAnalysisDictionaryFactory(MULTILEVELANALYSISDICTIONARY_CLASSID)
std::shared_ptr< Lima::Common::AbstractAccessByString > keys
std::shared_ptr< Lima::Common::AbstractAccessByString > keys
const DictionaryData * dicoData
unsigned char * endEntryData
unsigned char * startEntryData
launch exception related to the configuration file parsing