use of zemberek.morphology._morphotactics.Condition 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