static void MergeGrammems(THomonymGrammems& dst, const TGramBitSet& art_grammems, const TGramBitSet& newPos) { // first, reset Part Of Speech if any if (newPos.HasAny(TMorph::AllPOS())) dst.SetPOS(newPos); else if (art_grammems.HasAny(TMorph::AllPOS())) dst.SetPOS(art_grammems); // take other grammems from @art_grammems if any TGramBitSet other = art_grammems & ~TMorph::AllPOS(); if (other.any()) { // if there is a form with such grammems - just leave it alone and drop the rest ones bool found = false; for (THomonymGrammems::TFormIter it = dst.IterForms(); it.Ok(); ++it) if (it->HasAll(other)) { dst.ResetSingleForm(*it); found = true; } if (!found) { // otherwise merge all forms and replace grammems by classes TGramBitSet newForm = dst.All(); newForm.ReplaceByMaskIfAny(art_grammems, NSpike::AllCases); newForm.ReplaceByMaskIfAny(art_grammems, NSpike::AllGenders); newForm.ReplaceByMaskIfAny(art_grammems, NSpike::AllNumbers); const TGramBitSet anim(gAnimated, gInanimated); newForm.ReplaceByMaskIfAny(art_grammems, anim); newForm.ReplaceByMaskIfAny(art_grammems, NSpike::AllTimes); newForm.ReplaceByMaskIfAny(art_grammems, NSpike::AllPersons); // just add the rest non-classified grammems static const TGramBitSet nonclassified = ~(NSpike::AllCases | NSpike::AllGenders | NSpike::AllNumbers | anim | NSpike::AllTimes | NSpike::AllPersons); newForm |= art_grammems & nonclassified; dst.Reset(newForm); } } // if we still do not known POS, apply some workarounds: if (dst.GetPOS().none()) { dst.SetPOS(TGramBitSet(gSubstantive)); if (!dst.HasAny(NSpike::AllCases)) dst.Add(NSpike::AllCases); if (!dst.HasAny(NSpike::AllGenders)) dst.Add(NSpike::AllGenders); if (!dst.HasAny(NSpike::AllNumbers)) dst.Add(NSpike::AllNumbers); } // set a noun or adj without additional grammem as indeclinable if (!dst.HasAny(~TMorph::AllPOS()) && (art_grammems.Has(gSubstantive) || TMorph::IsFullAdjective(art_grammems))) dst.Add(NSpike::AllCases | NSpike::AllGenders | NSpike::AllNumbers); }
bool THomonymInflector::FindInForms(const THomonymGrammems& forms, const TGramBitSet& grammems, TGramBitSet& resgram) { using NInfl::DefaultFeatures; using NInfl::TFeature; if (forms.HasForms()) { for (THomonymGrammems::TFormIter it = forms.IterForms(); it.Ok(); ++it) if (it->HasAll(grammems)) { resgram = *it; return true; } } else if (forms.IsIndeclinable() && DefaultFeatures().BitSet(TFeature::Case, TFeature::Number).HasAll(grammems)) { resgram = grammems; return true; } return false; }