Esempio n. 1
0
 //Called from each constructor to make sure the noun has a dative singular:
 private static void AddDative(Noun n)
 {
     if (n.sgDat.Count == 0)
     {
         foreach (FormSg f in n.sgNom)
         {
             n.sgDat.Add(new FormSg(f.value, f.gender));
         }
     }
 }
Esempio n. 2
0
        public string printNounXml(Noun n)
        {
            NP     np = new NP(n);
            string nl = Environment.NewLine;

            string ret = "";

            if (this.withXmlDeclarations)
            {
                ret += "<?xml version='1.0' encoding='utf-8'?>" + nl;
            }
            if (this.withXmlDeclarations)
            {
                ret += "<?xml-stylesheet type='text/xsl' href='!gram.xsl'?>" + nl;
            }
            ret += "<Lemma lemma='" + clean4xml(n.getLemma()) + "' uid='" + clean4xml(n.getNickname()) + "'>" + nl;
            ret += "<noun gender='" + (n.getGender() == Gender.Masc ? "masc" : "fem") + "' declension='" + n.declension + "'>" + nl;
            //Singular nominative:
            for (int i = 0; i < Math.Max(np.sgNom.Count, np.sgNomArt.Count); i++)
            {
                ret += "\t<sgNom>" + nl;
                if (np.sgNom.Count > i)
                {
                    ret += "\t\t<articleNo>" + clean4xml(np.sgNom[i].value) + "</articleNo>" + nl;
                }
                if (np.sgNomArt.Count > i)
                {
                    ret += "\t\t<articleYes>" + clean4xml(np.sgNomArt[i].value) + "</articleYes>" + nl;
                }
                ret += "\t</sgNom>" + nl;
            }
            //Singular genitive:
            for (int i = 0; i < Math.Max(np.sgGen.Count, np.sgGenArt.Count); i++)
            {
                ret += "\t<sgGen>" + nl;
                if (np.sgGen.Count > i)
                {
                    ret += "\t\t<articleNo>" + clean4xml(np.sgGen[i].value) + "</articleNo>" + nl;
                }
                if (np.sgGenArt.Count > i)
                {
                    ret += "\t\t<articleYes>" + clean4xml(np.sgGenArt[i].value) + "</articleYes>" + nl;
                }
                ret += "\t</sgGen>" + nl;
            }
            //Plural nominative:
            for (int i = 0; i < Math.Max(np.plNom.Count, np.plNomArt.Count); i++)
            {
                ret += "\t<plNom>" + nl;
                if (np.plNom.Count > i)
                {
                    ret += "\t\t<articleNo>" + clean4xml(np.plNom[i].value) + "</articleNo>" + nl;
                }
                if (np.plNomArt.Count > i)
                {
                    ret += "\t\t<articleYes>" + clean4xml(np.plNomArt[i].value) + "</articleYes>" + nl;
                }
                ret += "\t</plNom>" + nl;
            }
            //Plural genitive:
            for (int i = 0; i < Math.Max(np.plGen.Count, np.plGenArt.Count); i++)
            {
                ret += "\t<plGen>" + nl;
                if (np.plGen.Count > i)
                {
                    ret += "\t\t<articleNo>" + clean4xml(np.plGen[i].value) + "</articleNo>" + nl;
                }
                if (np.plGenArt.Count > i)
                {
                    ret += "\t\t<articleYes>" + clean4xml(np.plGenArt[i].value) + "</articleYes>" + nl;
                }
                ret += "\t</plGen>" + nl;
            }
            ret += "</noun>" + nl;
            ret += "</Lemma>";
            return(ret);
        }
Esempio n. 3
0
 //Creates a noun phrase from a noun modified by an adjective:
 public NP(Noun head, Adjective mod)
 {
     if (mod.isPre)
     {
         Noun   prefixedHead = new Noun(head.printXml());             //create a copy of the head noun
         string prefix       = mod.getLemma();
         foreach (Form f in prefixedHead.sgNom)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.sgGen)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.sgDat)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.sgVoc)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.plNom)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.plGen)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.plVoc)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         foreach (Form f in prefixedHead.count)
         {
             f.value = Opers.Prefix(prefix, f.value);
         }
         NP np = new NP(prefixedHead);
         this.isDefinite = np.isDefinite;
         this.sgNom      = np.sgNom; this.sgNomArt = np.sgNomArt;
         this.sgGen      = np.sgGen; this.sgGenArt = np.sgGenArt;
         this.sgDat      = np.sgDat; this.sgDatArtN = np.sgDatArtN; this.sgDatArtS = np.sgDatArtS;
         this.plNom      = np.plNom; this.plNomArt = np.plNomArt;
         this.plGen      = np.plGen; this.plGenArt = np.plGenArt;
         this.plDat      = np.plDat; this.plDatArt = np.plDatArt;
     }
     else
     {
         this.isDefinite      = head.isDefinite;
         this.isImmutable     = head.isImmutable;
         this.forceNominative = true;
         #region singular-nominative
         foreach (FormSg headForm in head.sgNom)
         {
             {                     //without article:
                 foreach (Form modForm in mod.sgNom)
                 {
                     Mutation mutA  = (headForm.gender == Gender.Masc ? Mutation.None : Mutation.Len1);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgNom.Add(new FormSg(value, headForm.gender));
                 }
             }
             if (!head.isDefinite)                      //with article:
             {
                 foreach (Form modForm in mod.sgNom)
                 {
                     Mutation mutN = (headForm.gender == Gender.Masc ? Mutation.PrefT : Mutation.Len3);
                     if (head.isImmutable)
                     {
                         mutN = Mutation.None;
                     }
                     Mutation mutA  = (headForm.gender == Gender.Masc ? Mutation.None : Mutation.Len1);
                     string   value = "an " + Opers.Mutate(mutN, headForm.value) + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgNomArt.Add(new FormSg(value, headForm.gender));
                 }
             }
         }
         #endregion
         #region singular-genitive
         foreach (FormSg headForm in head.sgGen)
         {
             {                     //without article:
                 List <Form> modForms = (headForm.gender == Gender.Masc ? mod.sgGenMasc : mod.sgGenFem);
                 foreach (Form modForm in modForms)
                 {
                     Mutation mutN = (head.isProper ? Mutation.Len1 : Mutation.None);                           //proper nouns are always lenited in the genitive
                     if (head.isImmutable)
                     {
                         mutN = Mutation.None;
                     }
                     Mutation mutA  = (headForm.gender == Gender.Masc ? Mutation.Len1 : Mutation.None);
                     string   value = Opers.Mutate(mutN, headForm.value) + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgGen.Add(new FormSg(value, headForm.gender));
                 }
             }
         }
         foreach (FormSg headForm in head.sgGen)
         {
             //with article:
             if (!head.isDefinite || head.allowArticledGenitive)
             {
                 List <Form> modForms = (headForm.gender == Gender.Masc ? mod.sgGenMasc : mod.sgGenFem);
                 foreach (Form modForm in modForms)
                 {
                     Mutation mutN = (headForm.gender == Gender.Masc ? Mutation.Len3 : Mutation.PrefH);
                     if (head.isImmutable)
                     {
                         mutN = Mutation.None;
                     }
                     Mutation mutA    = (headForm.gender == Gender.Masc ? Mutation.Len1 : Mutation.None);
                     string   article = (headForm.gender == Gender.Masc ? "an" : "na");
                     string   value   = article + " " + Opers.Mutate(mutN, headForm.value) + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgGenArt.Add(new FormSg(value, headForm.gender));
                 }
             }
         }
         #endregion
         #region plural-nominative
         foreach (Form headForm in head.plNom)
         {
             {                     //without article:
                 foreach (Form modForm in mod.plNom)
                 {
                     Mutation mutA  = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.plNom.Add(new Form(value));
                 }
             }
             if (!head.isDefinite)                      //with article:
             {
                 foreach (Form modForm in mod.plNom)
                 {
                     Mutation mutN = Mutation.PrefH;
                     if (head.isImmutable)
                     {
                         mutN = Mutation.None;
                     }
                     Mutation mutA  = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     string   value = "na " + Opers.Mutate(mutN, headForm.value) + " " + Opers.Mutate(mutA, modForm.value);
                     this.plNomArt.Add(new Form(value));
                 }
             }
         }
         #endregion
         #region plural-genitive
         foreach (FormPlGen headForm in head.plGen)
         {
             {                     //without article:
                 List <Form> modForms = (headForm.strength == Strength.Strong ? mod.plNom : mod.sgNom);
                 foreach (Form modForm in modForms)
                 {
                     Mutation mutA = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     if (headForm.strength == Strength.Weak)
                     {
                         mutA = (Opers.IsSlenderI(headForm.value) ? Mutation.Len1 : Mutation.None);                                                            //"Gael", "captaen" are not slender
                     }
                     string value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.plGen.Add(new Form(value));
                 }
             }
         }
         foreach (FormPlGen headForm in head.plGen)
         {
             //with article:
             if (!head.isDefinite || head.allowArticledGenitive)
             {
                 List <Form> modForms = (headForm.strength == Strength.Strong ? mod.plNom : mod.sgNom);
                 foreach (Form modForm in modForms)
                 {
                     Mutation mutN = Mutation.Ecl1;
                     if (head.isImmutable)
                     {
                         mutN = Mutation.None;
                     }
                     Mutation mutA = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     if (headForm.strength == Strength.Weak)
                     {
                         mutA = (Opers.IsSlenderI(headForm.value) ? Mutation.Len1 : Mutation.None);                                                            //"Gael", "captaen" are not slender
                     }
                     string value = "na " + Opers.Mutate(mutN, headForm.value) + " " + Opers.Mutate(mutA, modForm.value);
                     this.plGenArt.Add(new Form(value));
                 }
             }
         }
         #endregion
         #region singular-dative
         foreach (FormSg headForm in head.sgDat)
         {
             {                     //without article:
                 foreach (Form modForm in mod.sgNom)
                 {
                     Mutation mutA  = (headForm.gender == Gender.Masc ? Mutation.None : Mutation.Len1);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgDat.Add(new FormSg(value, headForm.gender));
                 }
             }
             if (!head.isDefinite)                      //with article:
             {
                 foreach (Form modForm in mod.sgNom)
                 {
                     Mutation mutA  = (headForm.gender == Gender.Masc ? Mutation.None : Mutation.Len1);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.sgDatArtS.Add(new FormSg(value, headForm.gender));
                 }
                 foreach (Form modForm in mod.sgNom)
                 {
                     string value = headForm.value + " " + Opers.Mutate(Mutation.Len1, modForm.value);
                     this.sgDatArtN.Add(new FormSg(value, headForm.gender));
                 }
             }
         }
         #endregion
         #region plural-dative
         foreach (Form headForm in head.plNom)
         {
             {                     //without article:
                 foreach (Form modForm in mod.plNom)
                 {
                     Mutation mutA  = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.plDat.Add(new Form(value));
                 }
             }
             if (!head.isDefinite)                      //with article:
             {
                 foreach (Form modForm in mod.plNom)
                 {
                     Mutation mutA  = (Opers.IsSlender(headForm.value) ? Mutation.Len1 : Mutation.None);
                     string   value = headForm.value + " " + Opers.Mutate(mutA, modForm.value);
                     this.plDatArt.Add(new Form(value));
                 }
             }
         }
         #endregion
     }
 }
Esempio n. 4
0
 //Creates a noun phrase from a noun:
 public NP(Noun head)
 {
     this.isDefinite  = head.isDefinite;
     this.isImmutable = head.isImmutable;
     #region singular-nominative
     foreach (FormSg headForm in head.sgNom)
     {
         { //without article:
             this.sgNom.Add(new FormSg(headForm.value, headForm.gender));
         }
         if (!head.isDefinite)  //with article:
         {
             Mutation mut = (headForm.gender == Gender.Masc ? Mutation.PrefT : Mutation.Len3);
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string value = "an " + Opers.Mutate(mut, headForm.value);
             this.sgNomArt.Add(new FormSg(value, headForm.gender));
         }
     }
     #endregion
     #region singular-genitive
     foreach (FormSg headForm in head.sgGen)
     {
         {                                                                   //without article:
             Mutation mut = (head.isProper ? Mutation.Len1 : Mutation.None); //proper nouns are always lenited in the genitive
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string value = Opers.Mutate(mut, headForm.value);
             this.sgGen.Add(new FormSg(value, headForm.gender));
         }
         //with article:
         if (!head.isDefinite || head.allowArticledGenitive)
         {
             Mutation mut = (headForm.gender == Gender.Masc ? Mutation.Len3 : Mutation.PrefH);
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string article = (headForm.gender == Gender.Masc ? "an" : "na");
             string value   = article + " " + Opers.Mutate(mut, headForm.value);
             this.sgGenArt.Add(new FormSg(value, headForm.gender));
         }
     }
     #endregion
     #region plural-nominative
     foreach (Form headForm in head.plNom)
     {
         { //without article:
             this.plNom.Add(new Form(headForm.value));
         }
         if (!head.isDefinite)  //with article:
         {
             Mutation mut = Mutation.PrefH;
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string value = "na " + Opers.Mutate(mut, headForm.value);
             this.plNomArt.Add(new Form(value));
         }
     }
     #endregion
     #region plural-genitive
     foreach (Form headForm in head.plGen)
     {
         {                                                                   //without article:
             Mutation mut = (head.isProper ? Mutation.Len1 : Mutation.None); //proper nouns are always lenited in the articleless genitive
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string value = Opers.Mutate(mut, headForm.value);
             this.plGen.Add(new Form(value));
         }
         if (!head.isDefinite || head.allowArticledGenitive)  //with article:
         {
             Mutation mut = Mutation.Ecl1;
             if (head.isImmutable)
             {
                 mut = Mutation.None;
             }
             string value = "na " + Opers.Mutate(mut, headForm.value);
             this.plGenArt.Add(new Form(value));
         }
     }
     #endregion
     #region singular-dative
     foreach (FormSg headForm in head.sgDat)
     {
         {                 //without article:
             this.sgDat.Add(new FormSg(headForm.value, headForm.gender));
         }
         if (!head.isDefinite)                  //with article:
         {
             this.sgDatArtN.Add(new FormSg(headForm.value, headForm.gender));
             this.sgDatArtS.Add(new FormSg(headForm.value, headForm.gender));
         }
     }
     #endregion
     #region plural-dative
     foreach (Form headForm in head.plNom)
     {
         {                 //without article:
             this.plDat.Add(new Form(headForm.value));
         }
         if (!head.isDefinite)                  //with article:
         {
             this.plDatArt.Add(new Form(headForm.value));
         }
     }
     #endregion
 }