24namespace LinguisticProcessing {
25namespace AnalysisDict {
49 std::shared_ptr<Lima::Common::AbstractAccessByString>
keys;
96 std::shared_ptr<Lima::Common::AbstractAccessByString>
keys;
135 std::shared_ptr<Lima::Common::AbstractAccessByString>
keys;
168 const std::vector<MultiLevelAnalysisDictionaryEntry::LevelData>& data,
179 std::vector<MultiLevelAnalysisDictionaryEntry::LevelData> m_data;
186 StringsPoolIndex formId,
190 bool hasConcatenated,
191 bool hasAccentedForm,
192 const std::vector<LevelData>& data,
229 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseAccentedForms";
234 std::vector<AccentedLevelState> state;
235 for (
const auto& ld : m_d->m_data)
240 curState.
pos = ld.startEntryData;
241 assert(curState.
pos != ld.endEntryData);
244 curState.
pos += read;
245 if (curState.
pos != ld.endEntryData)
253 curState.
keys = ld.keys;
257 curState.
next(*m_d->m_sp);
259 state.push_back(curState);
267 auto* lowerState = &state.front();
268 auto final = lowerState->final;
269 auto hasInfo = !lowerState->final;
270 for (
auto& als : state)
272 if (als < *lowerState)
277 else if (als == *lowerState)
286 if (lowerState->end())
298 std::vector<LingInfoLevelState> liStates;
299 std::vector<ConcatenatedLevelState> concatStates;
300 auto finalReached =
false;
301 for (
const auto& als : state)
303 if (als == *lowerState)
305 finalReached = finalReached || als.final;
309 auto acc = als.dicoData->getEntryAddr(als.accentedEntry);
314 LWARN <<
"WARNING ! should never accentuate to a delete entry !";
321 LWARN <<
"WARNING ! should never accentuate to a empty entry !";
323 auto accEnd = acc+tmp;
330 curState.
posEnd = acc + tmp;
334 curState.
keys = als.keys;
338 curState.
next(*m_d->m_sp);
340 liStates.push_back(curState);
356 curState.
posEnd = acc+tmp;
360 curState.
keys = als.keys;
364 curState.
next(*m_d->m_sp);
366 concatStates.push_back(curState);
369 assert(acc == accEnd);
382 for (
auto& als : state)
384 if (als == *lowerState)
386 als.next(*m_d->m_sp);
400 std::vector<ConcatenatedLevelState> state;
402 for (
const auto& ld : m_d->m_data)
407 curState.
pos = ld.startEntryData;
408 assert(curState.
pos != ld.endEntryData);
412 curState.
pos += read;
413 if (curState.
pos != ld.endEntryData)
417 curState.
pos += read;
418 if (curState.
pos != ld.endEntryData)
426 curState.
keys = ld.keys;
430 curState.
next(*m_d->m_sp);
432 state.push_back(curState);
448 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos initialize entry reading";
454 std::vector<LingInfoLevelState> states;
455 for (
const auto& ld : m_d->m_data)
460 curState.
pos = ld.startEntryData;
466 curState.
keys = ld.keys;
470 curState.
next(*m_d->m_sp);
472 states.push_back(curState);
518 if (
currentNorm ==
static_cast<StringsPoolIndex
>(0))
543 LDEBUG <<
"LingInfoLevelState::next on OUT:" << (
void*)
pos << (
void*)
posEnd
560 if (lis.
end())
return true;
561 if (
end())
return false;
572 std::vector<LingInfoLevelState>& states,
576 if (states.empty())
return;
580 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos IN";
586 auto* lowerState = &states.front();
588 auto hasInfos =
false;
590 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos find lower state. state size="
593 for (
auto& state : states)
596 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos next level is at state lemma="
599 if (state < *lowerState)
602 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos is lower !";
605 hasInfos = (lowerState->lingInfoOffset !=0);
606 final = lowerState->final;
608 else if (state == *lowerState)
611 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos stateItr == lowerState";
613 if (!
final && state.lingInfoOffset != 0)
620 if (lowerState->end())
624 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos nothing more to read, exit";
629 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos lowerState found lemma="
630 << lowerState->lemmaStr <<
", norm=" << lowerState->normStr;
635 handler->
deleteLingInfos(lowerState->currentLemma, lowerState->currentNorm);
640 handler->
foundLingInfos(lowerState->currentLemma, lowerState->currentNorm);
642 bool finalReached =
false;
643 std::set<LinguisticCode> propsRead;
644 for (
auto& state : states)
647 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos in second states loop. lemma="
648 << state.lemmaStr <<
", norm=" << state.normStr;
650 if (state == *lowerState)
653 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos stateItr == lowerState !";
658 finalReached = state.final;
659 if (state.lingInfoOffset != 0)
662 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos read level info";
664 if (state.lingInfoOffset != 0)
666 auto props = state.dicoData->getLingPropertiesAddr(state.lingInfoOffset);
668 auto propsEnd = props + read;
669 while (props!=propsEnd)
673 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos got linguistic code" << l.toString();
675 if (propsRead.find(l) == propsRead.end())
683 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseLingInfos ling properties already read in previous dictionary !";
705 LDEBUG <<
"ConcatenatedLevelState::next" << (
void*)
pos << (
void*)
posEnd;
722 for (uint64_t nb = read; nb > 0; nb--)
729 c.formStr =
keys->getSpelling(c.form);
732 c.form = sp[c.formStr];
741 c.liState.posEnd =
pos;
745 c.liState.keys =
keys;
761 std::vector<ConcatenatedLevelState>& state,
767 LDEBUG <<
"parseConcatenated";
769 if (state.empty())
return;
776 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseConcatenated find lower concat state";
778 auto* lowerState = &state.front();
780 auto hasInfos =
false;
781 for (
auto& cls : state)
784 LDEBUG <<
"state has " << cls.components.size() <<
" components";
786 if (cls < *lowerState)
793 hasInfos = (cls.components.front().liState.lingInfoOffset != 0);
795 else if (cls == *lowerState)
798 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseConcatenated stateItr == lowerState";
802 if (!cls.components.empty()
803 && cls.components.front().liState.lingInfoOffset != 0)
815 if (lowerState->end())
820 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseConcatenated read infos";
826 for (
const auto& component : lowerState->components)
828 handler->
foundComponent(component.pos, component.len, component.form);
832 auto finalReached =
false;
836 std::vector<std::pair<std::vector<ConcatenatedLevelState::Component>::iterator,
837 std::vector<ConcatenatedLevelState::Component>::iterator> > componentsIt;
838 for (
auto& cls : state)
840 if (cls == *lowerState)
843 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseConcatenated stateItr == lowerState";
847 componentsIt.push_back(std::make_pair(cls.components.begin(),
848 cls.components.end()));
858 LDEBUG <<
"MultiLevelAnalysisDictionaryEntry::parseConcatenated read the "
859 << componentsIt.size() <<
" level iterators";
862 while (componentsIt.front().first != componentsIt.front().second)
865 componentsIt.front().first->len,
866 componentsIt.front().first->form);
867 std::vector<LingInfoLevelState> lingInfoState;
868 for (
auto& component : componentsIt)
870 assert(component.first != component.second);
871 lingInfoState.push_back(component.first->liState);
872 component.first.operator++();
880 for (
auto& cls : state)
882 if (cls == *lowerState)
936 if (as.
end())
return true;
937 if (
end())
return false;
#define ANALYSISDICTLOGINIT
static LinguisticCode decodeFromBinary(std::istream &is)
virtual void endComponent()
virtual void endLingInfos()
virtual void foundComponent(uint64_t position, uint64_t length, StringsPoolIndex form)
virtual void foundProperties(LinguisticCode lings)
virtual void deleteAccentedForm(StringsPoolIndex form)
virtual void endConcatenated()
virtual void endAccentedForm()
virtual void foundConcatenated()
virtual void foundAccentedForm(StringsPoolIndex form)
virtual void deleteLingInfos(StringsPoolIndex lemma, StringsPoolIndex norm)
virtual void deleteConcatenated()
virtual void startEntry(StringsPoolIndex form)
virtual void foundLingInfos(StringsPoolIndex lemma, StringsPoolIndex norm)
StringsPoolIndex m_entryId
LimaString accentedFormStr
AccentedLevelState(const AccentedLevelState &)=default
std::shared_ptr< Lima::Common::AbstractAccessByString > keys
bool operator==(const AccentedLevelState &lis) const
void next(FsaStringsPool &sp)
StringsPoolIndex accentedEntry
bool operator<(const AccentedLevelState &lis) const
StringsPoolIndex accentedForm
const DictionaryData * dicoData
~AccentedLevelState()=default
AccentedLevelState & operator=(const AccentedLevelState &)=default
Component(const Component &)=default
bool operator<(const Component &c) const
Component & operator=(const Component &)=default
LingInfoLevelState liState
bool operator==(const Component &c) const
~ConcatenatedLevelState()=default
ConcatenatedLevelState(const ConcatenatedLevelState &)=default
bool operator<(const ConcatenatedLevelState &cls) const
bool operator==(const ConcatenatedLevelState &cls) const
std::vector< Component > components
void next(FsaStringsPool &sp)
ConcatenatedLevelState & operator=(const ConcatenatedLevelState &)=default
const DictionaryData * dicoData
ConcatenatedLevelState()=default
std::shared_ptr< Lima::Common::AbstractAccessByString > keys
static uint64_t readCodedInt(unsigned char *&p)
void next(FsaStringsPool &sp)
std::shared_ptr< Lima::Common::AbstractAccessByString > keys
bool operator==(const LingInfoLevelState &lis) const
StringsPoolIndex currentNorm
StringsPoolIndex currentLemma
LingInfoLevelState(const LingInfoLevelState &)=default
~LingInfoLevelState()=default
bool operator<(const LingInfoLevelState &lis) const
const DictionaryData * dicoData
LingInfoLevelState & operator=(const LingInfoLevelState &)=default
MultiLevelAnalysisDictionaryEntry(StringsPoolIndex formId, bool isFinal, bool isEmpty, bool hasLingInfos, bool hasConcatenated, bool hasAccentedForm, const std::vector< LevelData > &data, Lima::FsaStringsPool *sp)
virtual void parseConcatenated(AbstractDictionaryEntryHandler *handler) const override
virtual AbstractDictionaryEntry * clone() override
virtual void parseLingInfos(AbstractDictionaryEntryHandler *handler) const override
MultiLevelAnalysisDictionaryEntry & operator=(const MultiLevelAnalysisDictionaryEntry &)
virtual void parseAccentedForms(AbstractDictionaryEntryHandler *handler) const override
void parseConcatenated(std::vector< ConcatenatedLevelState > &data, Lima::FsaStringsPool *sp, AbstractDictionaryEntryHandler *handler)
void parseLingInfos(std::vector< LingInfoLevelState > &data, Lima::FsaStringsPool *sp, AbstractDictionaryEntryHandler *handler)
#define STRINGS_POOL_INDEX_MAX_VALUE