예제 #1
0
    public void CalculatePersonNamesGrammars()
    {
      Grammars.Include(i => i.Names).Include(i => i.GrammarCases).Load();
      Grammars.ToList().ForEach(gr =>
      {
        var nomcase = gr.GrammarCases.FirstOrDefault(f => f.Case == Case.NOM);
        var names = PersonNames.AsEnumerable().Where(w => Regex.IsMatch(w.Name, $".?{gr.Suffix}{(w.Gender == Gender.M ? nomcase.MForm : nomcase.FForm)}$") && gr.BaseEnding == (w.Gender == Gender.M ? nomcase.MForm : nomcase.FForm) && gr.For == w.Part);
        foreach (var n in names)
        {
          n.Grammar = gr;
          n.GrammarId = gr.Id;
        };
      });

      SaveChanges();
    }
예제 #2
0
    private PersonData ParseSinglePersonData(string text)
    {
      var result = new PersonData();
      string firstName = "";
      string midName = "";
      string lastName = "";
      Gender gender = Gender.N;

      var list = text.ToLower().Trim(' ').Split(' ').Select(s => s.CapitalizeFirstChar()).ToList();

      string foundName = PersonNames.AsEnumerable().Select(s => s.Name).Intersect(list).FirstOrDefault();
      PersonName foundPersonName = FindPersonName(foundName);


      if (foundPersonName != null)
      {
        switch (foundPersonName.Part)
        {
          case NamePart.FIRST:
            firstName = foundName;
            result.FirstName = foundName;
            result.FirstNameGrammar = foundPersonName.Grammar;
            break;
          case NamePart.MID:
            midName = foundName;
            result.MidName = foundName;
            result.MidNameGrammar = foundPersonName.Grammar;
            break;

          default:
            break;
        };

        gender = foundPersonName.Gender;
        result.Gender = foundPersonName.Gender;
        list.Remove(foundName);
      };


      foundName = PersonNames.AsEnumerable().Select(s => s.Name).Intersect(list).FirstOrDefault();
      foundPersonName = FindPersonName(foundName);


      if (foundPersonName != null)
      {
        switch (foundPersonName.Part)
        {
          case NamePart.FIRST:
            firstName = foundName;
            result.FirstName = foundName;
            result.FirstNameGrammar = foundPersonName.Grammar;
            break;
          case NamePart.MID:
            midName = foundName;
            result.MidName = foundName;
            result.MidNameGrammar = foundPersonName.Grammar;
            break;

          default:
            break;
        };

        list.Remove(foundName);
      };


      if (list.Count > 0)
      {
        for (var i = 0; i < list.Count; i++)
        {
          var found = Grammars.AsEnumerable().FirstOrDefault(f => f.For == NamePart.LAST && Regex.IsMatch(list[i], @$".?{(gender.Equals(Gender.M) ? f.MForm : f.FForm)}$"));
          if (found != null)
          {
            lastName = list[i];
            result.LastName = list[i];
            result.LastNameGrammar = found;
          }
        };
      };


      if (string.IsNullOrWhiteSpace(lastName))
      {
        lastName = String.Join(" ", list).Trim(' ');
        var found = Grammars.AsEnumerable().FirstOrDefault(f => f.For == NamePart.LAST && Regex.IsMatch(lastName, @$".?{(gender.Equals(Gender.M) ? f.MForm : f.FForm)}$"));
        if (found != null)
        {
          result.LastName = lastName;
          result.LastNameGrammar = found;
        }
      };


      return result;
    }