Exemplo n.º 1
0
 /// <summary>
 /// Crea un mot amb una forma, amb el cas de la regla que l'ha generat i amb informació morfològica
 /// i gramatical. 
 /// La informació morfològica i gramatical del mot és la combinació de la informació provinent del
 /// cas de la regla (casRegla) i la d'info.
 /// </summary>
 /// <param name="forma">La forma del mot.</param>
 /// <param name="casRegla">El cas de la regla a partir del qual s'ha generat el mot.</param>
 /// <param name="extra">Informació morfològica i gramatical que s'afegeix a la del cas de la regla.</param>
 public Mot(string forma, CasRegla casRegla, MorfoGram extra)
 {
     this.forma = forma;
     this.casRegla = casRegla;
     this.extra = extra;
     this.info = null;
 }
Exemplo n.º 2
0
 private ItemDic(string arrel, uint[] flags, MorfoGram mgComuna, MorfoGram mgArrel)
 {
     this.arrel = arrel;
     for (int i = 0; i < flags.Length; i++)
         this.flags[i] = flags[i];
     MesMorfoGram(mgComuna, mgArrel);
     flagsComLletres = null;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Crea un cas per a una regla.
 /// </summary>
 /// <param name="regla">La regla a la qual pertany aquest cas.</param>
 /// <param name="suprimir">Els caràcters que s'han de suprimir. S'eliminen del principi
 /// o del final, segons si és prefix o sufix. Si és "0", no se suprimeix res.</param>
 /// <param name="afegir">El que s'ha d'afegir a l'arrel després de suprimir-ne caràcters, si cal.
 /// Se suprimeix del principi o del final, segons si és prefix o sufix.</param>
 /// <param name="condicio">La condició que ha de complir l'arrel perquè aquest cas sigui aplicable.</param>
 /// <param name="sufix">Si és true, es modifica el començament de l'arrel. Si és false, es
 /// modifica el final de l'arrel.</param>
 /// <param name="marca">La marca dialectal associada a aquest cas.</param>
 /// <param name="info">Informació morfològica i gramatical.</param>
 /// <param name="mesRegles">Regles que es poden aplicar després d'haver aplicat aquest cas.
 /// Correspon al "twofold" introduït per Hunspell.</param>
 public CasRegla(Regla regla, string suprimir, string afegir, string condicio, bool sufix, Marca marca, MorfoGram info, List<string> mesRegles)
 {
     this.regla = regla;
     this.sSuprimir = suprimir;
     this.suprimir = (suprimir == "0") ? 0 : suprimir.Length;
     this.afegir = afegir;
     sCondicio = condicio;
     if (condicio == ".")
         this.condicio = null;
     else if (sufix)
         this.condicio = new Regex(condicio + "$");
     else
         this.condicio = new Regex("^" + condicio);
     this.sufix = sufix;
     this.marca = marca;
     this.info = info;
     if (mesRegles != null)
     {
         this.mesRegles = new List<string>(mesRegles);
         this.mesRegles.Sort(string.Compare);
     }
     else
         this.mesRegles = null;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Crea sumant els valors de dos objectes MorfoGram.
 /// Per als objectes inexistents, se suposa el valor NOCAT, NOTEMPS, etc.
 /// Si els valors són incompatibles, es provoca una excepció.
 /// </summary>
 /// <param name="mf1">El primer MorfoGram</param>
 /// <param name="mf2">El segon MorfoGram</param>
 public MorfoGram(MorfoGram mf1, MorfoGram mf2)
 {
     if (mf1 == null && mf2 == null)
         return;
     if (mf1 == null || mf2 == null)
     {
         MorfoGram mfx = (mf1 != null) ? mf1 : mf2;
         cat = mfx.Cat;
         temps = mfx.Temps;
         pers = mfx.Pers;
         gen = mfx.Gen;
         nbre = mfx.Nbre;
         return;
     }
     if (Unificables(mf1, mf2))
     {
         cat = (mf1.Cat != eCat.NOCAT) ? mf1.Cat : mf2.Cat;
         temps = (mf1.Temps != eTemps.NOTEMPS) ? mf1.Temps : mf2.Temps;
         pers = (mf1.Pers != ePers.NOPERS) ? mf1.Pers : mf2.Pers;
         gen = (mf1.Gen != eGen.NOGEN) ? mf1.Gen : mf2.Gen;
         nbre = (mf1.Nbre != eNbre.NONBRE) ? mf1.Nbre : mf2.Nbre;
     }
     else
     {
         if ((mf1.Cat != eCat.NOCAT) && (mf2.Cat != eCat.NOCAT) && (mf1.Cat != mf2.Cat))
             throw new Exception(String.Format("Categories incompatibles ({0}, {1})", mf1.ToString(), mf2.ToString()));
         if ((mf1.Temps != eTemps.NOTEMPS) && (mf2.Temps != eTemps.NOTEMPS) && (mf1.Temps != mf2.Temps))
             throw new Exception(String.Format("Temps incompatibles ({0}, {1})", mf1.ToString(), mf2.ToString()));
         if ((mf1.Pers != ePers.NOPERS) && (mf2.Pers != ePers.NOPERS) && (mf1.Pers != mf2.Pers))
             throw new Exception(String.Format("Persones incompatibles ({0}, {1})", mf1.ToString(), mf2.ToString()));
         if ((mf1.Gen != eGen.NOGEN) && (mf2.Gen != eGen.NOGEN) && (mf1.Gen != mf2.Gen))
             throw new Exception(String.Format("Gèneres incompatibles ({0}, {1})", mf1.ToString(), mf2.ToString()));
         if ((mf1.Nbre != eNbre.NONBRE) && (mf2.Nbre != eNbre.NONBRE) && (mf1.Nbre != mf2.Nbre))
             throw new Exception(String.Format("Categories incompatibles ({0}, {1})", mf1.ToString(), mf2.ToString()));
     }
 }
Exemplo n.º 5
0
 public PC_verb_ir(bool pur, bool inc)
     : base(string.Format("Verb en -ir{0}{1}", pur ? ", pur" : "", inc ? ", incoatiu" : ""))
 {
     mgVerb = new MorfoGram(MorfoGram.eCat.VERB);
     mgArrel = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.FUT, MorfoGram.ePers.P1);
     this.pur = pur;
     this.inc = inc;
 }
Exemplo n.º 6
0
 private static void AgafaInfo(ref MorfoGram.eCat cat, ref MorfoGram.eTemps temps, 
     ref MorfoGram.eGen gen, ref MorfoGram.eNbre nbre, string nota)
 {
     Match match = reEtiInfo.Match(nota);
     if (!match.Success)
         return;
     string etiqueta = match.Groups[1].Value;
     if (etisInfo.ContainsKey(etiqueta))
     {
         MorfoGram info = etisInfo[etiqueta];
         if (info.Cat != MorfoGram.eCat.NOCAT) cat = info.Cat;
         if (info.Temps != MorfoGram.eTemps.NOTEMPS) temps = info.Temps;
         if (info.Gen != MorfoGram.eGen.NOGEN) gen = info.Gen;
         if (info.Nbre != MorfoGram.eNbre.NONBRE) nbre = info.Nbre;
     }
     else
         throw new Exception("Etiqueta d'informació desconeguda: " + etiqueta);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Genera els mots per a una arrel.
 /// </summary>
 /// <param name="arrel">L'arrel que es vol expandir.</param>
 /// <param name="infoComuna">
 /// Informació comuna a tots els mots que es generaran.
 /// Aquesta informació s'unifica amb la que va associada als casos.
 /// Per tant, només es generen els casos que tenen informació compatible.
 /// </param>
 /// <param name="regles">La llista completa de regles.</param>
 /// <param name="filtre">Només es generen mots que tenen marques contingudes en aquest filtre.</param>
 /// <param name="nomesAfixos">Si és true, només s'apliquen les regles amb la propietat EsAfix = true.</param>
 /// <returns>La llista generada de mots.</returns>
 public List<Mot> Genera(string arrel, MorfoGram infoComuna, Regles regles, Marques filtre, bool nomesAfixos)
 {
     List<Mot> mots = new List<Mot>();
     if (nomesAfixos && !EsAfix)
         return mots;
     int afegits = 0;
     foreach (CasRegla cas in casos)
     {
         if (!MorfoGram.Unificables(cas.Info, infoComuna) || !filtre.Conte(cas.Marca))
             continue;
         afegits += cas.Genera(arrel, ref mots, infoComuna, regles, filtre, nomesAfixos);
         if (afegits >= maxGenera)
                 break;
     }
     return mots;
 }
 /// <summary>
 /// Calcula el paradigma per a paraules amb singular i plural.
 /// </summary>
 private ParadigmaCat Id2(string arrel, MorfoGram morfoGram, Dictionary<string, string> dades, 
     Dictionary<string, string> exc)
 {
     // PERFER: mirar "dijous"
     bool admetArticle = (exc == null || !exc.ContainsKey("NOART"));
     string arrel0, arrel1;
     arrel0 = ParadigmaCat.Arrel0(arrel, out arrel1);
     if (arrel1 != arrel0)
     {
         // PER_FER: unificar amb Precalc()
         // Tenim una paraula amb trossos
         PC_multi par = new PC_multi();
         string[] trossos = arrel.Split(' ');
         for (int i = 0; i < trossos.Length; i++)
         {
             if (trossos.Length == 0)
                 continue;
             // PER_FER: la paraula pot tenir articles i preposicions
             Paraula ptros = new Paraula(trossos[i]);
             if (i == 0)
                 par.Add(new PC_formaFixada("Entrada amb espais, primer tros", morfoGram, ptros,
                     ptros.PotApostrofar(), ptros.PotApostrofar(morfoGram.Gen == MorfoGram.eGen.F)));
             else
                 par.Add(new PC_formaFixada("Entrada amb espais, tros interior", morfoGram, ptros, false, false));
         }
         return par;
     }
     Paraula paraula = new Paraula(arrel0);
     Debug.Assert(!paraula.Forma.Contains(" "), "No hi ha d'haver espais a l'arrel");
     if (exc != null)
     {
         // suposam que el singular i el plural tenen el mateix valor de VocalInicial
         string plural = Dades(exc, "PLU");
         if (plural != null)
         {
             if (plural.Contains(" "))
             {
                 // Hi ha més d'un plural
                 string[] trossos = plural.Split(' ');
                 PC_multi par = new PC_multi();
                 foreach (string tros in trossos)
                     par.Add(new PC_plural_precalc(morfoGram, paraula, tros, paraula.VocalInicial,
                         paraula.VocalInicial && admetArticle));
                 return par;
             }
             return new PC_plural_precalc(morfoGram, paraula,
                 plural, paraula.VocalInicial, paraula.VocalInicial && admetArticle);
         }
     }
     string admet = String.Format("D{0}, L{1}", paraula.VocalInicial ? "+" : "-",
         paraula.VocalInicial && admetArticle ? "+" : "-");
     if (morfoGram.Cat == MorfoGram.eCat.ADJ)
     {
         string id = null;
         if (paraula.VocalFinal && paraula.Aguda)
             id = "A2T, -ns, " + admet;
         else if (paraula.SxcFinal && paraula.Aguda)
             id = "A2T, -os, " + admet;
         else
             id = "A2T, -s, " + admet;
         return paradigmes[id];
     }
     else // (no és un adjectiu, ho tractam com un nom)
     {
         string id = null;
         if (morfoGram.Gen == MorfoGram.eGen.F)
         {
             // exemples: mà, casa
             if (paraula.VocalFinal && paraula.Aguda)
                 id = "NF, -ns, " + admet;
             else if (paraula.SxcFinal && paraula.Aguda)
                 id = "NF, -s, " + admet;
             // PERFER: comprovar que el plural de "falç" és "falçs"
             else
                 id = "NF, -s, " + admet;
         }
         else // (la paraula és masculina o no té gènere)
         {
             // exemples: ca, moix, peu
             if (paraula.VocalFinal && paraula.Aguda)
                 id = "NM, -ns, " + admet;
             else if (paraula.SxcFinal && paraula.Aguda)
                 id = "NM, -os, " + admet;
             else
                 id = "NM, -s, " + admet;
         }
         return paradigmes[id];
     }
     //throw new Exception("No sé què fer amb " + arrel);
 }
Exemplo n.º 9
0
 private void test_04(GrupTest arrel)
 {
     GrupTest grup = arrel.NouGrup("Entrades i mots");
     Regles regles = CarregaRegles(true);
     Identificador idDIEC = new IdentificadorDIEC("*** buit ***", regles, null);
     grup.NouTest("Entrades ignorades", delegate(RTest resultat)
     {
         Entrada entrada;
         Regex trosseja = new Regex(@"\|\|");
         string entrades = "ent=-adelf -adelfa||ent=ab-";
         foreach (string tros in trosseja.Split(entrades))
         {
             entrada = idDIEC.IdentificaEntrada(tros);
             resultat.Assert(entrada == null, "S'hauria d'ignorar \"{0}\"", tros);
         }
     });
     grup.NouTest("Neteja d'entrades", delegate(RTest resultat)
     {
         Entrada entrada;
         entrada = idDIEC.IdentificaEntrada("ent=a1^cat1=f.^com1=pl. as");
         resultat.Esperat("a", entrada.Arrel);
         entrada = idDIEC.IdentificaEntrada("ent=abaltir-se^cat1=v. pron.");
         resultat.Esperat("abaltir", entrada.Arrel);
         entrada = idDIEC.IdentificaEntrada("ent=abastador2 abastadora^cat1=m. i f.");
         resultat.Esperat("abastador abastadora", entrada.Arrel);
     });
     grup.NouTest("Informació morfològica i gramatical", delegate(RTest resultat)
     {
         MorfoGram mf1 = new MorfoGram();
         resultat.Esperat("ND", mf1.ToString());
         MorfoGram mf2 = new MorfoGram(MorfoGram.eCat.NOM);
         resultat.Esperat("NOM", mf2.ToString());
         MorfoGram mf12 = new MorfoGram(mf1, mf2);
         resultat.Esperat("NOM", mf12.ToString());
         MorfoGram mf3 = new MorfoGram(MorfoGram.eCat.VERB);
         try
         {
             MorfoGram mf23 = new MorfoGram(mf2, mf3);
             resultat.Error("Error indetectat unint {0} i {1}", mf2, mf3);
         }
         catch (Exception exc)
         {
             resultat.Nota("Error esperat intentant unir {0} i {1} ({2})", mf2, mf3, exc.Message);
         }
         MorfoGram mf4 = new MorfoGram(MorfoGram.eCat.NOCAT, MorfoGram.eTemps.IPR, MorfoGram.ePers.P3);
         resultat.Esperat("IPR.P3", mf4.ToString());
         MorfoGram mf34 = new MorfoGram(mf3, mf4);
         resultat.Esperat("VERB.IPR.P3", mf34.ToString());
     });
 }
Exemplo n.º 10
0
 public PC_plural_s(MorfoGram mgComuna, bool admetD, bool admetL, string desc)
     : base("E", mgComuna, admetD, admetL, desc)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Crea a partir del plural i amb informació d'apostrofació.
 /// </summary>
 /// <param name="mgComuna">Informació morfològica i gramatical comuna a totes les formes.</param>
 /// <param name="singular">Paraula en singular</param>
 /// <param name="plural">Plural precalculat.</param>
 /// <param name="admetD">Totes les formes admeten la preposició "de" apostrofada.</param>
 /// <param name="admetL">El singular admet l'article apostrofat.</param>
 public PC_plural_precalc(MorfoGram mgComuna, Paraula singular, string plural, bool admetD, bool admetL)
     : base(mgComuna.ToString() + " " /*+ singular + "/" + plural*/ + (admetD ? ", d'" : "") + (admetL ? ", l'" : ""))
 {
     this.mgComuna = mgComuna;
     mgArrel = null;
     this.singular = singular.Forma;
     this.plural = plural;
     // Interpretam la notació "abacà -às"
     if (plural.StartsWith("-"))
         this.plural = singular.PreTonica + plural.Substring(1);
     // PERFER: mirar si és aplicable la regla 'E'
     this.admetD = admetD;
     this.admetL = admetL;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Crea amb una categoria gramatical i informació sobre l'inici de la paraula.
 /// </summary>
 /// <param name="regla">La regla que aplicarem per al plural.</param>
 /// <param name="mgComuna">La informació morfogramatical comuna a totes les formes.</param>
 /// <param name="admetD">Admet "d'".</param>
 /// <param name="admetL">Admet "l'".</param>
 /// <param name="desc">Descripció del paradigma.</param>
 protected PC_plural_EGI(string regla, MorfoGram mgComuna, bool admetD, bool admetL, string desc)
     : base(desc)
 {
     this.regla = regla;
     this.mgComuna = mgComuna;
     mgArrel = new MorfoGram(MorfoGram.eNbre.SG);
     this.admetD = admetD;
     this.admetL = admetL;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Crea a partir de la forma i amb informació d'apostrofació.
 /// </summary>
 /// <param name="desc">Descripció del paradigma.</param>
 /// <param name="forma">La forma del nom.</param>
 /// <param name="admetD">Admet la preposició "de" apostrofada.</param>
 /// <param name="admetL">Admet l'article apostrofat.</param>
 /// <param name="admetN">Admet l'article personal apostrofat</param>
 public PC_nomPropi(string desc, MorfoGram mgComuna, bool admetD, bool admetL, bool admetN)
     : base(desc)
 {
     this.mgComuna = mgComuna;
     this.admetD = admetD;
     this.admetL = admetL;
     this.admetN = admetN;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Crea amb una regla, informació morfogramatical i informació sobre apostrofació.
 /// No funciona per a les paraules començades amb 'i' o 'u' àtones, ja que el femení i
 /// el masculí no funcionen igual pel que fa a l'article.
 /// </summary>
 /// <param name="regla">La regla per generar formes a partir del masculí singular.</param>
 /// <param name="mgComuna">Informació morfogramatical comuna a totes les formes.</param>
 /// <param name="admetD">Les formes admeten "d'".</param>
 /// <param name="admetL">Les formes admeten "l'".</param>
 /// <param name="desc">Descripció del paradigma.</param>
 public PC_MFSP(string regla, MorfoGram mgComuna, bool admetD, bool admetL, string desc)
     : base(desc)
 {
     this.regla = regla;
     this.mgComuna = mgComuna;
     this.admetD = admetD;
     this.admetL = admetL;
     mgArrel = mgComuna | mgMascSg;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Crea a partir de la forma i amb informació d'apostrofació.
 /// </summary>
 /// <param name="desc">Descripció del paradigma.</param>
 /// <param name="mgComuna">Informació morfològica i gramatical comuna a totes les formes.</param>
 /// <param name="paraula">La paraula.</param>
 /// <param name="admetD">Totes les formes admeten la preposició "de" apostrofada.</param>
 /// <param name="admetL">El singular admet l'article apostrofat.</param>
 public PC_formaFixada(string desc, MorfoGram mgComuna, Paraula paraula, bool admetD, bool admetL)
     : base(desc)
 {
     this.mgComuna = mgComuna;
     mgArrel = null;
     this.forma = paraula.Forma;
     this.admetD = admetD;
     this.admetL = admetL;
 }
Exemplo n.º 16
0
 protected List<Mot> GeneraMots(List<ItemDic> items, MorfoGram filtreMG, Marques filtreMRQ, bool nomesAfixos)
 {
     List<Mot> tot = GeneraMots(items, filtreMRQ, nomesAfixos);
     List<Mot> llista = tot.FindAll(delegate(Mot mot)
     {
         return MorfoGram.Unificables(mot.Info, filtreMG);
     });
     return llista;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Crea copiant les dades d'un altre.
 /// </summary>
 /// <param name="mg">L'origen de les dades.</param>
 public MorfoGram(MorfoGram mg)
     : this(mg, null)
 {
 }
Exemplo n.º 18
0
 public PC_precalc(string forma, MorfoGram mg, params string[] flags)
     : base(string.Format("precalc"/*@"""{0}"" x {{{1}}}"*/, forma, String.Join(", ", flags)))
 {
     this.forma = forma;
     this.mg = mg;
     this.flags = flags;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Afegeix informació morfogramatical compartida per totes les formes generades
 /// per aquest ítem.
 /// </summary>
 /// <param name="novaComuna">La informació nova per a mgComuna.</param>
 /// <param name="novaArrel">La informació nova per a mgArrel.</param>
 public void MesMorfoGram(MorfoGram novaComuna, MorfoGram novaArrel)
 {
     if (novaComuna != null)
     {
         if (mgCom == null)
             mgCom = new MorfoGram();
         mgCom |= novaComuna;
     }
     if (novaArrel != null)
     {
         if (mgArr == null)
             mgArr = new MorfoGram();
         mgArr |= novaArrel;
     }
 }
Exemplo n.º 20
0
 /// <summary>
 /// Crea amb informació morfogramatical.
 /// No admet a cap tros.
 /// </summary>
 /// <param name="mgComuna">Informació morfològica i gramatical comuna a totes les formes.</param>
 public PC_trossos(MorfoGram mgComuna)
     : base(mgComuna.ToString() + ", D-, L-")
 {
     this.mgComuna = mgComuna;
     admetD = false;
     admetL = false;
     esLlista = false;
     mgArrel = null;
 }
 private static Dictionary<string, ParadigmaCat> CreaParadigmes()
 {
     Dictionary<string, ParadigmaCat> llista = new Dictionary<string, ParadigmaCat>();
     for (int tp = 1; tp <= 3; ++tp) // tipus de plural: -s, -ns o -os
     {
         string descTP = null;
         switch (tp)
         {
             case 1:
                 descTP = "-s";
                 break;
             case 2:
                 descTP = "-ns";
                 break;
             case 3:
                 descTP = "-os";
                 break;
         }
         for (int cat = 1; cat <= 3; ++cat) // categoria: NM, NF, ADJ (2 terminacions)
         {
             string descCat = null;
             MorfoGram mg = new MorfoGram();
             switch (cat)
             {
                 case 1:
                     descCat = "NM";
                     mg.Cat = MorfoGram.eCat.NOM;
                     mg.Gen = MorfoGram.eGen.M;
                     break;
                 case 2:
                     descCat = "NF";
                     mg.Cat = MorfoGram.eCat.NOM;
                     mg.Gen = MorfoGram.eGen.F;
                     break;
                 case 3:
                     descCat = "A2T";
                     mg.Cat = MorfoGram.eCat.ADJ;
                     break;
             }
             for (int admetD = 0; admetD <= 1; ++admetD)
                 for (int admetL = 0; admetL <= 1; ++admetL)
                 {
                     string desc = String.Format("{0}, {1}, D{2}, L{3}",
                         descCat, descTP,
                         admetD == 0 ? "-" : "+", admetL == 0 ? "-" : "+");
                     switch (tp)
                     {
                         case 1:
                             llista[desc] = new PC_plural_s(mg, admetD == 1, admetL == 1, desc);
                             break;
                         case 2:
                             llista[desc] = new PC_plural_ns(mg, admetD == 1, admetL == 1, desc);
                             break;
                         case 3:
                             llista[desc] = new PC_plural_os(mg, admetD == 1, admetL == 1, desc);
                             break;
                     }
                 }
         }
     }
     //
     llista["NPM"] = new PC_plural(true);
     llista["NPF"] = new PC_plural(false);
     //
     llista["NSM"] = new PC_singular(true);
     llista["NSF"] = new PC_singular(false);
     //
     llista["???"] = new PC_trossos(new MorfoGram());
     llista["CONJ"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.CONJ));
     llista["PREP"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.PREP));
     llista["ART"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.ART));
     llista["PRON, D-"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.PRON), false, false, true);
     llista["PRON, D+"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.PRON), true, false, true);
     llista["LOC PREP"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.LOCPREP));
     llista["LOC ADJ"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.LOCADJ));
     llista["LOC ADV"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.LOCADV));
     llista["ADV, D-"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.ADV));
     llista["ADV, D+"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.ADV), true, false, true);
     llista["INTERJ"] = new PC_trossos(new MorfoGram(MorfoGram.eCat.INTERJ));
     //
     foreach (char ch in "FJBHKL")
     {
         string regla = ch.ToString();
         for (int an = 0; an <= 1; ++an)
         {
             MorfoGram mg = new MorfoGram(an == 0 ? MorfoGram.eCat.ADJ : MorfoGram.eCat.NOM);
             for (int admetD = 0; admetD <= 1; ++admetD)
                 for (int admetL = 0; admetL <= 1; ++admetL)
                 {
                     string desc = String.Format("{0}, MFSP, {1}, D{2}, L{3}",
                         an == 0 ? "A" : "N", regla,
                         admetD == 0 ? "-" : "+", admetL == 0 ? "-" : "+");
                     llista[desc] = new PC_MFSP(regla, mg, admetD == 1, admetL == 1, desc);
                 }
         }
     }
     //
     MorfoGram mgNomPropi = new MorfoGram(MorfoGram.eCat.NOMPR);
     for (int admetD = 0; admetD <= 1; ++admetD)
         for (int admetL = 0; admetL <= 1; ++admetL)
             for (int admetN = 0; admetN <= 1; ++admetN)
             {
                 string desc = String.Format("NP, D{0}, L{1}, N{2}",
                     admetD == 0 ? "-" : "+", admetL == 0 ? "-" : "+", admetN == 0 ? "-" : "+");
                 llista[desc] = new PC_nomPropi(desc, mgNomPropi, admetD == 1, admetL == 1, admetN == 1);
             }
     //
     llista["V, -ar"] = new PC_verb_ar();
     llista["V, -re"] = new PC_verb_re();
     llista["V, -ir, P"] = new PC_verb_ir(true, false);
     llista["V, -ir, I"] = new PC_verb_ir(false, true);
     //
     return llista;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Crea amb informació morfogramatical.
 /// </summary>
 /// <param name="mgComuna">Informació morfològica i gramatical comuna a totes les formes.</param>
 /// <param name="admetD">Admet "d'".</param>
 /// <param name="admetL">Admet "l'".</param>
 /// <param name="esLlista">Si els trossos són una llista. Si és true, admetD i admetL
 /// afecten tots els trossos. Si és false, només afecten el primer tros.</param>
 public PC_trossos(MorfoGram mgComuna, bool admetD, bool admetL, bool esLlista)
     : base(mgComuna.ToString() + (admetD ? ", D+" : ", D-"))
 {
     this.mgComuna = mgComuna;
     this.admetD = admetD;
     this.admetL = admetL;
     this.esLlista = esLlista;
     mgArrel = null;
 }
 /// <summary>
 /// Calcula el paradigma per a adjectius i masculins/femenins.
 /// El resultat pot tenir dues terminacions (abacial), tres (feliç) o quatre (blanc).
 /// </summary>
 private ParadigmaCat Id4(string arrel, MorfoGram morfoGram, Dictionary<string, string> dades, Dictionary<string, string> exc)
 {
     bool admetArticle = (exc == null || !exc.ContainsKey("NOART"));
     string fem;
     string masc = ParadigmaCat.Arrel0(arrel, out fem);
     if (exc != null && exc.ContainsKey("PLU") && exc["PLU"].Contains(" "))
     {
         string[] trossos = exc["PLU"].Split(' ');
         if (trossos.Length != 2) throw new Exception("S'esperaven dos trossos: " + exc["PLU"]);
         Dictionary<string, string> exc2 = new Dictionary<string, string>(exc);
         exc2["PLU"] = trossos[0];
         ParadigmaCat parMasc = Id2(masc, morfoGram | mgMasc, dades, exc2);
         exc2["PLU"] = trossos[1];
         ParadigmaCat parFem = Id2(fem, morfoGram | mgFem, dades, exc2);
         return new PC_multi(parMasc, parFem);
     }
     if (fem == masc)
     {
         // Si hi ha una forma, vol dir que és igual per al masculí i el femení, almenys en singular
         ParadigmaCat par = Id2(arrel, morfoGram, dades, exc);
         if (arrel.EndsWith("ç"))
         {
             // Si termina en 'ç', hi ha dues formes per al plural
             PC_multi pars = new PC_multi(par);
             Paraula fpl = new Paraula(arrel.Substring(0, arrel.Length - 1) + "ces");
             pars.Add(new PC_formaFixada("plural en -ces", new MorfoGram(morfoGram.Cat, MorfoGram.eGen.F, MorfoGram.eNbre.PL),
                 fpl, fpl.VocalInicial, false));
             return pars;
         }
         else
             return par;
     }
     else // (fem != null)
     {
         Paraula pMasc = new Paraula(masc);
         foreach (char id in "FJBHKL")
         {
             if (id == 'H' && (!pMasc.Aguda || !pMasc.VocalFinal))
                 continue;
             Regla regla = regles.Llista[id.ToString()];
             List<Mot> femenins = regla.Genera(masc, mgFemSg, regles, Marques.totes, true);
             if (femenins.Count == 0)
                 continue;
             if (femenins.Exists(delegate(Mot mot) { return mot.Forma == fem; }))
             {
                 string idPar = String.Format("{0}, MFSP, {1}, D{2}, L{3}",
                     morfoGram.Cat == MorfoGram.eCat.ADJ ? "A" : "N",
                     id.ToString(),
                     pMasc.VocalInicial ? "+" : "-",
                     pMasc.VocalInicial && admetArticle ? "+" : "-");
                 ParadigmaCat par = paradigmes[idPar];
                 Paraula pFem = new Paraula(fem);
                 if (pFem.PotApostrofar(true)&& admetArticle)
                 {
                     MorfoGram mgFS = new MorfoGram(mgFemSg);
                     mgFS.Cat = morfoGram.Cat;
                     par = new PC_multi(par, new PC_formaFixada("femení singular, D+, L+", mgFS, pFem, true, true));
                     // PERFER: No hauríem d'admetre "d'" ja que està inclòs dins l'altre paradigma
                 }
                 return par;
             }
         }
         return new PC_multi(Id2(masc, mgMascSg, dades, exc), Id2(fem, mgFemSg, dades, exc));
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Afegeix un participi a la llista d'ítems.
 /// Si comença per vocal, li afegeix el flag que permet "d'" i el que permet "l'".
 /// Si comença per vocal, crida AfegeixParFemSg per si la forma femenina singular també pot dur l'article
 /// apostrofat.
 /// </summary>
 protected void AfegeixParticipi(List<ItemDic> items, string mascSg, MorfoGram mgComuna, MorfoGram mgArrel,
     Marques filtre, params string[] flags)
 {
     AfegeixItem(items, mascSg, mgComuna, mgArrel, flags);
     if (Paraula.TeVocalInicial(mascSg))
     {
         AfegeixItem(items, mascSg, mgComuna, mgArrel, "V", "Y");
         AfegeixParFemSg(items, mascSg, filtre);
     }
 }
Exemplo n.º 25
0
 /// <summary>
 /// Genera mots a partir d'una arrel. Els mots creats s'afegeixen a la llista donada.
 /// </summary>
 /// <param name="mots">La llista que recull els mots creats.</param>
 /// <param name="arrel">L'arrel a la qual s'ha d'aplicar el cas.</param>
 /// <param name="infoComuna">Informació morfològica que s'ha d'afegir a la del cas.
 /// Pot ser informació comuna a totes les formes d'una entrada.</param>
 /// <param name="regles">Llista de regles en vigor, per si està definit mesRegles</param>
 /// <param name="filtre">Només es generen mots que tenen marques contingudes en aquest filtre.</param>
 /// <param name="nomesAfixos">Si és true, només s'apliquen les regles amb la propietat EsAfix = true.</param>
 /// <returns>El nombre de mots afegits.</returns>
 public int Genera(string arrel, ref List<Mot> mots, MorfoGram infoComuna, Regles regles, Marques filtre, bool nomesAfixos)
 {
     if ((suprimir > arrel.Length) || (condicio != null && !condicio.IsMatch(arrel)) || !filtre.Conte(Marca))
         return 0;
     int afegits = 0;
     string forma;
     if (sufix)
         forma = arrel.Substring(0, arrel.Length - suprimir) + afegir;
     else
         forma = afegir + arrel.Substring(suprimir);
     Mot motBase = new Mot(forma, this, infoComuna);
     mots.Add(motBase);
     afegits += 1;
     if (mesRegles != null)
         foreach (string idRegla in mesRegles)
         {
             Regla regla = regles.Llista[idRegla];
             if (nomesAfixos && !regla.EsAfix)
                 continue;
             List<Mot> nous = regla.Genera(forma, motBase.Info, regles, filtre, nomesAfixos);
             if (mesRegles.Count > 1)
             {
                 foreach (string idRegla2 in mesRegles)
                 {
                     if (idRegla == idRegla2)
                         continue;
                     Regla regla2 = regles.Llista[idRegla2];
                     if (nomesAfixos && !regla2.EsAfix)
                         continue;
                     List<Mot> nous2;
                     foreach (Mot mot in nous)
                     {
                         nous2 = regla2.Genera(mot.Forma, mot.Info, regles, filtre, nomesAfixos);
                         mots.AddRange(nous2);
                         afegits += nous2.Count;
                     }
                 }
             }
             mots.AddRange(nous);
             afegits += nous.Count;
         }
     return afegits;
 }
Exemplo n.º 26
0
 public static int Cmp(MorfoGram mf1, MorfoGram mf2)
 {
     if ((mf1 == null) && (mf2 == null)) return 0;
     if (mf1 == null) return -1;
     if (mf2 == null) return 1;
     if (mf1.Cat != mf2.Cat) return (int)mf1.Cat - (int)mf2.Cat;
     if (mf1.Temps != mf2.Temps) return (int)mf1.Temps - (int)mf2.Temps;
     if (mf1.Pers != mf2.Pers) return (int)mf1.Pers - (int)mf2.Pers;
     if (mf1.Gen != mf2.Gen) return (int)mf1.Gen - (int)mf2.Gen;
     if (mf1.Nbre != mf2.Nbre) return (int)mf1.Nbre - (int)mf2.Nbre;
     return 0;
 }
Exemplo n.º 27
0
 private static Dictionary<string, MorfoGram> creaEtisInfo()
 {
     Dictionary<string, MorfoGram> etis = new Dictionary<string, MorfoGram>();
     // flexió nominal
     etis["PLU"] = new MorfoGram(MorfoGram.eCat.NOCAT, MorfoGram.eNbre.PL);
     etis["FEM"] = new MorfoGram(MorfoGram.eCat.NOCAT, MorfoGram.eGen.F, MorfoGram.eNbre.SG);
     etis["MPL"] = new MorfoGram(MorfoGram.eCat.NOCAT, MorfoGram.eGen.M, MorfoGram.eNbre.PL);
     etis["FPL"] = new MorfoGram(MorfoGram.eCat.NOCAT, MorfoGram.eGen.F, MorfoGram.eNbre.PL);
     // flexió verbal
     etis["INF"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.INF);
     etis["GER"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.GER);
     etis["PAR"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.PAR);
     etis["IPR"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.IPR);
     etis["IIM"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.IIM);
     etis["IPE"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.IPE);
     etis["FUT"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.FUT);
     etis["CON"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.CON);
     etis["SPR"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.SPR);
     etis["SIM"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.SIM);
     etis["IMP"] = new MorfoGram(MorfoGram.eCat.VERB, MorfoGram.eTemps.IMP);
     return etis;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Diu si dos conjunts de trets són unificables.
 /// Un valor és unificable amb ell mateix i amb el valor NOXXX
 /// </summary>
 /// <param name="mf1">Un primer conjunt de trets.</param>
 /// <param name="mf2">Un segon conjunt de trets.</param>
 /// <returns>True si els dos conjunts són unificables.</returns>
 public static bool Unificables(MorfoGram mf1, MorfoGram mf2)
 {
     if (mf1 == null || mf2 == null)
         return true;
     if ((mf1.Cat != eCat.NOCAT) && (mf2.Cat != eCat.NOCAT) && (mf1.Cat != mf2.Cat))
         return false;
     if ((mf1.Temps != eTemps.NOTEMPS) && (mf2.Temps != eTemps.NOTEMPS) && (mf1.Temps != mf2.Temps))
         return false;
     if ((mf1.Pers != ePers.NOPERS) && (mf2.Pers != ePers.NOPERS) && (mf1.Pers != mf2.Pers))
         return false;
     if ((mf1.Gen != eGen.NOGEN) && (mf2.Gen != eGen.NOGEN) && (mf1.Gen != mf2.Gen))
         return false;
     if ((mf1.Nbre != eNbre.NONBRE) && (mf2.Nbre != eNbre.NONBRE) && (mf1.Nbre != mf2.Nbre))
         return false;
     return true;
 }
Exemplo n.º 29
0
 private static Dictionary<string, MorfoGram> CreaTaulaTP()
 {
     Dictionary<string, MorfoGram> taula = new Dictionary<string,MorfoGram>();
     taula.Add("INF0", new MorfoGram(eCat.VERB, eTemps.INF));
     taula.Add("GER0", new MorfoGram(eCat.VERB, eTemps.GER));
     taula.Add("PAR0", new MorfoGram(eCat.VERB, eTemps.PAR, ePers.NOPERS, eGen.M, eNbre.SG));
     taula.Add("PAR1", new MorfoGram(eCat.VERB, eTemps.PAR, ePers.NOPERS, eGen.M, eNbre.SG));
     taula.Add("PAR2", new MorfoGram(eCat.VERB, eTemps.PAR, ePers.NOPERS, eGen.M, eNbre.PL));
     taula.Add("PAR3", new MorfoGram(eCat.VERB, eTemps.PAR, ePers.NOPERS, eGen.F, eNbre.SG));
     taula.Add("PAR4", new MorfoGram(eCat.VERB, eTemps.PAR, ePers.NOPERS, eGen.F, eNbre.PL));
     for (eTemps temps = eTemps.IPR; temps <= eTemps.IMP; ++temps)
     {
         int primera = ((temps == eTemps.IMP) ? 2 : 1);
         for (int p = primera; p <= 6; p++)
         {
             string id = string.Format("{0}{1}", temps, p);
             MorfoGram mg = new MorfoGram(eCat.VERB, temps, (ePers)p);
             taula.Add(id, mg);
         }
     }
     return taula;
 }
Exemplo n.º 30
0
 protected void AfegeixItem(List<ItemDic> llista, string arrel, MorfoGram mgComuna, MorfoGram mgArrel, 
     params string[] flags)
 {
     ItemDic item = llista.Find(delegate(ItemDic i) {
         return (i.Arrel == arrel) && MorfoGram.Unificables(i.mgComuna, mgComuna) && MorfoGram.Unificables(i.mgArrel, mgArrel);
     });
     if (item == null)
     {
         item = new ItemDic(arrel, flags);
         llista.Add(item);
     }
     else
         item.MesFlags(flags);
     item.MesMorfoGram(mgComuna, mgArrel);
 }