use of zemberek.morphology._morphotactics.Conditions.ContainsMorpheme in project zemberek-nlp by ahmetaa.
the class TurkishMorphotactics method connectNounStates.
/**
* Turkish Nouns always have Noun-Person-Possession-Case morphemes. Even there are no suffix
* characters. elma -> Noun:elma - A3sg:ε - Pnon:ε - Nom:ε (Third person singular, No possession,
* Nominal Case)
*/
public void connectNounStates() {
// ev-ε-?-?
noun_S.addEmpty(a3sg_S, notHave(RootAttribute.ImplicitPlural));
// ev-ler-?-?.
noun_S.add(a3pl_S, "lAr", notHave(RootAttribute.ImplicitPlural).and(notHave(RootAttribute.CompoundP3sg)));
// Allow only implicit plural `hayvanat`.
noun_S.addEmpty(a3pl_S, has(RootAttribute.ImplicitPlural));
// --- Compound Handling ---------
// for compound roots like "zeytinyağ-" generate two transitions
// NounCompound--(ε)--> a3sgCompound --(ε)--> pNonCompound_S --> Nom_S
nounCompoundRoot_S.addEmpty(a3sgCompound_S, has(RootAttribute.CompoundP3sgRoot));
a3sgCompound_S.addEmpty(pnonCompound_S);
a3sgCompound_S.add(p3pl_S, "lArI");
// ---- Proper noun handling -------
// TODO: consider adding single quote after an overhaul.
// nounProper_S.add(puncProperSeparator_S, "'");
nounProper_S.addEmpty(a3sg_S);
nounProper_S.add(a3pl_S, "lAr");
puncProperSeparator_S.addEmpty(a3sg_S);
puncProperSeparator_S.add(a3pl_S, "lAr");
// ---- For compund derivations -----------------
pnonCompound_S.addEmpty(nom_S);
nom_S.add(become_S, "lAş");
nom_S.add(acquire_S, "lAn");
// for "zeytinyağlı"
nom_S.add(with_S, "lI", new ContainsMorpheme(with, without).not());
// for "zeytinyağsız"
nom_S.add(without_S, "sIz", new ContainsMorpheme(with, without).not());
// for "zeytinyağlık"
nom_S.add(ness_S, "lI~k", not(new ContainsMorpheme(ness)));
nom_S.add(ness_S, "lI!ğ", not(new ContainsMorpheme(ness)));
// for "zeytinyağcı"
nom_S.add(agt_S, ">cI", not(new ContainsMorpheme(agt)));
// for "zeytinyağsı"
nom_S.add(justLike_S, "+msI", not(new ContainsMorpheme(justLike)));
// for "zeytinyağcık"
nom_S.add(dim_S, ">cI~k", Conditions.HAS_NO_SURFACE.andNot(new ContainsMorpheme(dim)));
nom_S.add(dim_S, ">cI!ğ", Conditions.HAS_NO_SURFACE.andNot(new ContainsMorpheme(dim)));
// "zeytinyağcağız"
nom_S.add(dim_S, "cAğIz", Conditions.HAS_NO_SURFACE);
// for compound roots like "zeytinyağ-lar-ı" generate two transition
// NounCompound--(lAr)--> a3plCompound ---> p3sg_S, P1sg etc.
nounCompoundRoot_S.add(a3plCompound_S, "lAr", has(RootAttribute.CompoundP3sgRoot));
// but for pnon connection, we use lArI
nounCompoundRoot_S.add(a3plCompound2_S, "lArI", has(RootAttribute.CompoundP3sgRoot));
a3plCompound_S.add(p3sg_S, "I").add(p2sg_S, "In").add(p1sg_S, "Im").add(p1pl_S, "ImIz").add(p2pl_S, "InIz").add(p3pl_S, "I");
// this path is used for plural analysis (A3pl+Pnon+Nom) of compound words.
a3plCompound2_S.addEmpty(pnonCompound2_S);
pnonCompound2_S.addEmpty(nom_ST);
// ------
Condition noFamily = notHave(RootAttribute.FamilyMember);
// ev-ε-ε-? Reject "annemler" etc.
a3sg_S.addEmpty(pnon_S, // ev
noFamily).add(p1sg_S, "Im", // evim
noFamily).add(p2sg_S, "In", // evin
noFamily).add(p3sg_S, "+sI", // evi, odası
noFamily).addEmpty(p3sg_S, // "zeytinyağı" has two analyses. Pnon and P3sg.
has(RootAttribute.CompoundP3sg)).add(p1pl_S, "ImIz", // evimiz
noFamily).add(p2pl_S, "InIz", // eviniz
noFamily).add(p3pl_S, "lArI", // evleri
noFamily);
// ev-ler-ε-?
a3pl_S.addEmpty(pnon_S, noFamily);
// ev-ler-im-?
a3pl_S.add(p1sg_S, "Im", noFamily).add(p2sg_S, "In", noFamily).addEmpty(p1sg_S, // for words like "annemler"
has(RootAttribute.ImplicitP1sg)).addEmpty(p2sg_S, // for words like "annenler"
has(RootAttribute.ImplicitP2sg)).add(p3sg_S, "I", noFamily).add(p1pl_S, "ImIz", noFamily).add(p2pl_S, "InIz", noFamily).add(p3pl_S, "I", noFamily);
// --- handle su - akarsu roots. ----
nounSuRoot_S.addEmpty(a3sgSu_S);
nounSuRoot_S.add(a3pl_S, "lar");
a3sgSu_S.addEmpty(pnon_S).add(p1sg_S, "yum").add(p2sg_S, "yun").add(p3sg_S, "yu").add(p1pl_S, "yumuz").add(p2pl_S, "yunuz").add(p3pl_S, "lArI");
// ev-?-ε-ε (ev, evler).
pnon_S.addEmpty(nom_ST, notHave(RootAttribute.FamilyMember));
Condition equCond = new Conditions.ContainsMorpheme(adj, futPart, presPart, narrPart, pastPart).not().or(new Conditions.ContainsMorphemeSequence(able, verb, // allow `yapabildiğince`
pastPart));
// Not allow "zetinyağı-ya" etc.
pnon_S.add(dat_ST, "+yA", // ev-e
notHave(RootAttribute.CompoundP3sg)).add(abl_ST, ">dAn", // ev-den
notHave(RootAttribute.CompoundP3sg)).add(loc_ST, ">dA", // evde
notHave(RootAttribute.CompoundP3sg)).add(acc_ST, "+yI", // evi
notHave(RootAttribute.CompoundP3sg)).add(gen_ST, "+nIn", // evin, zeytinyağının
previousStateIsNot(a3sgSu_S)).add(gen_ST, "yIn", // suyun
previousStateIs(a3sgSu_S)).add(equ_ST, ">cA", // evce
notHave(RootAttribute.CompoundP3sg).and(equCond)).add(ins_ST, // evle, zeytinyağıyla
"+ylA");
// zeytinyağı-na
pnon_S.add(dat_ST, "+nA", has(RootAttribute.CompoundP3sg)).add(abl_ST, "+ndAn", // zeytinyağı-ndan
has(RootAttribute.CompoundP3sg)).add(loc_ST, "+ndA", // zeytinyağı-nda
has(RootAttribute.CompoundP3sg)).add(equ_ST, "+ncA", // zeytinyağı-nca
has(RootAttribute.CompoundP3sg).and(equCond)).add(acc_ST, "+nI", // zeytinyağı-nı
has(RootAttribute.CompoundP3sg));
// This transition is for words like "içeri" or "dışarı".
// Those words implicitly contains Dative suffix.
// But It is also possible to add dative suffix +yA to those words such as "içeri-ye".
pnon_S.addEmpty(dat_ST, has(RootAttribute.ImplicitDative));
p1sg_S.addEmpty(// evim
nom_ST).add(dat_ST, // evime
"A").add(loc_ST, // evimde
"dA").add(abl_ST, // evimden
"dAn").add(ins_ST, // evimle
"lA").add(gen_ST, // evimin
"In").add(equ_ST, "cA", // evimce
equCond.or(new Conditions.ContainsMorpheme(pastPart))).add(acc_ST, // evimi
"I");
p2sg_S.addEmpty(// evin
nom_ST).add(dat_ST, // evine
"A").add(loc_ST, // evinde
"dA").add(abl_ST, // evinden
"dAn").add(ins_ST, // evinle
"lA").add(gen_ST, // evinin
"In").add(equ_ST, "cA", // evince
equCond.or(new Conditions.ContainsMorpheme(pastPart))).add(acc_ST, // evini
"I");
p3sg_S.addEmpty(// evi
nom_ST).add(dat_ST, // evine
"nA").add(loc_ST, // evinde
"ndA").add(abl_ST, // evinden
"ndAn").add(ins_ST, // eviyle
"ylA").add(gen_ST, // evinin
"nIn").add(equ_ST, "ncA", // evince
equCond.or(new Conditions.ContainsMorpheme(pastPart))).add(acc_ST, // evini
"nI");
p1pl_S.addEmpty(// evimiz
nom_ST).add(dat_ST, // evimize
"A").add(loc_ST, // evimizde
"dA").add(abl_ST, // evimizden
"dAn").add(ins_ST, // evimizden
"lA").add(gen_ST, // evimizin
"In").add(equ_ST, "cA", // evimizce
equCond.or(new Conditions.ContainsMorpheme(pastPart))).add(acc_ST, // evimizi
"I");
p2pl_S.addEmpty(// eviniz
nom_ST).add(dat_ST, // evinize
"A").add(loc_ST, // evinizde
"dA").add(abl_ST, // evinizden
"dAn").add(ins_ST, // evinizle
"lA").add(gen_ST, // evinizin
"In").add(equ_ST, "cA", // evinizce
equCond.or(new Conditions.ContainsMorpheme(pastPart))).add(acc_ST, // evinizi
"I");
p3pl_S.addEmpty(// evleri
nom_ST).add(dat_ST, // evlerine
"nA").add(loc_ST, // evlerinde
"ndA").add(abl_ST, // evlerinden
"ndAn").add(ins_ST, // evleriyle
"ylA").add(gen_ST, // evlerinin
"nIn").add(equ_ST, // evlerince.
"+ncA").add(acc_ST, // evlerini
"nI");
// ev-ε-ε-ε-cik (evcik). Disallow this path if visitor contains any non empty surface suffix.
// There are two almost identical suffix transitions with templates ">cI~k" and ">cI!ğ"
// This was necessary for some simplification during analysis. This way there will be only one
// surface form generated for each transition.
nom_ST.add(dim_S, ">cI~k", Conditions.HAS_NO_SURFACE);
nom_ST.add(dim_S, ">cI!ğ", Conditions.HAS_NO_SURFACE);
// ev-ε-ε-ε-ceğiz (evceğiz)
nom_ST.add(dim_S, "cAğIz", Conditions.HAS_NO_SURFACE);
// connect dim to the noun root.
dim_S.addEmpty(noun_S);
nom_ST.add(ness_S, "lI~k", Conditions.CURRENT_GROUP_EMPTY.andNot(new ContainsMorpheme(ness)));
nom_ST.add(ness_S, "lI!ğ", Conditions.CURRENT_GROUP_EMPTY.andNot(new ContainsMorpheme(ness)));
// connect `ness` to the noun root.
ness_S.addEmpty(noun_S);
nom_ST.add(agt_S, ">cI", Conditions.CURRENT_GROUP_EMPTY.andNot(new ContainsMorpheme(adj, agt)));
// connect `ness` to the noun root.
agt_S.addEmpty(noun_S);
// here we do not allow an adjective to pass here.
// such as, adj->zero->noun->ε-ε-ε->zero->Verb is not acceptable because there is already a
// adj->zero->Verb path.
Condition noun2VerbZeroDerivationCondition = Conditions.HAS_TAIL.andNot(Conditions.CURRENT_GROUP_EMPTY.and(new Conditions.LastDerivationIs(adjZeroDeriv_S)));
nom_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
// elma-ya-yım elma-ya-ydı
dat_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
// elma-dan-ım elma-dan-dı
abl_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
// elma-da-yım elma-da-ydı
loc_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
// elma-yla-yım elma-yla-ydı
ins_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
// elma-nın-ım elma-nın-dı
gen_ST.addEmpty(nounZeroDeriv_S, noun2VerbZeroDerivationCondition);
nounZeroDeriv_S.addEmpty(nVerb_S);
// meyve-li
Condition noSurfaceAfterDerivation = new NoSurfaceAfterDerivation();
nom_ST.add(with_S, "lI", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(with, without)));
nom_ST.add(without_S, "sIz", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(with, without, inf1)));
nom_ST.add(justLike_S, "+msI", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(justLike, futPart, pastPart, presPart, adj)));
nom_ST.add(justLike_S, "ImsI", notHave(PhoneticAttribute.LastLetterVowel).and(noSurfaceAfterDerivation).andNot(new ContainsMorpheme(justLike, futPart, pastPart, presPart, adj)));
nom_ST.add(related_S, "sAl", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(with, without, related)));
// connect With to Adjective root.
with_S.addEmpty(adj_ST);
without_S.addEmpty(adj_ST);
related_S.addEmpty(adj_ST);
justLike_S.addEmpty(adj_ST);
// meyve-de-ki
Condition notRelRepetition = new HasTailSequence(rel, adj, zero, noun, a3sg, pnon, loc).not();
loc_ST.add(rel_S, "ki", notRelRepetition.andNot(new Conditions.SecondaryRootIs(SecondaryPos.Time)));
rel_S.addEmpty(adj_ST);
// for covering dünkü, anki, yarınki etc.
// TODO: Use a more general grouping, not using Secondary Pos
Condition time = Conditions.CURRENT_GROUP_EMPTY.and(new Conditions.SecondaryRootIs(SecondaryPos.Time));
DictionaryItem dun = lexicon.getItemById("dün_Noun_Time");
DictionaryItem gun = lexicon.getItemById("gün_Noun_Time");
DictionaryItem bugun = lexicon.getItemById("bugün_Noun_Time");
DictionaryItem ileri = lexicon.getItemById("ileri_Noun");
DictionaryItem geri = lexicon.getItemById("geri_Noun");
DictionaryItem ote = lexicon.getItemById("öte_Noun");
DictionaryItem beri = lexicon.getItemById("beri_Noun");
Condition time2 = Conditions.rootIsAny(dun, gun, bugun);
nom_ST.add(rel_S, "ki", time.andNot(time2));
nom_ST.add(rel_S, "ki", Conditions.rootIsAny(ileri, geri, ote, beri));
nom_ST.add(rel_S, "kü", time2.and(time));
// After Genitive suffix, Rel suffix makes a Pronoun derivation.
gen_ST.add(relToPron_S, "ki");
relToPron_S.addEmpty(pronAfterRel_S);
ContainsMorpheme verbDeriv = new ContainsMorpheme(inf1, inf2, inf3, pastPart, futPart);
nom_ST.add(become_S, "lAş", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(adj)).andNot(verbDeriv));
become_S.addEmpty(verbRoot_S);
nom_ST.add(acquire_S, "lAn", noSurfaceAfterDerivation.andNot(new ContainsMorpheme(adj)).andNot(verbDeriv));
acquire_S.addEmpty(verbRoot_S);
// Inf1 mak makes noun derivation. However, it cannot get any possessive or plural suffix.
// Also cannot be followed by Dat, Gen, Acc case suffixes.
// So we create a path only for it.
nounInf1Root_S.addEmpty(a3sgInf1_S);
a3sgInf1_S.addEmpty(pnonInf1_S);
pnonInf1_S.addEmpty(nom_ST);
pnonInf1_S.add(abl_ST, "tAn");
pnonInf1_S.add(loc_ST, "tA");
pnonInf1_S.add(ins_ST, "lA");
nounActOfRoot_S.addEmpty(a3sgActOf_S);
nounActOfRoot_S.add(a3plActOf_S, "lar");
a3sgActOf_S.addEmpty(pnonActOf);
a3plActOf_S.addEmpty(pnonActOf);
pnonActOf.addEmpty(nom_ST);
}
use of zemberek.morphology._morphotactics.Conditions.ContainsMorpheme in project zemberek-nlp by ahmetaa.
the class TurkishMorphotactics method connectVerbAfterNounAdjStates.
private void connectVerbAfterNounAdjStates() {
// elma-..-ε-yım
nVerb_S.addEmpty(nPresent_S);
// elma-ydı, çorap-tı
nVerb_S.add(nPast_S, "+y>dI");
// elma-ymış
nVerb_S.add(nNarr_S, "+ymIş");
nVerb_S.add(nCond_S, "+ysA");
nVerb_S.add(vWhile_S, "+yken");
// word "değil" is special. It contains negative suffix implicitly. Also it behaves like
// noun->Verb Zero morpheme derivation. because it cannot have most Verb suffixes.
// So we connect it to a separate root state "nVerbDegil" instead of Verb
DictionaryItem degilRoot = lexicon.getItemById("değil_Verb");
nVerbDegil_S.addEmpty(nNeg_S, rootIs(degilRoot));
// copy transitions from nVerb_S
nNeg_S.copyOutgoingTransitionsFrom(nVerb_S);
Condition noFamily = notHave(RootAttribute.FamilyMember);
// for preventing elmamım, elmamdım
// pP1sg_S, pDat_ST, pA1sg_S, pA1pl_S, pA3pl_S, pP2sg_S, pP1pl_S, pP3sg_S, pP1sg_S
// TODO: below causes "beklemedeyiz" to fail.
ContainsMorpheme verbDeriv = new ContainsMorpheme(inf1, inf2, inf3, pastPart, futPart);
Condition allowA1sgTrans = noFamily.andNot(new Conditions.ContainsMorphemeSequence(p1sg, nom)).andNot(verbDeriv);
Condition allowA2sgTrans = noFamily.andNot(new Conditions.ContainsMorphemeSequence(p2sg, nom)).andNot(verbDeriv);
Condition allowA3plTrans = noFamily.andNot(new Conditions.PreviousGroupContains(a3pl_S)).andNot(new Conditions.ContainsMorphemeSequence(p3pl, nom)).andNot(verbDeriv);
Condition allowA2plTrans = noFamily.andNot(new Conditions.ContainsMorphemeSequence(p2pl, nom)).andNot(verbDeriv);
Condition allowA1plTrans = noFamily.andNot(new Conditions.ContainsMorphemeSequence(p1sg, nom)).andNot(new Conditions.ContainsMorphemeSequence(p1pl, nom)).andNot(verbDeriv);
// elma-yım
nPresent_S.add(nA1sg_ST, "+yIm", allowA1sgTrans);
nPresent_S.add(nA2sg_ST, "sIn", allowA1sgTrans);
// elma-ε-ε-dır to non terminal A3sg. We do not allow ending with A3sg from empty Present tense.
nPresent_S.addEmpty(nA3sg_S);
// we allow `değil` to end with terminal A3sg from Present tense.
nPresent_S.addEmpty(nA3sg_ST, rootIs(degilRoot));
// elma-lar, elma-da-lar as Verb.
// TODO: consider disallowing this for "elmalar" case.
nPresent_S.add(nA3pl_ST, "lAr", notHave(RootAttribute.CompoundP3sg).andNot(new Conditions.PreviousGroupContainsMorpheme(inf1)).and(allowA3plTrans));
// elma-ydı-m. Do not allow "elmaya-yım" (Oflazer accepts this)
nPast_S.add(nA1sg_ST, "m", allowA1sgTrans);
nNarr_S.add(nA1sg_ST, "Im", allowA1sgTrans);
nPast_S.add(nA2sg_ST, "n", allowA2sgTrans);
nNarr_S.add(nA2sg_ST, "sIn", allowA2sgTrans);
nPast_S.add(nA1pl_ST, "k", allowA1plTrans);
nNarr_S.add(nA1pl_ST, "Iz", allowA1plTrans);
nPresent_S.add(nA1pl_ST, "+yIz", allowA1plTrans);
nPast_S.add(nA2pl_ST, "InIz", allowA1plTrans);
nNarr_S.add(nA2pl_ST, "sInIz", allowA1plTrans);
nPresent_S.add(nA2pl_ST, "sInIz", allowA1plTrans);
// elma-ydı-lar.
nPast_S.add(nA3pl_ST, "lAr", notHave(RootAttribute.CompoundP3sg).and(allowA3plTrans));
// elma-ymış-lar.
nNarr_S.add(nA3pl_ST, "lAr", notHave(RootAttribute.CompoundP3sg).and(allowA3plTrans));
// elma-ydı-ε
nPast_S.addEmpty(nA3sg_ST);
// elma-ymış-ε
nNarr_S.addEmpty(nA3sg_ST);
// narr+cons is allowed but not past+cond
nNarr_S.add(nCond_S, "sA");
nCond_S.add(nA1sg_ST, "m", allowA1sgTrans);
nCond_S.add(nA2sg_ST, "n", allowA2sgTrans);
nCond_S.add(nA1pl_ST, "k", allowA1plTrans);
nCond_S.add(nA2pl_ST, "nIz", allowA2plTrans);
nCond_S.addEmpty(nA3sg_ST);
nCond_S.add(nA3pl_ST, "lAr");
// for not allowing "elma-ydı-m-dır"
Condition rejectNoCopula = new CurrentGroupContainsAny(nPast_S, nCond_S, nCopBeforeA3pl_S).not();
// elma-yım-dır
nA1sg_ST.add(nCop_ST, "dIr", rejectNoCopula);
nA1pl_ST.add(nCop_ST, "dIr", rejectNoCopula);
nA3sg_S.add(nCop_ST, ">dIr", rejectNoCopula);
nA3pl_ST.add(nCop_ST, "dIr", rejectNoCopula);
// Copula can come before A3pl.
nPresent_S.add(nCopBeforeA3pl_S, ">dIr");
nCopBeforeA3pl_S.add(nA3pl_ST, "lAr");
}
use of zemberek.morphology._morphotactics.Conditions.ContainsMorpheme in project zemberek-nlp by ahmetaa.
the class TurkishMorphotactics method connectAdjectiveStates.
private void connectAdjectiveStates() {
// zero morpheme derivation. Words like "yeşil-i" requires Adj to Noun conversion.
// Since noun suffixes are not derivational a "Zero" morpheme is used for this.
// Transition has a HAS_TAIL condition because Adj->Zero->Noun+A3sg+Pnon+Nom) is not allowed.
adj_ST.addEmpty(adjZeroDeriv_S, Conditions.HAS_TAIL);
adjZeroDeriv_S.addEmpty(noun_S);
adjZeroDeriv_S.addEmpty(nVerb_S);
adj_ST.add(aLy_S, ">cA");
aLy_S.addEmpty(advRoot_ST);
adj_ST.add(aAsIf_S, ">cA", new Conditions.ContainsMorpheme(asIf, ly, agt, with, justLike).not());
aAsIf_S.addEmpty(adj_ST);
adj_ST.add(aAgt_S, ">cI", new Conditions.ContainsMorpheme(asIf, ly, agt, with, justLike).not());
aAgt_S.addEmpty(noun_S);
adj_ST.add(justLike_S, "+msI", new NoSurfaceAfterDerivation().and(new ContainsMorpheme(justLike).not()));
adj_ST.add(justLike_S, "ImsI", notHave(PhoneticAttribute.LastLetterVowel).and(new NoSurfaceAfterDerivation()).and(new ContainsMorpheme(justLike).not()));
adj_ST.add(become_S, "lAş", new NoSurfaceAfterDerivation());
adj_ST.add(acquire_S, "lAn", new NoSurfaceAfterDerivation());
Condition c1 = new Conditions.PreviousMorphemeIsAny(futPart, pastPart);
adjAfterVerb_S.addEmpty(aPnon_ST, c1);
adjAfterVerb_S.add(aP1sg_ST, "Im", c1);
adjAfterVerb_S.add(aP2sg_ST, "In", c1);
adjAfterVerb_S.add(aP3sg_ST, "I", c1);
adjAfterVerb_S.add(aP1pl_ST, "ImIz", c1);
adjAfterVerb_S.add(aP2pl_ST, "InIz", c1);
adjAfterVerb_S.add(aP3pl_ST, "lArI", c1);
adj_ST.add(ness_S, "lI~k");
adj_ST.add(ness_S, "lI!ğ");
adjAfterVerb_ST.add(ness_S, "lI~k", new Conditions.PreviousMorphemeIs(aorPart));
adjAfterVerb_ST.add(ness_S, "lI!ğ", new Conditions.PreviousMorphemeIs(aorPart));
}
use of zemberek.morphology._morphotactics.Conditions.ContainsMorpheme in project zemberek-nlp by ahmetaa.
the class TurkishMorphotactics method connectVerbs.
private void connectVerbs() {
// Imperative.
verbRoot_S.addEmpty(vImp_S);
vImp_S.addEmpty(// oku
vA2sg_ST).add(vA2sg_ST, // oku
"sAnA").add(vA3sg_ST, // okusun
"sIn").add(vA2pl_ST, // okuyun
"+yIn").add(vA2pl_ST, // okuyunuz
"+yInIz").add(vA2pl_ST, // okuyunuz
"sAnIzA").add(vA3pl_ST, // okusunlar
"sInlAr");
// Causative suffixes
// Causes Verb-Verb derivation. There are three forms: "t", "tIr" and "Ir".
// 1- "t" form is used if verb ends with a vowel, or immediately after "tIr" Causative.
// 2- "tIr" form is used if verb ends with a consonant or immediately after "t" Causative.
// 3- "Ir" form appears after some specific verbs but currently we treat them as separate verb.
// such as "pişmek - pişirmek". Oflazer parses them as causative.
verbRoot_S.add(vCausT_S, "t", has(RootAttribute.Causative_t).or(new Conditions.LastDerivationIs(vCausTır_S)).andNot(new Conditions.LastDerivationIsAny(vCausT_S, vPass_S, vAble_S)));
verbRoot_S.add(vCausTır_S, ">dIr", has(PhoneticAttribute.LastLetterConsonant).andNot(new Conditions.LastDerivationIsAny(vCausTır_S, vPass_S, vAble_S)));
vCausT_S.addEmpty(verbRoot_S);
vCausTır_S.addEmpty(verbRoot_S);
// Progressive1 suffix. "-Iyor"
// if last letter is a vowel, this is handled with verbRoot_Prog_S root.
verbRoot_S.add(vProgYor_S, "Iyor", notHave(PhoneticAttribute.LastLetterVowel));
// For "aramak", the modified root "ar" connects to verbRoot_Prog_S. Here it is connected to
// progressive "Iyor" suffix. We use a separate root state for these for convenience.
verbRoot_Prog_S.add(vProgYor_S, "Iyor");
vProgYor_S.add(vA1sg_ST, "um").add(vA2sg_ST, "sun").addEmpty(vA3sg_ST).add(vA1pl_ST, "uz").add(vA2pl_ST, "sunuz").add(vA3pl_ST, "lar");
vProgYor_S.add(vCond_S, "sa").add(vPastAfterTense_S, "du").add(vNarrAfterTense_S, "muş").add(vCopBeforeA3pl_S, "dur").add(vWhile_S, "ken");
// Progressive - 2 "-mAktA"
verbRoot_S.add(vProgMakta_S, "mAktA");
vProgMakta_S.add(vA1sg_ST, "yIm").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "yIz").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr");
vProgMakta_S.add(vCond_S, "ysA").add(vPastAfterTense_S, "ydI").add(vNarrAfterTense_S, "ymIş").add(vCopBeforeA3pl_S, "dIr").add(vWhile_S, "yken");
// Positive Aorist Tense.
// For single syllable words, it forms as "ar-er". For others "ir-ır-ur-ür"
// However there are exceptions to it as well. So dictionary items are marked as Aorist_I and
// Aorist_A.
verbRoot_S.add(vAor_S, "Ir", has(RootAttribute.Aorist_I).or(Conditions.HAS_SURFACE));
verbRoot_S.add(vAor_S, "Ar", has(RootAttribute.Aorist_A).and(Conditions.HAS_NO_SURFACE));
vAor_S.add(vA1sg_ST, "Im").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "Iz").add(vA1pl_ST, "sInIz").add(vA3pl_ST, "lAr");
vAor_S.add(vPastAfterTense_S, "dI").add(vNarrAfterTense_S, "mIş").add(vCond_S, "sA").add(vCopBeforeA3pl_S, "dIr").add(vWhile_S, "ken");
// Negative
verbRoot_S.add(vNeg_S, "mA");
vNeg_S.addEmpty(vImp_S).add(vPast_S, "dI").add(vFut_S, "yAcA~k").add(vFut_S, "yAcA!ğ").add(vNarr_S, "mIş").add(vProgMakta_S, "mAktA").add(vOpt_S, "yA").add(vDesr_S, "sA").add(vNeces_S, "mAlI").add(vInf1_S, "mAk").add(vInf2_S, "mA").add(vInf3_S, "yIş").add(vActOf_S, "mAcA").add(vPastPart_S, "dI~k").add(vPastPart_S, "dI!ğ").add(vFutPart_S, "yAcA~k").add(vFutPart_S, "yAcA!ğ").add(vPresPart_S, "yAn").add(vNarrPart_S, "mIş").add(vSinceDoingSo_S, "yAlI").add(vByDoingSo_S, "yArAk").add(vHastily_S, "yIver").add(vEverSince_S, "yAgör").add(vAfterDoing_S, "yIp").add(vWhen_S, "yIncA").add(vWithoutBeingAbleToHaveDoneSo_S, "yAmAdAn").add(vAsLongAs_S, "dIkçA").add(vWithoutHavingDoneSo_S, "mAdAn").add(vWithoutHavingDoneSo_S, "mAksIzIn").add(vNotState_S, "mAzlI~k").add(vNotState_S, "mAzlI!ğ").add(vFeelLike_S, "yAsI");
// Negative form is "m" before progressive "Iyor" because last vowel drops.
// We use a separate negative state for this.
verbRoot_S.add(vNegProg1_S, "m");
vNegProg1_S.add(vProgYor_S, "Iyor");
// Negative Aorist
// Aorist tense forms differently after negative. It can be "z" or empty.
vNeg_S.add(vAorNeg_S, "z");
vNeg_S.addEmpty(vAorNegEmpty_S);
vAorNeg_S.add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr").add(vPastAfterTense_S, "dI").add(vNarrAfterTense_S, "mIş").add(vCond_S, "sA").add(vCopBeforeA3pl_S, "dIr").add(vWhile_S, "ken");
vAorNegEmpty_S.add(vA1sg_ST, "m").add(vA1pl_ST, "yIz");
// okuma-maz-ım
vNeg_S.add(vAorPartNeg_S, "z");
vAorPartNeg_S.addEmpty(adjAfterVerb_ST);
// Positive Ability.
// This makes a Verb-Verb derivation.
verbRoot_S.add(vAble_S, "+yAbil", new Conditions.LastDerivationIs(vAble_S).not());
vAble_S.addEmpty(verbRoot_S);
// Negative ability.
verbRoot_S.add(vAbleNeg_S, "+yA");
// Also for ability that comes before negative, we add a new root state.
// From there only negative connections is possible.
vAbleNeg_S.addEmpty(vAbleNegDerivRoot_S);
vAbleNegDerivRoot_S.add(vNeg_S, "mA");
vAbleNegDerivRoot_S.add(vNegProg1_S, "m");
// it is possible to have abil derivation after negative.
vNeg_S.add(vAble_S, "yAbil");
// Infinitive 1 "mAk"
// Causes Verb to Noun derivation. It is connected to a special noun root state.
verbRoot_S.add(vInf1_S, "mA~k");
vInf1_S.addEmpty(nounInf1Root_S);
// Infinitive 2 "mA"
// Causes Verb to Noun derivation.
verbRoot_S.add(vInf2_S, "mA");
vInf2_S.addEmpty(noun_S);
// Infinitive 3 "+yUş"
// Causes Verb to Noun derivation.
verbRoot_S.add(vInf3_S, "+yIş");
vInf3_S.addEmpty(noun_S);
// Agt 3 "+yIcI"
// Causes Verb to Noun and Adj derivation.
verbRoot_S.add(vAgt_S, "+yIcI");
vAgt_S.addEmpty(noun_S);
vAgt_S.addEmpty(adjAfterVerb_ST);
// ActOf "mAcA"
// Causes Verb to Noun and Adj derivation.
verbRoot_S.add(vActOf_S, "mAcA");
vActOf_S.addEmpty(nounActOfRoot_S);
// PastPart "oku-duğ-um"
verbRoot_S.add(vPastPart_S, ">dI~k");
verbRoot_S.add(vPastPart_S, ">dI!ğ");
vPastPart_S.addEmpty(noun_S);
vPastPart_S.addEmpty(adjAfterVerb_S);
// FutPart "oku-yacağ-ım kitap"
verbRoot_S.add(vFutPart_S, "+yAcA~k");
verbRoot_S.add(vFutPart_S, "+yAcA!ğ");
vFutPart_S.addEmpty(noun_S, Conditions.HAS_TAIL);
vFutPart_S.addEmpty(adjAfterVerb_S);
// FutPart "oku-yacağ-ım kitap"
verbRoot_S.add(vNarrPart_S, "mIş");
vNarrPart_S.addEmpty(adj_ST);
// AorPart "okunabilir-lik"
verbRoot_S.add(vAorPart_S, "Ir", has(RootAttribute.Aorist_I).or(Conditions.HAS_SURFACE));
verbRoot_S.add(vAorPart_S, "Ar", has(RootAttribute.Aorist_A).and(Conditions.HAS_NO_SURFACE));
vAorPart_S.addEmpty(adjAfterVerb_ST);
// PresPart
verbRoot_S.add(vPresPart_S, "+yAn");
vPresPart_S.addEmpty(noun_S, Conditions.HAS_TAIL);
// connect to terminal Adj
vPresPart_S.addEmpty(adjAfterVerb_ST);
// FeelLike
verbRoot_S.add(vFeelLike_S, "+yAsI");
vFeelLike_S.addEmpty(noun_S, Conditions.HAS_TAIL);
// connect to terminal Adj
vFeelLike_S.addEmpty(adjAfterVerb_ST);
// NotState
verbRoot_S.add(vNotState_S, "mAzlI~k");
verbRoot_S.add(vNotState_S, "mAzlI!ğ");
vNotState_S.addEmpty(noun_S);
// Passive
// Causes Verb-Verb derivation. Passive morpheme has three forms.
// 1- If Verb ends with a vowel: "In"
// 2- If Verb ends with letter 'l' : "InIl"
// 3- If Verb ends with other consonants: "nIl"
// When loading dictionary, first and second case items are marked with Passive_In
verbRoot_S.add(vPass_S, "In", has(RootAttribute.Passive_In).andNot(new Conditions.ContainsMorpheme(pass)));
verbRoot_S.add(vPass_S, "InIl", has(RootAttribute.Passive_In).andNot(new Conditions.ContainsMorpheme(pass)));
verbRoot_S.add(vPass_S, "+nIl", new Conditions.PreviousStateIsAny(vCausT_S, vCausTır_S).or(notHave(RootAttribute.Passive_In).andNot(new Conditions.ContainsMorpheme(pass))));
vPass_S.addEmpty(verbRoot_S);
// Condition "oku-r-sa"
vCond_S.add(vA1sg_ST, "m").add(vA2sg_ST, "n").addEmpty(vA3sg_ST).add(vA1pl_ST, "k").add(vA2pl_ST, "nIz").add(vA3pl_ST, "lAr");
// Past "oku-du"
verbRoot_S.add(vPast_S, ">dI");
vPast_S.add(vA1sg_ST, "m").add(vA2sg_ST, "n").addEmpty(vA3sg_ST).add(vA1pl_ST, "k").add(vA2pl_ST, "nIz").add(vA3pl_ST, "lAr");
vPast_S.add(vCond_S, "ysA");
// Narrative "oku-muş"
verbRoot_S.add(vNarr_S, "mIş");
vNarr_S.add(vA1sg_ST, "Im").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "Iz").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr");
vNarr_S.add(vCond_S, "sA");
vNarr_S.add(vPastAfterTense_S, "tI");
vNarr_S.add(vCopBeforeA3pl_S, "tIr");
vNarr_S.add(vWhile_S, "ken");
vNarr_S.add(vNarrAfterTense_S, "mIş");
// Past after tense "oku-muş-tu"
vPastAfterTense_S.add(vA1sg_ST, "m").add(vA2sg_ST, "n").addEmpty(vA3sg_ST).add(vA1pl_ST, "k").add(vA2pl_ST, "nIz").add(vA3pl_ST, "lAr");
// Narrative after tense "oku-r-muş"
vNarrAfterTense_S.add(vA1sg_ST, "Im").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "Iz").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr");
vNarrAfterTense_S.add(vWhile_S, "ken");
vNarrAfterTense_S.add(vCopBeforeA3pl_S, "tIr");
// Future "oku-yacak"
verbRoot_S.add(vFut_S, "+yAcA~k");
verbRoot_S.add(vFut_S, "+yAcA!ğ");
vFut_S.add(vA1sg_ST, "Im").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "Iz").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr");
vFut_S.add(vCond_S, "sA");
vFut_S.add(vPastAfterTense_S, "tI");
vFut_S.add(vNarrAfterTense_S, "mIş");
vFut_S.add(vCopBeforeA3pl_S, "tIr");
vFut_S.add(vWhile_S, "ken");
// `demek` and `yemek` are special because they are the only two verbs with two letters
// and ends with a vowel.
// Their root transform as:
// No chabge: de-di, de-miş, de-dir
// Change : di-yecek di-yor de-r
// "ye" has similar behavior but not the same. Such as "yi-yin" but for "de", "de-yin"
// TODO: this can be achieved with less repetition.
RootSurfaceIsAny diYiCondition = new RootSurfaceIsAny("di", "yi");
RootSurfaceIsAny deYeCondition = new RootSurfaceIsAny("de", "ye");
Condition cMultiVerb = new Conditions.PreviousMorphemeIsAny(everSince, repeat, almost, hastily, stay, start).not();
vDeYeRoot_S.add(vFut_S, "yece~k", diYiCondition).add(vFut_S, "yece!ğ", diYiCondition).add(vProgYor_S, "yor", diYiCondition).add(vAble_S, "yebil", diYiCondition).add(vAbleNeg_S, "ye", diYiCondition).add(vInf3_S, "yiş", new RootSurfaceIsAny("yi")).add(vFutPart_S, "yece~k", diYiCondition).add(vFutPart_S, "yece!ğ", diYiCondition).add(vPresPart_S, "yen", diYiCondition).add(vEverSince_S, "yegel", diYiCondition.and(cMultiVerb)).add(vRepeat_S, "yedur", diYiCondition.and(cMultiVerb)).add(vRepeat_S, "yegör", diYiCondition.and(cMultiVerb)).add(vAlmost_S, "yeyaz", diYiCondition.and(cMultiVerb)).add(vStart_S, "yekoy", diYiCondition.and(cMultiVerb)).add(vSinceDoingSo_S, "yeli", diYiCondition).add(vByDoingSo_S, "yerek", diYiCondition).add(vAfterDoing_S, "yip", diYiCondition).add(vWithoutBeingAbleToHaveDoneSo_S, "yemeden", diYiCondition).add(vOpt_S, "ye", diYiCondition);
vDeYeRoot_S.add(vCausTır_S, "dir", deYeCondition).add(vPass_S, "n", deYeCondition).add(vPass_S, "nil", deYeCondition).add(vPast_S, "di", deYeCondition).add(vNarr_S, "miş", deYeCondition).add(vAor_S, "r", deYeCondition).add(vNeg_S, "me", deYeCondition).add(vNegProg1_S, "m", deYeCondition).add(vProgMakta_S, "mekte", deYeCondition).add(vDesr_S, "se", deYeCondition).add(vInf1_S, "mek", deYeCondition).add(vInf2_S, "me", deYeCondition).add(vInf3_S, "yiş", new RootSurfaceIsAny("de")).add(vPastPart_S, "di~k", deYeCondition).add(vPastPart_S, "di!ğ", deYeCondition).add(vNarrPart_S, "miş", deYeCondition).add(vHastily_S, "yiver", diYiCondition.and(cMultiVerb)).add(vAsLongAs_S, "dikçe").add(vWithoutHavingDoneSo_S, "meden").add(vWithoutHavingDoneSo_S, "meksizin").add(vNeces_S, "meli").add(vNotState_S, "mezli~k").add(vNotState_S, "mezli!ğ").addEmpty(vImp_S, deYeCondition);
// Optative (gel-e, gel-eyim gel-me-ye-yim)
verbRoot_S.add(vOpt_S, "+yA");
vOpt_S.add(vA1sg_ST, "yIm").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "lIm").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr").add(vPastAfterTense_S, "ydI").add(vNarrAfterTense_S, "ymIş");
// Desire (gel-se, gel-se-m gel-me-se-m)
verbRoot_S.add(vDesr_S, "sA");
vDesr_S.add(vA1sg_ST, "m").add(vA2sg_ST, "n").addEmpty(vA3sg_ST).add(vA1pl_ST, "k").add(vA2pl_ST, "nIz").add(vA3pl_ST, "lAr").add(vPastAfterTense_S, "ydI").add(vNarrAfterTense_S, "ymIş");
verbRoot_S.add(vNeces_S, "mAlI");
vNeces_S.add(vA1sg_ST, "yIm").add(vA2sg_ST, "sIn").addEmpty(vA3sg_ST).add(vA1pl_ST, "yIz").add(vA2pl_ST, "sInIz").add(vA3pl_ST, "lAr").add(vPastAfterTense_S, "ydI").add(vNarrAfterTense_S, "ymIş").add(vCopBeforeA3pl_S, "dIr").add(vWhile_S, "yken");
// A3pl exception case.
// A3pl can appear before or after some tense suffixes.
// "yapar-lar-dı" - "yapar-dı-lar"
// For preventing "yapar-dı-lar-dı", conditions are added.
Condition previousNotPastNarrCond = new PreviousStateIsAny(vPastAfterTense_S, vNarrAfterTense_S, vCond_S).not();
vA3pl_ST.add(vPastAfterTense_ST, "dI", previousNotPastNarrCond);
vA3pl_ST.add(vNarrAfterTense_ST, "mIş", previousNotPastNarrCond);
vA3pl_ST.add(vCond_ST, "sA", previousNotPastNarrCond);
Condition a3plCopWhile = new PreviousMorphemeIsAny(prog1, prog2, neces, fut, narr, aor);
vA3pl_ST.add(vCop_ST, "dIr", a3plCopWhile);
vA3pl_ST.add(vWhile_S, "ken", a3plCopWhile);
Condition a3sgCopWhile = new PreviousMorphemeIsAny(prog1, prog2, neces, fut, narr, aor);
vA1sg_ST.add(vCop_ST, "dIr", a3sgCopWhile);
vA2sg_ST.add(vCop_ST, "dIr", a3sgCopWhile);
vA3sg_ST.add(vCop_ST, ">dIr", a3sgCopWhile);
vA1pl_ST.add(vCop_ST, "dIr", a3sgCopWhile);
vA2pl_ST.add(vCop_ST, "dIr", a3sgCopWhile);
vCopBeforeA3pl_S.add(vA3pl_ST, "lAr");
// Allow Past+A2pl+Cond Past+A2sg+Cond (geldinse, geldinizse)
Condition previousPast = new Conditions.PreviousMorphemeIs(past).andNot(new ContainsMorpheme(cond, desr));
vA2pl_ST.add(vCondAfterPerson_ST, "sA", previousPast);
vA2sg_ST.add(vCondAfterPerson_ST, "sA", previousPast);
vA1sg_ST.add(vCondAfterPerson_ST, "sA", previousPast);
vA1pl_ST.add(vCondAfterPerson_ST, "sA", previousPast);
verbRoot_S.add(vEverSince_S, "+yAgel", cMultiVerb);
verbRoot_S.add(vRepeat_S, "+yAdur", cMultiVerb);
verbRoot_S.add(vRepeat_S, "+yAgör", cMultiVerb);
verbRoot_S.add(vAlmost_S, "+yAyaz", cMultiVerb);
verbRoot_S.add(vHastily_S, "+yIver", cMultiVerb);
verbRoot_S.add(vStay_S, "+yAkal", cMultiVerb);
verbRoot_S.add(vStart_S, "+yAkoy", cMultiVerb);
vEverSince_S.addEmpty(verbRoot_S);
vRepeat_S.addEmpty(verbRoot_S);
vAlmost_S.addEmpty(verbRoot_S);
vHastily_S.addEmpty(verbRoot_S);
vStay_S.addEmpty(verbRoot_S);
vStart_S.addEmpty(verbRoot_S);
vA3sg_ST.add(vAsIf_S, ">cAsInA", new Conditions.PreviousMorphemeIsAny(aor, narr));
verbRoot_S.add(vWhen_S, "+yIncA");
verbRoot_S.add(vSinceDoingSo_S, "+yAlI");
verbRoot_S.add(vByDoingSo_S, "+yArAk");
verbRoot_S.add(vAdamantly_S, "+yAsIyA");
verbRoot_S.add(vAfterDoing_S, "+yIp");
verbRoot_S.add(vWithoutBeingAbleToHaveDoneSo_S, "+yAmAdAn");
verbRoot_S.add(vAsLongAs_S, ">dIkçA");
verbRoot_S.add(vWithoutHavingDoneSo_S, "mAdAn");
verbRoot_S.add(vWithoutHavingDoneSo_S, "mAksIzIn");
vAsIf_S.addEmpty(advRoot_ST);
vSinceDoingSo_S.addEmpty(advRoot_ST);
vByDoingSo_S.addEmpty(advRoot_ST);
vAdamantly_S.addEmpty(advRoot_ST);
vAfterDoing_S.addEmpty(advRoot_ST);
vWithoutBeingAbleToHaveDoneSo_S.addEmpty(advRoot_ST);
vAsLongAs_S.addEmpty(advRoot_ST);
vWithoutHavingDoneSo_S.addEmpty(advRoot_ST);
vWhile_S.addEmpty(advRoot_ST);
vWhen_S.addEmpty(advNounRoot_ST);
}
Aggregations