Пример #1
0
        static List <string> readSeedData()
        {
            List <string> fileStrings = new List <string>();
            StreamReader  SR;
            string        S;
            string        ending;

            SR = File.OpenText(basedir + @"infinitives.txt");
            while ((S = SR.ReadLine()) != null)
            {
                if (S.IndexOf(@"//") != -1)
                {
                    // double-slash anywhere in the line means skip the whole line (for now)
                    continue;
                }
                S = S.Trim();
                if (S.Length < 3 && S != "ir")
                {
                    Console.WriteLine("skipping " + S + " on loading from file");
                    continue;
                }

                if (S.IndexOf(@"[begin]") != -1)
                {
                    // empty it brutally
                    fileStrings = new List <string>();
                    continue;
                }

                if (S.IndexOf(@"[end]") != -1)
                {
                    // finish off. We only wanted the section
                    break;
                }

                ending = S.Substring(S.Length - 2);

                if (ending != "ar" && ending != "er" && ending != "ir" && S != "pôr")
                {
                    Console.WriteLine("skipping " + S);
                    continue;
                }

#if (pooledregulars)
                if (Regulars.IsRegular(S) && !(S == "falar" || S == "comer" || S == "partir"))
                {
                    Regulars.AddRegular(S);
                }
                else
#endif
                fileStrings.Add(S);
            }
            SR.Close();
            return(fileStrings);
        }
Пример #2
0
 public IActionResult Index(Regulars expr)
 {
     if (ModelState.IsValid)
     {
         OrderData.Items.Add(new Order()
         {
             Name  = expr.Name,
             Count = expr.Count,
             Price = expr.Price,
         });
         return(RedirectToAction("Index"));
     }
     return(View(expr));
 }
Пример #3
0
        static public Verbiage GetAConjugation(Conjugation con)
        {
            string          infinitive;
            string          conjugatedVerb;
            Conjugation     conjugation = con;
            PersonalPronoun pronoun;
            int             index;

            if (personalPronouns.Count * infinitives.Count <= historyList.Count)
            {
                // for really small datasets, elminate possible endless loop
                historyList.RemoveRange(0, historyList.Count);
            }

            do
            {
                pronoun = getPersonalPronoun();
                index   = r.Next(0, infinitives.Count);
            } while (History.isInHistory(index, pronoun, historyList));

            History h = new History(index, pronoun);

            historyList.Add(h);

            infinitive = infinitives[index];

#if (pooledregulars)
            infinitive = Regulars.SubstituteRegular(infinitive);
#endif

            conjugatedVerb = conjugateVerb(infinitive, pronoun, conjugation);

            bool     isIrregular = Verbs.isIrregular(infinitive, conjugation);
            Verbiage verbiage    = new Verbiage(infinitive, conjugatedVerb, pronoun, conjugation, isIrregular);
            return(verbiage);
        }
Пример #4
0
        static public void StaticConstructor(string[] args)
        {
            if (args[0] != null)
            {
                // if directory and exists, set basedir
                basedir = args[0] + @"\";
            }
            r = new Random();

            regulars         = new Regulars();
            personalPronouns = new PersonalPronouns();
            Tenses           = new List <Tense>();
            historyList      = new List <History>();
            mistakes         = new List <Verbiage>();

            Endings[] e = new Endings[3];
            Tense     t;

            // Conjugation.Present
            e[0] = new Endings('a', new string[] { "o", "a", "amos", "am" });
            e[1] = new Endings('e', new string[] { "o", "e", "emos", "em" });
            e[2] = new Endings('i', new string[] { "o", "e", "imos", "em" });
            t    = new Tense(Conjugation.Present, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("dar", new string[] { "dou", "dá", "damos", "dão" }));
            t.addIrregularVerb(new IrregularVerb("dizer", new string[] { "digo", "diz", "dizemos", "dizem" }));
            t.addIrregularVerb(new IrregularVerb("estar", new string[] { "estou", "está", "estamos", "estão" }));
            t.addIrregularVerb(new IrregularVerb("fazer", new string[] { "faço", "faz", "fazemos", "fazem" }));
            t.addIrregularVerb(new IrregularVerb("haver", new string[] { "hei", "há", "havemos", "hão" }));
            t.addIrregularVerb(new IrregularVerb("ir", new string[] { "vou", "vai", "vamos", "vão" }));
            t.addIrregularVerb(new IrregularVerb("poder", new string[] { "posso", "pode", "podemos", "podem" }));
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "ponho", "põe", "pomos", "põem" }));
            t.addIrregularVerb(new IrregularVerb("querer", new string[] { "quero", "quer", "queremos", "querem" }));
            t.addIrregularVerb(new IrregularVerb("saber", new string[] { "sei", "sabe", "sabemos", "sabem" }));
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "sou", "é", "somos", "são" }));
            t.addIrregularVerb(new IrregularVerb("ter", new string[] { "tenho", "tem", "temos", "têm" }));
            t.addIrregularVerb(new IrregularVerb("trazer", new string[] { "trago", "traz", "trazemos", "trazem" }));
            t.addIrregularVerb(new IrregularVerb("ver", new string[] { "vejo", "vê", "vemos", "vêem" }));
            t.addIrregularVerb(new IrregularVerb("vir", new string[] { "venho", "vem", "vimos", "vêm" }));

            t.addIrregularVerb(new IrregularVerb("crer", new string[] { "creio", "crê", "cremos", "crêem" }));
            t.addIrregularVerb(new IrregularVerb("ler", new string[] { "leio", "lê", "lemos", "lêem" }));
            t.addIrregularVerb(new IrregularVerb("medir", new string[] { "meço", "mede", "medimos", "medem" }));
            t.addIrregularVerb(new IrregularVerb("ouvir", new string[] { "ouço", "ouve", "ouvimos", "ouvem" }));
            t.addIrregularVerb(new IrregularVerb("pedir", new string[] { "peço", "pede", "pedimos", "pedem" }));
            t.addIrregularVerb(new IrregularVerb("despedir", new string[] { "despeço", "despede", "despedimos", "despedem" }));
            t.addIrregularVerb(new IrregularVerb("perder", new string[] { "perco", "perde", "perdemos", "perdem" }));
            t.addIrregularVerb(new IrregularVerb("rir", new string[] { "rio", "ri", "rimos", "riem" }));
            t.addIrregularVerb(new IrregularVerb("valer", new string[] { "valho", "vale", "valemos", "valem" }));

            t.addIrregularVerb(new IrregularVerb("boiar", new string[] { "bóio", "bóia", "boiamos", "bóiam" }));
            t.addIrregularVerb(new IrregularVerb("odiar", new string[] { "odeio", "odeia", "odiamos", "odeiam" }));

            t.addIrregularVerb(new IrregularVerb("cear", new string[] { "ceio", "ceia", "ceamos", "ceiam" }));
            t.addIrregularVerb(new IrregularVerb("chatear", new string[] { "chateio", "chateia", "chateamos", "chateiam" }));
            t.addIrregularVerb(new IrregularVerb("passear", new string[] { "passeio", "passeia", "passeamos", "passeiam" }));
            t.addIrregularVerb(new IrregularVerb("recear", new string[] { "receio", "receia", "receamos", "receiam" }));
            t.addIrregularVerb(new IrregularVerb("rechear", new string[] { "recheio", "recheia", "recheamos", "recheiam" }));

            t.addIrregularVerb(new IrregularVerb("erguer", new string[] { "ergo", "ergue", "erguemos", "erguem" }));

            t.addIrregularVerb(new IrregularVerb("aderir", new string[] { "adiro", "adere", "aderimos", "aderem" }));
            t.addIrregularVerb(new IrregularVerb("advertir", new string[] { "advirto", "adverte", "advertimos", "advertem" }));
            //          competir isn't in this category after all (I think)
            t.addIrregularVerb(new IrregularVerb("consentir", new string[] { "consinto", "consente", "consentimos", "consentem" }));
            //          corrigir is misspelled in Sue Tyson-Ward as corregir
            t.addIrregularVerb(new IrregularVerb("despir", new string[] { "dispo", "despe", "despimos", "despem" }));
            t.addIrregularVerb(new IrregularVerb("divertir", new string[] { "divirto", "diverte", "divertimos", "divertem" }));
            t.addIrregularVerb(new IrregularVerb("dormir", new string[] { "durmo", "dorme", "dormimos", "dormem" }));
            t.addIrregularVerb(new IrregularVerb("engolir", new string[] { "engulo", "engole", "engolimos", "engolem" }));
            t.addIrregularVerb(new IrregularVerb("ferir", new string[] { "firo", "fere", "ferimos", "ferem" }));
            t.addIrregularVerb(new IrregularVerb("investir", new string[] { "invisto", "investe", "investimos", "investem" }));
            t.addIrregularVerb(new IrregularVerb("mentir", new string[] { "minto", "mente", "mentimos", "mentem" }));
            t.addIrregularVerb(new IrregularVerb("preferir", new string[] { "prefiro", "prefere", "preferimos", "preferem" }));
            t.addIrregularVerb(new IrregularVerb("pressentir", new string[] { "pressinto", "pressente", "pressentimos", "pressentem" }));
            t.addIrregularVerb(new IrregularVerb("referir", new string[] { "refiro", "refere", "referimos", "referem" }));
            t.addIrregularVerb(new IrregularVerb("repetir", new string[] { "repito", "repete", "repetimos", "repetem" }));
            t.addIrregularVerb(new IrregularVerb("sentir", new string[] { "sinto", "sente", "sentimos", "sentem" }));
            t.addIrregularVerb(new IrregularVerb("servir", new string[] { "sirvo", "serve", "servimos", "servem" }));
            t.addIrregularVerb(new IrregularVerb("sugerir", new string[] { "sugiro", "sugere", "sugerimos", "sugerem" }));
            t.addIrregularVerb(new IrregularVerb("transferir", new string[] { "transfiro", "transfere", "transferimos", "transferem" }));
            t.addIrregularVerb(new IrregularVerb("vestir", new string[] { "visto", "veste", "vestimos", "vestem" }));

            t.addIrregularVerb(new IrregularVerb("cobrir", new string[] { "cubro", "cobre", "cobrimos", "cobrem" }));
            t.addIrregularVerb(new IrregularVerb("descobrir", new string[] { "descubro", "descobre", "descobrimos", "descobrem" }));

            t.addIrregularVerb(new IrregularVerb("conseguir", new string[] { "consigo", "consegue", "conseguimos", "conseguem" }));
            t.addIrregularVerb(new IrregularVerb("seguir", new string[] { "sigo", "segue", "seguimos", "seguem" }));

            t.addIrregularVerb(new IrregularVerb("acudir", new string[] { "acudo", "acode", "acudimos", "acodem" }));
            t.addIrregularVerb(new IrregularVerb("cuspir", new string[] { "cuspo", "cospe", "cuspimos", "cospem" }));
            t.addIrregularVerb(new IrregularVerb("subir", new string[] { "subo", "sobe", "subimos", "sobem" }));
            t.addIrregularVerb(new IrregularVerb("sacudir", new string[] { "sacudo", "sacode", "sacudimos", "sacodem" }));

            t.addIrregularVerb(new IrregularVerb("cair", new string[] { "caio", "cai", "caímos", "caem" }));
            t.addIrregularVerb(new IrregularVerb("sair", new string[] { "saio", "sai", "saímos", "saem" }));

            // Conjugation.Preterite
            e[0] = new Endings('a', new string[] { "ei", "ou", "amos", "aram" });
            e[1] = new Endings('e', new string[] { "i", "eu", "emos", "eram" });
            e[2] = new Endings('i', new string[] { "i", "iu", "imos", "iram" });
            t    = new Tense(Conjugation.Preterite, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("cair", new string[] { "caí", "caiu", "caímos", "caíram" }));
            t.addIrregularVerb(new IrregularVerb("sair", new string[] { "saí", "saiu", "saímos", "saíram" }));

            t.addIrregularVerb(new IrregularVerb("dar", new string[] { "dei", "deu", "demos", "deram" }));
            t.addIrregularVerb(new IrregularVerb("dizer", new string[] { "disse", "disse", "dissemos", "disseram" }));
            t.addIrregularVerb(new IrregularVerb("estar", new string[] { "estive", "esteve", "estivemos", "estiveram" }));
            t.addIrregularVerb(new IrregularVerb("fazer", new string[] { "fiz", "fez", "fizemos", "fizeram" }));
            t.addIrregularVerb(new IrregularVerb("haver", new string[] { "houve", "houve", "houvemos", "houveram" }));
            t.addIrregularVerb(new IrregularVerb("ir", new string[] { "fui", "foi", "fomos", "foram" }));
            t.addIrregularVerb(new IrregularVerb("poder", new string[] { "pude", "pôde", "pudemos", "puderam" }));
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "pus", "pôs", "pusemos", "puseram" }));
            t.addIrregularVerb(new IrregularVerb("querer", new string[] { "quis", "quis", "quisemos", "quiseram" }));
            t.addIrregularVerb(new IrregularVerb("saber", new string[] { "soube", "soube", "soubemos", "souberam" }));
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "fui", "foi", "fomos", "foram" }));
            t.addIrregularVerb(new IrregularVerb("ter", new string[] { "tive", "teve", "tivemos", "tiveram" }));
            t.addIrregularVerb(new IrregularVerb("trazer", new string[] { "trouxe", "trouxe", "trouxemos", "trouxeram" }));
            t.addIrregularVerb(new IrregularVerb("ver", new string[] { "vi", "viu", "vimos", "viram" }));
            t.addIrregularVerb(new IrregularVerb("vir", new string[] { "vim", "veio", "viemos", "vieram" }));

            // Conjugation.Imperfect
            e[0] = new Endings('a', new string[] { "ava", "ava", "ávamos", "avam" });
            e[1] = new Endings('e', new string[] { "ia", "ia", "íamos", "iam" });
            e[2] = new Endings('i', new string[] { "ia", "ia", "íamos", "iam" });
            t    = new Tense(Conjugation.Imperfect, e);
            Tenses.Add(t);

            t.addIrregularVerb(new IrregularVerb("cair", new string[] { "caía", "caía", "caíamos", "caíam" }));
            t.addIrregularVerb(new IrregularVerb("sair", new string[] { "saía", "saía", "saíamos", "saíam" }));

            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "punha", "punha", "púnhamos", "punham" }));
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "era", "era", "éramos", "eram" }));
            t.addIrregularVerb(new IrregularVerb("ter", new string[] { "tinha", "tinha", "tínhamos", "tinham" }));
            t.addIrregularVerb(new IrregularVerb("vir", new string[] { "vinha", "vinha", "vínhamos", "vinham" }));

            // Conjugation.Future
            e[0] = new Endings('a', new string[] { "arei", "ará", "aremos", "arão" });
            e[1] = new Endings('e', new string[] { "erei", "erá", "eremos", "erão" });
            e[2] = new Endings('i', new string[] { "irei", "irá", "iremos", "irão" });
            t    = new Tense(Conjugation.Future, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("fazer", new string[] { "farei", "fará", "faremos", "farão" }));
            t.addIrregularVerb(new IrregularVerb("trazer", new string[] { "trarei", "trará", "traremos", "trarão" }));
            // "unofficial" irregular -- breaks when processed in regular verb conjugation routine
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "porei", "porá", "poremos", "porão" }));

            // Conjugation.Conditional
            e[0] = new Endings('a', new string[] { "aria", "aria", "aríamos", "ariam" });
            e[1] = new Endings('e', new string[] { "eria", "eria", "eríamos", "eriam" });
            e[2] = new Endings('i', new string[] { "iria", "iria", "iríamos", "iriam" });
            t    = new Tense(Conjugation.Conditional, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("dizer", new string[] { "diria", "diria", "diríamos", "diriam" }));
            t.addIrregularVerb(new IrregularVerb("fazer", new string[] { "faria", "faria", "faríamos", "fariam" }));
            t.addIrregularVerb(new IrregularVerb("trazer", new string[] { "traria", "traria", "traríamos", "trariam" }));
            // "unofficial" irregular -- breaks when processed in regular verb conjugation routine
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "poria", "poria", "poríamos", "poriam" }));

            // Conjugation.SubjunctivePresent
            e[0] = new Endings('a', new string[] { "e", "e", "emos", "em" });
            e[1] = new Endings('e', new string[] { "a", "a", "amos", "am" });
            e[2] = new Endings('i', new string[] { "a", "a", "amos", "am" });
            t    = new Tense(Conjugation.SubjunctivePresent, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "seja", "seja", "sejamos", "sejam" }));
            t.addIrregularVerb(new IrregularVerb("estar", new string[] { "esteja", "esteja", "estejamos", "estejam" }));
            t.addIrregularVerb(new IrregularVerb("haver", new string[] { "haja", "haja", "hajamos", "hajam" }));
            t.addIrregularVerb(new IrregularVerb("saber", new string[] { "saiba", "saiba", "saibamos", "saibam" }));
            t.addIrregularVerb(new IrregularVerb("querer", new string[] { "queira", "queira", "queiramos", "queiram" }));
            t.addIrregularVerb(new IrregularVerb("dar", new string[] { "dê", "dê", "dêmos", "dêem" }));
            t.addIrregularVerb(new IrregularVerb("ir", new string[] { "vá", "vá", "vamos", "vão" }));
            // "unofficial" irregular -- breaks when processed in regular verb conjugation routine
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "ponha", "ponha", "ponhamos", "ponham" }));

            // Conjugation.SubjunctiveImperfect
            e[0] = new Endings('a', new string[] { "asse", "asse", "ássemos", "assem" });
            e[1] = new Endings('e', new string[] { "esse", "esse", "êssemos", "essem" });
            e[2] = new Endings('i', new string[] { "isse", "isse", "íssemos", "issem" });
            t    = new Tense(Conjugation.SubjunctiveImperfect, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "fosse", "fosse", "fôssemos", "fossem" }));
            t.addIrregularVerb(new IrregularVerb("estar", new string[] { "estivesse", "estivesse", "estivéssemos", "estivessem" }));
            t.addIrregularVerb(new IrregularVerb("haver", new string[] { "houvesse", "houvesse", "houvéssemos", "houvessem" }));
            t.addIrregularVerb(new IrregularVerb("saber", new string[] { "soubesse", "soubesse", "soubéssemos", "soubessem" }));
            t.addIrregularVerb(new IrregularVerb("querer", new string[] { "quisesse", "quisesse", "quiséssemos", "quisessem" }));
            t.addIrregularVerb(new IrregularVerb("dar", new string[] { "desse", "desse", "déssemos", "dessem" }));
            t.addIrregularVerb(new IrregularVerb("ir", new string[] { "fosse", "fosse", "fôssemos", "fossem" }));
            // "unofficial" irregular -- breaks when processed in regular verb conjugation routine
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "pusesse", "pusesse", "puséssemos", "pusessem" }));
            t.addIrregularVerb(new IrregularVerb("cair", new string[] { "caísse", "caísse", "caíssemos", "caíssem" }));
            t.addIrregularVerb(new IrregularVerb("sair", new string[] { "saísse", "saísse", "saíssemos", "saíssem" }));

            // Conjugation.SubjunctiveFuture
            e[0] = new Endings('a', new string[] { "ar", "ar", "armos", "arem" });
            e[1] = new Endings('e', new string[] { "er", "er", "ermos", "erem" });
            e[2] = new Endings('i', new string[] { "ir", "ir", "irmos", "irem" });
            t    = new Tense(Conjugation.SubjunctiveFuture, e);
            Tenses.Add(t);
            t.addIrregularVerb(new IrregularVerb("ser", new string[] { "for", "for", "formos", "forem" }));
            t.addIrregularVerb(new IrregularVerb("estar", new string[] { "estiver", "estiver", "estivermos", "estiverem" }));
            t.addIrregularVerb(new IrregularVerb("haver", new string[] { "houver", "houver", "houvermos", "houverem" }));
            t.addIrregularVerb(new IrregularVerb("saber", new string[] { "souber", "souber", "soubermos", "souberem" }));
            t.addIrregularVerb(new IrregularVerb("querer", new string[] { "quiser", "quiser", "quisermos", "quiserem" }));
            t.addIrregularVerb(new IrregularVerb("dar", new string[] { "dar", "dar", "darmos", "darem" }));
            t.addIrregularVerb(new IrregularVerb("ir", new string[] { "for", "for", "formos", "forem" }));
            // "unofficial" irregular -- breaks when processed in regular verb conjugation routine
            t.addIrregularVerb(new IrregularVerb("pôr", new string[] { "puser", "puser", "pusermos", "puserem" }));
            t.addIrregularVerb(new IrregularVerb("cair", new string[] { "caír", "caír", "caírmos", "caírem" }));
            t.addIrregularVerb(new IrregularVerb("sair", new string[] { "saír", "saír", "saírmos", "saírem" }));


            infinitives = readSeedData();
        }
Пример #5
0
        public static object Evaluate(string expression)
        {
            expression = expression.Trim();

            //字符串表达式
            var quoteMatch = quoteTextRegex.Match(expression);

            if (quoteMatch.Success)
            {
                return(Regulars.ResolveEscape(quoteMatch.Groups["quoteText"].Value));
            }



            //数值表达式
            var intergerMatch = intergerRegex.Match(expression);
            var decimalMatch  = decimalRegex.Match(expression);

            if (intergerMatch.Success || decimalMatch.Success)
            {
                var d = decimal.Parse(expression);

                if (intergerMatch.Success)
                {
                    if (d > int.MinValue && d < int.MaxValue)
                    {
                        return((int)d);
                    }

                    else if (d > long.MinValue && d < long.MaxValue)
                    {
                        return((long)d);
                    }
                }

                return(d);
            }


            //列表表达式
            var listMatch = listExpressionRegex.Match(expression);

            if (listMatch.Success)
            {
                return(listMatch.Groups["item"].Captures.Cast <Capture>().Select(c => Evaluate(c.Value)).ToArray());
            }



            //特殊值表达式(例如null)
            var specialValueMatch = specialValueRegex.Match(expression);

            if (specialValueMatch.Success)
            {
                switch (specialValueMatch.Groups["name"].Value)
                {
                case "null":
                    return(null);

                default:
                    throw new FormatException();
                }
            }


            //环境变量表达式
            var environmentVariableMatch = environmentVariableRegex.Match(expression);

            if (environmentVariableMatch.Success)
            {
                string providerName = environmentVariableMatch.Groups["prefix"].Value;
                string exp          = environmentVariableMatch.Groups["name"].Value;

                return(EnvironmentExpressions.EvaluateExpression(providerName, exp));
            }

            return(expression);
        }