Exemplo n.º 1
0
        private static bool subjunctiveReader(string conjugate,
                                              ref PersonList personList)
        {
            bool completed = true;

            string[] replace1 = new string[] { "que ", "qu'" };
            string[] replace2 = new string[] { "j'", "tu ", "il ", "ils ", "nous ", "vous ", "je " };

            foreach (string s in replace1)
            {
                foreach (string s2 in replace2)
                {
                    string rS = s + s2;

                    int matchCount = Regex.Matches(conjugate, "^" + rS).Count;

                    if (matchCount < 1)
                    {
                        continue;
                    }

                    if ((s2 == "j'" || s2 == "je "))
                    {
                        personList.Je = conjugate;
                    }
                    else if (s2 == "tu ")
                    {
                        personList.Tu = conjugate;
                    }
                    else if (s2 == "il ")
                    {
                        personList.Il = conjugate;
                    }
                    else if (s2 == "ils ")
                    {
                        personList.Ils = conjugate;
                    }
                    else if (s2 == "nous ")
                    {
                        personList.Nous = conjugate;
                    }
                    else if (s2 == "vous ")
                    {
                        personList.Vous = conjugate;
                    }
                    else
                    {
                        completed = false;
                    }
                }
            }

            return(completed);
        }
Exemplo n.º 2
0
        public static List <Tense> Get(string source)
        {
            var tenses = new List <Tense>();

            string          blockRegex = "<td width=\\\"221\\\" [\\w\\W]+?>([\\w\\W]+?)<\\/td>";
            MatchCollection matches    = Regex.Matches(source, blockRegex);

            foreach (Match m in matches)
            {
                Tense tense = new Tense();

                // Get the content.
                string content = m.Groups[1].Value.Trim('\n');

                // Get name of the tense being matched.
                string nameRegex = "<span class=\"arial-13-bleu\">(.*?)<\\/span>";
                tense.Name = Regex.Match(content, nameRegex).Groups[1].Value;

                // Get infinitive.
                string fromRegex = "<font color=\"0078FF\">(.*?)<\\/font>";
                string from      = Regex.Match(source, fromRegex).Groups[1].Value.ToLower();
                tense.Infinitive = from;

                // Get the list of conjugated verbs.
                string personsRegex = "(.*?)<span class=\"conjuguaison\">(.*?)<\\/span>";

                PersonList personList = new PersonList();

                foreach (Match person in Regex.Matches(content, personsRegex))
                {
                    string conjugate = (person.Groups[1].Value + person.Groups[2].Value).Trim();
                    string formatted = conjugate.Trim().Remove(0, conjugate.IndexOf(' ') + 1);

                    if (!standardReader(conjugate, formatted, ref personList))
                    {
                        subjunctiveReader(conjugate, ref personList);
                    }
                }
                tense.Person = personList;

                tenses.Add(tense);
            }

            return(tenses);
        }
Exemplo n.º 3
0
        private static bool standardReader(string conjugate, string formatted,
                                           ref PersonList personList)
        {
            bool completed = true;

            if (conjugate.StartsWith("je") || conjugate.StartsWith("j'"))
            {
                personList.Je = Regex.Replace(formatted, "j'(.*?)", "(j') ");
            }
            else if (conjugate.StartsWith("tu"))
            {
                personList.Tu = formatted;
            }
            else if (conjugate.StartsWith("ils"))
            {
                personList.Ils = formatted;
            }
            else if (conjugate.StartsWith("nous"))
            {
                personList.Nous = formatted;
            }
            else if (conjugate.StartsWith("vous"))
            {
                personList.Vous = formatted;
            }
            else if (conjugate.StartsWith("il"))
            {
                personList.Il = formatted;
            }
            else
            {
                completed = false;
            }

            return(completed);
        }
Exemplo n.º 4
0
 /*
  * Serialization
  */
 public Tense(SerializationInfo info, StreamingContext context)
 {
     Infinitive = info.GetString("Infinitive");
     Name       = info.GetString("Name");
     Person     = (PersonList)info.GetValue("Person", typeof(PersonList));
 }
Exemplo n.º 5
0
 public Tense(string infinitive, string name, PersonList person)
 {
     this.Infinitive = infinitive;
     this.Name       = name;
     this.Person     = person;
 }