Esempio n. 1
0
 public string GetWordform(string word, Pullenti.Morph.MorphClass cla, Pullenti.Morph.MorphGender gender, Pullenti.Morph.MorphCase cas, Pullenti.Morph.MorphNumber num, Pullenti.Morph.MorphLang lang, Pullenti.Morph.MorphWordForm addInfo)
 {
     if (Pullenti.Morph.LanguageHelper.IsCyrillicChar(word[0]))
     {
         if (m_EngineRu.Language.IsRu && lang.IsRu)
         {
             return(m_EngineRu.GetWordform(word, cla, gender, cas, num, addInfo));
         }
         if (m_EngineUa.Language.IsUa && lang.IsUa)
         {
             return(m_EngineUa.GetWordform(word, cla, gender, cas, num, addInfo));
         }
         if (m_EngineBy.Language.IsBy && lang.IsBy)
         {
             return(m_EngineBy.GetWordform(word, cla, gender, cas, num, addInfo));
         }
         if (m_EngineKz.Language.IsKz && lang.IsKz)
         {
             return(m_EngineKz.GetWordform(word, cla, gender, cas, num, addInfo));
         }
         return(m_EngineRu.GetWordform(word, cla, gender, cas, num, addInfo));
     }
     else
     {
         return(m_EngineEn.GetWordform(word, cla, gender, cas, num, addInfo));
     }
 }
Esempio n. 2
0
 public static void SetGender(List <PersonMorphCollection> list, Pullenti.Morph.MorphGender gen)
 {
     foreach (PersonMorphCollection li in list)
     {
         li.Remove(null, (gen == Pullenti.Morph.MorphGender.Masculine ? Pullenti.Morph.MorphGender.Feminie : Pullenti.Morph.MorphGender.Masculine));
     }
 }
Esempio n. 3
0
        internal void Deserialize(Stream stream)
        {
            m_Class = new Pullenti.Morph.MorphClass()
            {
                Value = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream)
            };
            m_Case = new Pullenti.Morph.MorphCase()
            {
                Value = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream)
            };
            m_Gender   = (Pullenti.Morph.MorphGender)Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream);
            m_Number   = (Pullenti.Morph.MorphNumber)Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream);
            m_Voice    = (Pullenti.Morph.MorphVoice)Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream);
            m_Language = new Pullenti.Morph.MorphLang()
            {
                Value = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeShort(stream)
            };
            int cou = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);

            m_Items = new List <Pullenti.Morph.MorphBaseInfo>();
            for (int i = 0; i < cou; i++)
            {
                Pullenti.Morph.MorphBaseInfo it = this.DeserializeItem(stream);
                if (it != null)
                {
                    m_Items.Add(it);
                }
            }
            m_NeedRecalc = false;
        }
Esempio n. 4
0
 public static List <string> GetStdAdjFull(Pullenti.Ner.Token t, Pullenti.Morph.MorphGender gen, Pullenti.Morph.MorphNumber num, bool strict)
 {
     if (!(t is Pullenti.Ner.TextToken))
     {
         return(null);
     }
     return(GetStdAdjFullStr((t as Pullenti.Ner.TextToken).Term, gen, num, strict));
 }
Esempio n. 5
0
 public void Add(string val, string shortval, Pullenti.Morph.MorphGender gen, bool addOtherGenderVar = false)
 {
     if (val == null)
     {
         return;
     }
     if (Head == null)
     {
         if (val.Length > 3)
         {
             Head = val.Substring(0, 3);
         }
         else
         {
             Head = val;
         }
     }
     if (gen == Pullenti.Morph.MorphGender.Masculine || gen == Pullenti.Morph.MorphGender.Feminie)
     {
         foreach (PersonMorphVariant it in Items)
         {
             if (it.Value == val && it.Gender == gen)
             {
                 return;
             }
         }
         Items.Add(new PersonMorphVariant()
         {
             Value = val, Gender = gen, ShortValue = shortval
         });
         if (addOtherGenderVar)
         {
             Pullenti.Morph.MorphGender g0 = (gen == Pullenti.Morph.MorphGender.Feminie ? Pullenti.Morph.MorphGender.Masculine : Pullenti.Morph.MorphGender.Feminie);
             string v = Pullenti.Morph.MorphologyService.GetWordform(val, new Pullenti.Morph.MorphBaseInfo()
             {
                 Class = new Pullenti.Morph.MorphClass()
                 {
                     IsProperSurname = true
                 }, Gender = g0
             });
             if (v != null)
             {
                 Items.Add(new PersonMorphVariant()
                 {
                     Value = v, Gender = g0, ShortValue = shortval
                 });
             }
         }
     }
     else
     {
         this.Add(val, shortval, Pullenti.Morph.MorphGender.Masculine, false);
         this.Add(val, shortval, Pullenti.Morph.MorphGender.Feminie, false);
     }
 }
Esempio n. 6
0
 bool ContainsItem(string v, Pullenti.Morph.MorphGender g)
 {
     foreach (PersonMorphVariant it in Items)
     {
         if (it.Value == v && it.Gender == g)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 7
0
        public static void Initialize()
        {
            if (m_Inited)
            {
                return;
            }
            m_Inited = true;
            string obj = ResourceHelper.GetString("ShortNames.txt");

            if (obj != null)
            {
                Pullenti.Ner.Core.AnalysisKit kit = new Pullenti.Ner.Core.AnalysisKit(new Pullenti.Ner.SourceOfAnalysis(obj));
                for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next)
                {
                    if (t.IsNewlineBefore)
                    {
                        Pullenti.Morph.MorphGender g = (t.IsValue("F", null) ? Pullenti.Morph.MorphGender.Feminie : Pullenti.Morph.MorphGender.Masculine);
                        t = t.Next;
                        string        nam  = (t as Pullenti.Ner.TextToken).Term;
                        List <string> shos = new List <string>();
                        for (t = t.Next; t != null; t = t.Next)
                        {
                            if (t.IsNewlineBefore)
                            {
                                break;
                            }
                            else
                            {
                                shos.Add((t as Pullenti.Ner.TextToken).Term);
                            }
                        }
                        foreach (string s in shos)
                        {
                            List <ShortnameVar> li = null;
                            if (!m_Shorts_Names.TryGetValue(s, out li))
                            {
                                m_Shorts_Names.Add(s, (li = new List <ShortnameVar>()));
                            }
                            li.Add(new ShortnameVar()
                            {
                                Name = nam, Gender = g
                            });
                        }
                        if (t == null)
                        {
                            break;
                        }
                        t = t.Previous;
                    }
                }
            }
        }
Esempio n. 8
0
 public void RemoveItems(Pullenti.Morph.MorphGender gen)
 {
     if (m_Items == null)
     {
         return;
     }
     for (int i = m_Items.Count - 1; i >= 0; i--)
     {
         if (((m_Items[i].Gender & gen)) == Pullenti.Morph.MorphGender.Undefined)
         {
             m_Items.RemoveAt(i);
             m_NeedRecalc = true;
         }
     }
 }
Esempio n. 9
0
        public bool Remove(string val, Pullenti.Morph.MorphGender gen)
        {
            bool ret = false;

            for (int i = Items.Count - 1; i >= 0; i--)
            {
                if (val != null && Items[i].Value != val)
                {
                    continue;
                }
                if (gen != Pullenti.Morph.MorphGender.Undefined && Items[i].Gender != gen)
                {
                    continue;
                }
                Items.RemoveAt(i);
                ret = true;
            }
            return(ret);
        }
Esempio n. 10
0
        public static PersonMorphCollection AddPrefix(PersonMorphCollection prefix, PersonMorphCollection body)
        {
            PersonMorphCollection res = new PersonMorphCollection();

            res.Head = string.Format("{0}-{1}", prefix.Head, body.Head);
            foreach (PersonMorphVariant pv in prefix.Items)
            {
                foreach (PersonMorphVariant bv in body.Items)
                {
                    Pullenti.Morph.MorphGender g = bv.Gender;
                    if (g == Pullenti.Morph.MorphGender.Undefined)
                    {
                        g = pv.Gender;
                    }
                    else if (pv.Gender != Pullenti.Morph.MorphGender.Undefined && pv.Gender != g)
                    {
                        g = Pullenti.Morph.MorphGender.Undefined;
                    }
                    res.Add(string.Format("{0}-{1}", pv.Value, bv.Value), null, g, false);
                }
            }
            return(res);
        }
Esempio n. 11
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            StringBuilder res = new StringBuilder();

            if (gender == Pullenti.Morph.MorphGender.Undefined)
            {
                gender = Morph.Gender;
            }
            if (Adverbs != null && Adverbs.Count > 0)
            {
                int i = 0;
                if (Adjectives.Count > 0)
                {
                    for (int j = 0; j < Adjectives.Count; j++)
                    {
                        for (; i < Adverbs.Count; i++)
                        {
                            if (Adverbs[i].BeginChar < Adjectives[j].BeginChar)
                            {
                                res.AppendFormat("{0} ", Adverbs[i].GetNormalCaseText(Pullenti.Morph.MorphClass.Adverb, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false));
                            }
                            else
                            {
                                break;
                            }
                        }
                        string s = Adjectives[j].GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective | Pullenti.Morph.MorphClass.Pronoun, num, gender, keepChars);
                        res.AppendFormat("{0} ", s ?? "?");
                    }
                }
                for (; i < Adverbs.Count; i++)
                {
                    res.AppendFormat("{0} ", Adverbs[i].GetNormalCaseText(Pullenti.Morph.MorphClass.Adverb, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false));
                }
            }
            else
            {
                foreach (Pullenti.Ner.MetaToken t in Adjectives)
                {
                    string s = t.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective | Pullenti.Morph.MorphClass.Pronoun, num, gender, keepChars);
                    res.AppendFormat("{0} ", s ?? "?");
                }
            }
            string r = null;

            if ((Noun.BeginToken is Pullenti.Ner.ReferentToken) && Noun.BeginToken == Noun.EndToken)
            {
                r = Noun.BeginToken.GetNormalCaseText(null, num, gender, keepChars);
            }
            else
            {
                Pullenti.Morph.MorphClass cas = Pullenti.Morph.MorphClass.Noun | Pullenti.Morph.MorphClass.Pronoun;
                if (mc != null && !mc.IsUndefined)
                {
                    cas = mc;
                }
                r = Noun.GetNormalCaseText(cas, num, gender, keepChars);
            }
            if (r == null || r == "?")
            {
                r = Noun.GetNormalCaseText(null, num, Pullenti.Morph.MorphGender.Undefined, false);
            }
            res.Append(r ?? Noun.ToString());
            return(res.ToString());
        }
Esempio n. 12
0
 internal void CorrectData()
 {
     Pullenti.Morph.MorphGender g = Pullenti.Morph.MorphGender.Undefined;
     while (true)
     {
         bool ch = false;
         if (Pullenti.Ner.Person.Internal.PersonMorphCollection.Intersect(m_SurnameOccurs))
         {
             ch = true;
         }
         if (Pullenti.Ner.Person.Internal.PersonMorphCollection.Intersect(m_NameOccurs))
         {
             ch = true;
         }
         if (Pullenti.Ner.Person.Internal.PersonMorphCollection.Intersect(m_SecOccurs))
         {
             ch = true;
         }
         if (Pullenti.Ner.Person.Internal.PersonMorphCollection.Intersect(m_IdentOccurs))
         {
             ch = true;
         }
         if (!ch)
         {
             break;
         }
         if (g == Pullenti.Morph.MorphGender.Undefined && m_SurnameOccurs.Count > 0 && m_SurnameOccurs[0].Gender != Pullenti.Morph.MorphGender.Undefined)
         {
             g = m_SurnameOccurs[0].Gender;
         }
         if (g == Pullenti.Morph.MorphGender.Undefined && m_NameOccurs.Count > 0 && m_NameOccurs[0].Gender != Pullenti.Morph.MorphGender.Undefined)
         {
             g = m_NameOccurs[0].Gender;
         }
         if (g == Pullenti.Morph.MorphGender.Undefined && m_IdentOccurs.Count > 0 && m_IdentOccurs[0].Gender != Pullenti.Morph.MorphGender.Undefined)
         {
             g = m_IdentOccurs[0].Gender;
         }
         if (g != Pullenti.Morph.MorphGender.Undefined)
         {
             Pullenti.Ner.Person.Internal.PersonMorphCollection.SetGender(m_SurnameOccurs, g);
             Pullenti.Ner.Person.Internal.PersonMorphCollection.SetGender(m_NameOccurs, g);
             Pullenti.Ner.Person.Internal.PersonMorphCollection.SetGender(m_SecOccurs, g);
             Pullenti.Ner.Person.Internal.PersonMorphCollection.SetGender(m_IdentOccurs, g);
         }
     }
     if (g != Pullenti.Morph.MorphGender.Undefined)
     {
         if (!IsFemale && !IsMale)
         {
             if (g == Pullenti.Morph.MorphGender.Masculine)
             {
                 IsMale = true;
             }
             else
             {
                 IsFemale = true;
             }
         }
     }
     this.CorrectSurnames();
     this.CorrectIdentifiers();
     this.CorrectAttrs();
     this.RemoveSlots(ATTR_LASTNAME, m_SurnameOccurs);
     this.RemoveSlots(ATTR_FIRSTNAME, m_NameOccurs);
     this.RemoveSlots(ATTR_MIDDLENAME, m_SecOccurs);
     this.RemoveSlots(ATTR_IDENTITY, m_IdentOccurs);
     this.RemoveInitials(ATTR_FIRSTNAME);
     this.RemoveInitials(ATTR_MIDDLENAME);
 }
Esempio n. 13
0
        public static string GetNameEx(Pullenti.Ner.Token begin, Pullenti.Ner.Token end, Pullenti.Morph.MorphClass cla, Pullenti.Morph.MorphCase mc, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool ignoreBracketsAndHiphens = false, bool ignoreGeoReferent = false)
        {
            if (end == null || begin == null)
            {
                return(null);
            }
            if (begin.EndChar > end.BeginChar && begin != end)
            {
                return(null);
            }
            StringBuilder res    = new StringBuilder();
            string        prefix = null;

            for (Pullenti.Ner.Token t = begin; t != null && t.EndChar <= end.EndChar; t = t.Next)
            {
                if (res.Length > 1000)
                {
                    break;
                }
                if (t.IsTableControlChar)
                {
                    continue;
                }
                if (ignoreBracketsAndHiphens)
                {
                    if (BracketHelper.IsBracket(t, false))
                    {
                        if (t == end)
                        {
                            break;
                        }
                        if (t.IsCharOf("(<["))
                        {
                            BracketSequenceToken br = BracketHelper.TryParse(t, BracketParseAttr.No, 100);
                            if (br != null && br.EndChar <= end.EndChar)
                            {
                                string tmp = GetNameEx(br.BeginToken.Next, br.EndToken.Previous, Pullenti.Morph.MorphClass.Undefined, Pullenti.Morph.MorphCase.Undefined, Pullenti.Morph.MorphGender.Undefined, ignoreBracketsAndHiphens, false);
                                if (tmp != null)
                                {
                                    if ((br.EndChar == end.EndChar && br.BeginToken.Next == br.EndToken.Previous && !br.BeginToken.Next.Chars.IsLetter) && !(br.BeginToken.Next is Pullenti.Ner.ReferentToken))
                                    {
                                    }
                                    else
                                    {
                                        res.AppendFormat(" {0}{1}{2}", t.GetSourceText(), tmp, br.EndToken.GetSourceText());
                                    }
                                }
                                t = br.EndToken;
                            }
                        }
                        continue;
                    }
                    if (t.IsHiphen)
                    {
                        if (t == end)
                        {
                            break;
                        }
                        else if (t.IsWhitespaceBefore || t.IsWhitespaceAfter)
                        {
                            continue;
                        }
                    }
                }
                Pullenti.Ner.TextToken tt = t as Pullenti.Ner.TextToken;
                if (tt != null)
                {
                    if (!ignoreBracketsAndHiphens)
                    {
                        if ((tt.Next != null && tt.Next.IsHiphen && (tt.Next.Next is Pullenti.Ner.TextToken)) && tt != end && tt.Next != end)
                        {
                            if (prefix == null)
                            {
                                prefix = tt.Term;
                            }
                            else
                            {
                                prefix = string.Format("{0}-{1}", prefix, tt.Term);
                            }
                            t = tt.Next;
                            if (t == end)
                            {
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    string s = null;
                    if (cla.Value != 0 || !mc.IsUndefined || gender != Pullenti.Morph.MorphGender.Undefined)
                    {
                        foreach (Pullenti.Morph.MorphBaseInfo wff in tt.Morph.Items)
                        {
                            Pullenti.Morph.MorphWordForm wf = wff as Pullenti.Morph.MorphWordForm;
                            if (wf == null)
                            {
                                continue;
                            }
                            if (cla.Value != 0)
                            {
                                if (((wf.Class.Value & cla.Value)) == 0)
                                {
                                    continue;
                                }
                            }
                            if (!mc.IsUndefined)
                            {
                                if (((wf.Case & mc)).IsUndefined)
                                {
                                    continue;
                                }
                            }
                            if (gender != Pullenti.Morph.MorphGender.Undefined)
                            {
                                if (((wf.Gender & gender)) == Pullenti.Morph.MorphGender.Undefined)
                                {
                                    continue;
                                }
                            }
                            if (s == null || wf.NormalCase == tt.Term)
                            {
                                s = wf.NormalCase;
                            }
                        }
                        if (s == null && gender != Pullenti.Morph.MorphGender.Undefined)
                        {
                            foreach (Pullenti.Morph.MorphBaseInfo wff in tt.Morph.Items)
                            {
                                Pullenti.Morph.MorphWordForm wf = wff as Pullenti.Morph.MorphWordForm;
                                if (wf == null)
                                {
                                    continue;
                                }
                                if (cla.Value != 0)
                                {
                                    if (((wf.Class.Value & cla.Value)) == 0)
                                    {
                                        continue;
                                    }
                                }
                                if (!mc.IsUndefined)
                                {
                                    if (((wf.Case & mc)).IsUndefined)
                                    {
                                        continue;
                                    }
                                }
                                if (s == null || wf.NormalCase == tt.Term)
                                {
                                    s = wf.NormalCase;
                                }
                            }
                        }
                    }
                    if (s == null)
                    {
                        s = tt.Term;
                        if (tt.Chars.IsLastLower && tt.LengthChar > 2)
                        {
                            s = tt.GetSourceText();
                            for (int i = s.Length - 1; i >= 0; i--)
                            {
                                if (char.IsUpper(s[i]))
                                {
                                    s = s.Substring(0, i + 1);
                                    break;
                                }
                            }
                        }
                    }
                    if (prefix != null)
                    {
                        string delim = "-";
                        if (ignoreBracketsAndHiphens)
                        {
                            delim = " ";
                        }
                        s = string.Format("{0}{1}{2}", prefix, delim, s);
                    }
                    prefix = null;
                    if (res.Length > 0 && s.Length > 0)
                    {
                        if (char.IsLetterOrDigit(s[0]))
                        {
                            char ch0 = res[res.Length - 1];
                            if (ch0 == '-')
                            {
                            }
                            else
                            {
                                res.Append(' ');
                            }
                        }
                        else if (!ignoreBracketsAndHiphens && BracketHelper.CanBeStartOfSequence(tt, false, false))
                        {
                            res.Append(' ');
                        }
                    }
                    res.Append(s);
                }
                else if (t is Pullenti.Ner.NumberToken)
                {
                    if (res.Length > 0)
                    {
                        if (!t.IsWhitespaceBefore && res[res.Length - 1] == '-')
                        {
                        }
                        else
                        {
                            res.Append(' ');
                        }
                    }
                    Pullenti.Ner.NumberToken nt = t as Pullenti.Ner.NumberToken;
                    if ((t.Morph.Class.IsAdjective && nt.Typ == Pullenti.Ner.NumberSpellingType.Words && nt.BeginToken == nt.EndToken) && (nt.BeginToken is Pullenti.Ner.TextToken))
                    {
                        res.Append((nt.BeginToken as Pullenti.Ner.TextToken).Term);
                    }
                    else
                    {
                        res.Append(nt.Value);
                    }
                }
                else if (t is Pullenti.Ner.MetaToken)
                {
                    if ((ignoreGeoReferent && t != begin && t.GetReferent() != null) && t.GetReferent().TypeName == "GEO")
                    {
                        continue;
                    }
                    string s = GetNameEx((t as Pullenti.Ner.MetaToken).BeginToken, (t as Pullenti.Ner.MetaToken).EndToken, cla, mc, gender, ignoreBracketsAndHiphens, ignoreGeoReferent);
                    if (!string.IsNullOrEmpty(s))
                    {
                        if (res.Length > 0)
                        {
                            if (!t.IsWhitespaceBefore && res[res.Length - 1] == '-')
                            {
                            }
                            else
                            {
                                res.Append(' ');
                            }
                        }
                        res.Append(s);
                    }
                }
                if (t == end)
                {
                    break;
                }
            }
            if (res.Length == 0)
            {
                return(null);
            }
            return(res.ToString());
        }
Esempio n. 14
0
        public Pullenti.Morph.MorphBaseInfo FindItem(Pullenti.Morph.MorphCase cas, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gen = Pullenti.Morph.MorphGender.Undefined)
        {
            if (m_Items == null)
            {
                return(null);
            }
            Pullenti.Morph.MorphBaseInfo res = null;
            int maxCoef = 0;

            foreach (Pullenti.Morph.MorphBaseInfo it in m_Items)
            {
                if (!cas.IsUndefined)
                {
                    if (((it.Case & cas)).IsUndefined)
                    {
                        continue;
                    }
                }
                if (num != Pullenti.Morph.MorphNumber.Undefined)
                {
                    if (((num & it.Number)) == Pullenti.Morph.MorphNumber.Undefined)
                    {
                        continue;
                    }
                }
                if (gen != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (((gen & it.Gender)) == Pullenti.Morph.MorphGender.Undefined)
                    {
                        continue;
                    }
                }
                Pullenti.Morph.MorphWordForm wf = it as Pullenti.Morph.MorphWordForm;
                if (wf != null && wf.UndefCoef > 0)
                {
                    if (wf.UndefCoef > maxCoef)
                    {
                        maxCoef = wf.UndefCoef;
                        res     = it;
                    }
                    continue;
                }
                return(it);
            }
            return(res);
        }
Esempio n. 15
0
 public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
 {
     return(base.GetNormalCaseText(Pullenti.Morph.MorphClass.Verb, num, gender, keepChars));
 }
Esempio n. 16
0
 /// <summary>
 /// Удалить элементы, не соответствующие параметрам
 /// </summary>
 public void RemoveItems(Pullenti.Morph.MorphBaseInfo inf)
 {
     if (m_Items == null)
     {
         return;
     }
     if (m_Items.Count == 0)
     {
         if (inf.Gender != Pullenti.Morph.MorphGender.Undefined)
         {
             m_Gender &= inf.Gender;
         }
         if (inf.Number != Pullenti.Morph.MorphNumber.Undefined)
         {
             m_Number &= inf.Number;
         }
         if (!inf.Case.IsUndefined)
         {
             m_Case &= inf.Case;
         }
         return;
     }
     for (int i = m_Items.Count - 1; i >= 0; i--)
     {
         bool ok = true;
         Pullenti.Morph.MorphBaseInfo it = m_Items[i];
         if (inf.Gender != Pullenti.Morph.MorphGender.Undefined)
         {
             if (((it.Gender & inf.Gender)) == Pullenti.Morph.MorphGender.Undefined)
             {
                 ok = false;
             }
         }
         bool chNum = false;
         if (inf.Number != Pullenti.Morph.MorphNumber.Plural && inf.Number != Pullenti.Morph.MorphNumber.Undefined)
         {
             if (((it.Number & inf.Number)) == Pullenti.Morph.MorphNumber.Undefined)
             {
                 ok = false;
             }
             chNum = true;
         }
         if (!inf.Class.IsUndefined)
         {
             if (((inf.Class & it.Class)).IsUndefined)
             {
                 ok = false;
             }
         }
         if (!inf.Case.IsUndefined)
         {
             if (((inf.Case & it.Case)).IsUndefined)
             {
                 ok = false;
             }
         }
         if (!ok)
         {
             m_Items.RemoveAt(i);
             m_NeedRecalc = true;
         }
         else
         {
             if (!inf.Case.IsUndefined)
             {
                 if (it.Case != ((inf.Case & it.Case)))
                 {
                     it.Case      = (inf.Case & it.Case);
                     m_NeedRecalc = true;
                 }
             }
             if (inf.Gender != Pullenti.Morph.MorphGender.Undefined)
             {
                 if (it.Gender != ((inf.Gender & it.Gender)))
                 {
                     it.Gender    = (inf.Gender & it.Gender);
                     m_NeedRecalc = true;
                 }
             }
             if (chNum)
             {
                 if (it.Number != ((inf.Number & it.Number)))
                 {
                     it.Number    = (inf.Number & it.Number);
                     m_NeedRecalc = true;
                 }
             }
         }
     }
 }
Esempio n. 17
0
        void _recalc()
        {
            m_NeedRecalc = false;
            if (m_Items == null || m_Items.Count == 0)
            {
                return;
            }
            m_Class  = new Pullenti.Morph.MorphClass();
            m_Gender = Pullenti.Morph.MorphGender.Undefined;
            bool g = m_Gender == Pullenti.Morph.MorphGender.Undefined;

            m_Number = Pullenti.Morph.MorphNumber.Undefined;
            bool n = m_Number == Pullenti.Morph.MorphNumber.Undefined;

            m_Case = new Pullenti.Morph.MorphCase();
            bool ca = m_Case.IsUndefined;
            bool la = m_Language == null || m_Language.IsUndefined;

            m_Voice = Pullenti.Morph.MorphVoice.Undefined;
            bool verbHasUndef = false;

            if (m_Items != null)
            {
                foreach (Pullenti.Morph.MorphBaseInfo it in m_Items)
                {
                    m_Class.Value |= it.Class.Value;
                    if (g)
                    {
                        m_Gender |= it.Gender;
                    }
                    if (ca)
                    {
                        m_Case |= it.Case;
                    }
                    if (n)
                    {
                        m_Number |= it.Number;
                    }
                    if (la)
                    {
                        m_Language.Value |= it.Language.Value;
                    }
                    if (it.Class.IsVerb)
                    {
                        if (it is Pullenti.Morph.MorphWordForm)
                        {
                            Pullenti.Morph.MorphVoice v = (it as Pullenti.Morph.MorphWordForm).Misc.Voice;
                            if (v == Pullenti.Morph.MorphVoice.Undefined)
                            {
                                verbHasUndef = true;
                            }
                            else
                            {
                                m_Voice |= v;
                            }
                        }
                    }
                }
            }
            if (verbHasUndef)
            {
                m_Voice = Pullenti.Morph.MorphVoice.Undefined;
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Получить связанный с токеном текст в именительном падеже
 /// </summary>
 /// <param name="mc">желательная часть речи</param>
 /// <param name="num">желательное число</param>
 /// <param name="gender">желательный пол</param>
 /// <param name="keepChars">сохранять регистр символов (по умолчанию, всё в верхний)</param>
 /// <return>строка текста</return>
 public virtual string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
 {
     return(this.ToString());
 }
Esempio n. 19
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            string res = Normal;

            if (keepChars)
            {
                if (Chars.IsAllLower)
                {
                    res = res.ToLower();
                }
                else if (Chars.IsAllUpper)
                {
                }
                else if (Chars.IsCapitalUpper)
                {
                    res = MiscHelper.ConvertFirstCharUpperAndOtherLower(res);
                }
            }
            return(res);
        }
Esempio n. 20
0
        StatisticWordInfo AddToken(Pullenti.Ner.TextToken tt)
        {
            List <string> vars = new List <string>();

            vars.Add(tt.Term);
            string s = MiscHelper.GetAbsoluteNormalValue(tt.Term, false);

            if (s != null && !vars.Contains(s))
            {
                vars.Add(s);
            }
            foreach (Pullenti.Morph.MorphBaseInfo wff in tt.Morph.Items)
            {
                Pullenti.Morph.MorphWordForm wf = wff as Pullenti.Morph.MorphWordForm;
                if (wf == null)
                {
                    continue;
                }
                if (wf.NormalCase != null && !vars.Contains(wf.NormalCase))
                {
                    vars.Add(wf.NormalCase);
                }
                if (wf.NormalFull != null && !vars.Contains(wf.NormalFull))
                {
                    vars.Add(wf.NormalFull);
                }
            }
            StatisticWordInfo res = null;

            foreach (string v in vars)
            {
                if (m_Items.TryGetValue(v, out res))
                {
                    break;
                }
            }
            if (res == null)
            {
                res = new StatisticWordInfo()
                {
                    Normal = tt.Lemma
                }
            }
            ;
            foreach (string v in vars)
            {
                if (!m_Items.ContainsKey(v))
                {
                    m_Items.Add(v, res);
                }
            }
            res.TotalCount++;
            if ((tt.Next is Pullenti.Ner.TextToken) && tt.Next.Chars.IsAllLower)
            {
                if (tt.Next.Chars.IsCyrillicLetter && tt.Next.GetMorphClassInDictionary().IsVerb)
                {
                    Pullenti.Morph.MorphGender g = tt.Next.Morph.Gender;
                    if (g == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.FemaleVerbsAfterCount++;
                    }
                    else if (((g & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                    {
                        res.MaleVerbsAfterCount++;
                    }
                }
            }
            if (tt.Previous != null)
            {
                if ((tt.Previous is Pullenti.Ner.TextToken) && tt.Previous.Chars.IsLetter && !tt.Previous.Chars.IsAllLower)
                {
                }
                else
                {
                    res.NotCapitalBeforeCount++;
                }
            }
            return(res);
        }

        Dictionary <string, StatisticWordInfo> m_Items = new Dictionary <string, StatisticWordInfo>();
        StatisticWordInfo FindItem(Pullenti.Ner.TextToken tt, bool doAbsolute = true)
        {
            if (tt == null)
            {
                return(null);
            }
            StatisticWordInfo res;

            if (m_Items.TryGetValue(tt.Term, out res))
            {
                return(res);
            }
            if (doAbsolute)
            {
                string s = MiscHelper.GetAbsoluteNormalValue(tt.Term, false);
                if (s != null)
                {
                    if (m_Items.TryGetValue(s, out res))
                    {
                        return(res);
                    }
                }
            }
            foreach (Pullenti.Morph.MorphBaseInfo wff in tt.Morph.Items)
            {
                Pullenti.Morph.MorphWordForm wf = wff as Pullenti.Morph.MorphWordForm;
                if (wf == null)
                {
                    continue;
                }
                if (m_Items.TryGetValue(wf.NormalCase ?? "", out res))
                {
                    return(res);
                }
                if (wf.NormalFull != null && m_Items.TryGetValue(wf.NormalFull, out res))
                {
                    return(res);
                }
            }
            return(null);
        }

        void AddBigramm(StatisticWordInfo b1, StatisticWordInfo b2)
        {
            Dictionary <string, int> di;

            if (!m_Bigramms.TryGetValue(b1.Normal, out di))
            {
                m_Bigramms.Add(b1.Normal, (di = new Dictionary <string, int>()));
            }
            if (di.ContainsKey(b2.Normal))
            {
                di[b2.Normal]++;
            }
            else
            {
                di.Add(b2.Normal, 1);
            }
            if (!m_BigrammsRev.TryGetValue(b2.Normal, out di))
            {
                m_BigrammsRev.Add(b2.Normal, (di = new Dictionary <string, int>()));
            }
            if (di.ContainsKey(b1.Normal))
            {
                di[b1.Normal]++;
            }
            else
            {
                di.Add(b1.Normal, 1);
            }
        }

        Dictionary <string, Dictionary <string, int> > m_Bigramms    = new Dictionary <string, Dictionary <string, int> >();
        Dictionary <string, Dictionary <string, int> > m_BigrammsRev = new Dictionary <string, Dictionary <string, int> >();
        Dictionary <string, Dictionary <string, int> > m_Initials    = new Dictionary <string, Dictionary <string, int> >();
        Dictionary <string, Dictionary <string, int> > m_InitialsRev = new Dictionary <string, Dictionary <string, int> >();
Esempio n. 21
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            bool empty = true;

            if (mc != null && mc.IsPreposition)
            {
                return(Pullenti.Morph.LanguageHelper.NormalizePreposition(Term));
            }
            foreach (Pullenti.Morph.MorphBaseInfo it in Morph.Items)
            {
                if (mc != null && !mc.IsUndefined)
                {
                    Pullenti.Morph.MorphClass cc = it.Class & mc;
                    if (cc.IsUndefined)
                    {
                        continue;
                    }
                    if (cc.IsMisc && !cc.IsProper && mc != it.Class)
                    {
                        continue;
                    }
                }
                Pullenti.Morph.MorphWordForm wf = it as Pullenti.Morph.MorphWordForm;
                bool normalFull = false;
                if (gender != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (((it.Gender & gender)) == Pullenti.Morph.MorphGender.Undefined)
                    {
                        if ((gender == Pullenti.Morph.MorphGender.Masculine && ((it.Gender != Pullenti.Morph.MorphGender.Undefined || it.Number == Pullenti.Morph.MorphNumber.Plural)) && wf != null) && wf.NormalFull != null)
                        {
                            normalFull = true;
                        }
                        else if (gender == Pullenti.Morph.MorphGender.Masculine && it.Class.IsPersonalPronoun)
                        {
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                if (!it.Case.IsUndefined)
                {
                    empty = false;
                }
                if (wf != null)
                {
                    string res;
                    if (num == Pullenti.Morph.MorphNumber.Singular && it.Number == Pullenti.Morph.MorphNumber.Plural && wf.NormalFull != null)
                    {
                        int le = wf.NormalCase.Length;
                        if ((le == (wf.NormalFull.Length + 2) && le > 4 && wf.NormalCase[le - 2] == 'С') && wf.NormalCase[le - 1] == 'Я')
                        {
                            res = wf.NormalCase;
                        }
                        else
                        {
                            res = (normalFull ? wf.NormalFull : wf.NormalFull);
                        }
                    }
                    else
                    {
                        res = (normalFull ? wf.NormalFull : (wf.NormalCase ?? Term));
                    }
                    if (num == Pullenti.Morph.MorphNumber.Singular && mc != null && mc == Pullenti.Morph.MorphClass.Noun)
                    {
                        if (res == "ДЕТИ")
                        {
                            res = "РЕБЕНОК";
                        }
                    }
                    if (keepChars)
                    {
                        if (Chars.IsAllLower)
                        {
                            res = res.ToLower();
                        }
                        else if (Chars.IsCapitalUpper)
                        {
                            res = Pullenti.Ner.Core.MiscHelper.ConvertFirstCharUpperAndOtherLower(res);
                        }
                    }
                    return(res);
                }
            }
            if (!empty)
            {
                return(null);
            }
            string te = null;

            if (num == Pullenti.Morph.MorphNumber.Singular && mc != null)
            {
                Pullenti.Morph.MorphBaseInfo bi = new Pullenti.Morph.MorphBaseInfo()
                {
                    Class = new Pullenti.Morph.MorphClass()
                    {
                        Value = mc.Value
                    }, Gender = gender, Number = Pullenti.Morph.MorphNumber.Singular, Language = Morph.Language
                };
                string vars = Pullenti.Morph.MorphologyService.GetWordform(Term, bi);
                if (vars != null)
                {
                    te = vars;
                }
            }
            if (te == null)
            {
                te = Term;
            }
            if (keepChars)
            {
                if (Chars.IsAllLower)
                {
                    return(te.ToLower());
                }
                else if (Chars.IsCapitalUpper)
                {
                    return(Pullenti.Ner.Core.MiscHelper.ConvertFirstCharUpperAndOtherLower(te));
                }
            }
            return(te);
        }
Esempio n. 22
0
        public static List <string> GetStdAdjFullStr(string v, Pullenti.Morph.MorphGender gen, Pullenti.Morph.MorphNumber num, bool strict)
        {
            List <string> res = new List <string>();

            if (v.StartsWith("Б"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("БОЛЬШИЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("БОЛЬШИЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("БОЛЬШАЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("БОЛЬШОЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("БОЛЬШОЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v.StartsWith("М"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("МАЛЫЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("МАЛЫЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("МАЛАЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("МАЛЫЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("МАЛОЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v.StartsWith("В"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("ВЕРХНИЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("ВЕРХНИЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("ВЕРХНЯЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("ВЕРХНИЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("ВЕРХНЕЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v == "Н")
            {
                List <string> r1 = GetStdAdjFullStr("НОВ", gen, num, strict);
                List <string> r2 = GetStdAdjFullStr("НИЖ", gen, num, strict);
                if (r1 == null && r2 == null)
                {
                    return(null);
                }
                if (r1 == null)
                {
                    return(r2);
                }
                if (r2 == null)
                {
                    return(r1);
                }
                r1.Insert(1, r2[0]);
                r2.RemoveAt(0);
                r1.AddRange(r2);
                return(r1);
            }
            if (v == "С" || v == "C")
            {
                List <string> r1 = GetStdAdjFullStr("СТ", gen, num, strict);
                List <string> r2 = GetStdAdjFullStr("СР", gen, num, strict);
                if (r1 == null && r2 == null)
                {
                    return(null);
                }
                if (r1 == null)
                {
                    return(r2);
                }
                if (r2 == null)
                {
                    return(r1);
                }
                r1.Insert(1, r2[0]);
                r2.RemoveAt(0);
                r1.AddRange(r2);
                return(r1);
            }
            if (v.StartsWith("НОВ"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("НОВЫЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("НОВЫЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("НОВАЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("НОВЫЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("НОВОЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v.StartsWith("НИЖ"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("НИЖНИЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("НИЖНИЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("НИЖНЯЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("НИЖНИЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("НИЖНЕЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v.StartsWith("СТ"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("СТАРЫЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("СТАРЫЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("СТАРАЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("СТАРЫЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("СТАРОЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            if (v.StartsWith("СР"))
            {
                if (num == Pullenti.Morph.MorphNumber.Plural)
                {
                    res.Add("СРЕДНИЕ");
                    return(res);
                }
                if (!strict && ((num & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined)
                {
                    res.Add("СРЕДНИЕ");
                }
                if (((gen & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Feminie)
                    {
                        res.Add("СРЕДНЯЯ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Masculine)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Masculine)
                    {
                        res.Add("СРЕДНИЙ");
                    }
                }
                if (((gen & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined)
                {
                    if (!strict || gen == Pullenti.Morph.MorphGender.Neuter)
                    {
                        res.Add("СРЕДНЕЕ");
                    }
                }
                if (res.Count > 0)
                {
                    return(res);
                }
                return(null);
            }
            return(null);
        }
Esempio n. 23
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            if (gender == Pullenti.Morph.MorphGender.Undefined)
            {
                gender = Source.Morph.Gender;
            }
            StringBuilder res = new StringBuilder();

            for (int k = AdjIndex1; k <= AdjIndex2; k++)
            {
                string adj = Source.Adjectives[k].GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective | Pullenti.Morph.MorphClass.Pronoun, num, gender, keepChars);
                if (adj == null || adj == "?")
                {
                    adj = MiscHelper.GetTextValueOfMetaToken(Source.Adjectives[k], (keepChars ? GetTextAttr.KeepRegister : GetTextAttr.No));
                }
                res.AppendFormat("{0} ", adj ?? "?");
            }
            string noun = null;

            if ((Source.Noun.BeginToken is Pullenti.Ner.ReferentToken) && Source.BeginToken == Source.Noun.EndToken)
            {
                noun = Source.Noun.BeginToken.GetNormalCaseText(null, num, gender, keepChars);
            }
            else
            {
                Pullenti.Morph.MorphClass cas = Pullenti.Morph.MorphClass.Noun | Pullenti.Morph.MorphClass.Pronoun;
                if (mc != null && !mc.IsUndefined)
                {
                    cas = mc;
                }
                noun = Source.Noun.GetNormalCaseText(cas, num, gender, keepChars);
            }
            if (noun == null || noun == "?")
            {
                noun = Source.Noun.GetNormalCaseText(null, num, Pullenti.Morph.MorphGender.Undefined, false);
            }
            res.Append(noun ?? "?");
            return(res.ToString());
        }
Esempio n. 24
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            GetTextAttr attr = GetTextAttr.No;

            if (num == Pullenti.Morph.MorphNumber.Singular)
            {
                attr |= GetTextAttr.FirstNounGroupToNominativeSingle;
            }
            else
            {
                attr |= GetTextAttr.FirstNounGroupToNominative;
            }
            if (keepChars)
            {
                attr |= GetTextAttr.KeepRegister;
            }
            return(MiscHelper.GetTextValue(BeginToken, EndToken, attr));
        }
Esempio n. 25
0
        public override string GetNormalCaseText(Pullenti.Morph.MorphClass mc = null, Pullenti.Morph.MorphNumber num = Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender gender = Pullenti.Morph.MorphGender.Undefined, bool keepChars = false)
        {
            if ((BeginToken is Pullenti.Ner.ReferentToken) && BeginToken == EndToken)
            {
                return(BeginToken.GetNormalCaseText(mc, num, gender, keepChars));
            }
            string res     = null;
            int    maxCoef = 0;
            int    defCoef = -1;

            foreach (Pullenti.Morph.MorphBaseInfo it in Morph.Items)
            {
                NounPhraseItemTextVar v = it as NounPhraseItemTextVar;
                if (v == null)
                {
                    continue;
                }
                if (v.UndefCoef > 0 && (((v.UndefCoef < maxCoef) || defCoef >= 0)))
                {
                    continue;
                }
                if (num == Pullenti.Morph.MorphNumber.Singular && v.SingleNumberValue != null)
                {
                    if (mc != null && ((gender == Pullenti.Morph.MorphGender.Neuter || gender == Pullenti.Morph.MorphGender.Feminie)) && mc.IsAdjective)
                    {
                        Pullenti.Morph.MorphBaseInfo bi = new Pullenti.Morph.MorphBaseInfo()
                        {
                            Class = new Pullenti.Morph.MorphClass()
                            {
                                Value = mc.Value
                            }, Gender = gender, Number = Pullenti.Morph.MorphNumber.Singular, Case = Pullenti.Morph.MorphCase.Nominative, Language = Morph.Language
                        };
                        string str = Pullenti.Morph.MorphologyService.GetWordform(v.SingleNumberValue, bi);
                        if (str != null)
                        {
                            res = str;
                        }
                    }
                    else
                    {
                        res = v.SingleNumberValue;
                    }
                    if (v.UndefCoef == 0)
                    {
                        break;
                    }
                    maxCoef = v.UndefCoef;
                    continue;
                }
                if (string.IsNullOrEmpty(v.NormalValue))
                {
                    continue;
                }
                if (char.IsDigit(v.NormalValue[0]) && mc != null && mc.IsAdjective)
                {
                    int val;
                    if (int.TryParse(v.NormalValue, out val))
                    {
                        string str = Pullenti.Ner.Core.NumberHelper.GetNumberAdjective(val, gender, (num == Pullenti.Morph.MorphNumber.Singular || val == 1 ? Pullenti.Morph.MorphNumber.Singular : Pullenti.Morph.MorphNumber.Plural));
                        if (str != null)
                        {
                            res = str;
                            if (v.UndefCoef == 0)
                            {
                                break;
                            }
                            maxCoef = v.UndefCoef;
                            continue;
                        }
                    }
                }
                string res1 = (it as NounPhraseItemTextVar).NormalValue;
                if (num == Pullenti.Morph.MorphNumber.Singular)
                {
                    if (res1 == "ДЕТИ")
                    {
                        res1 = "РЕБЕНОК";
                    }
                    else if (res1 == "ЛЮДИ")
                    {
                        res1 = "ЧЕЛОВЕК";
                    }
                }
                maxCoef = v.UndefCoef;
                if (v.UndefCoef > 0)
                {
                    res = res1;
                    continue;
                }
                int defCo = 0;
                if (mc != null && mc.IsAdjective && v.UndefCoef == 0)
                {
                }
                else if (((BeginToken is Pullenti.Ner.TextToken) && res1 == (BeginToken as Pullenti.Ner.TextToken).Term && it.Case.IsNominative) && it.Number == Pullenti.Morph.MorphNumber.Singular)
                {
                    defCo = 1;
                }
                if (num == Pullenti.Morph.MorphNumber.Plural && ((v.Number & Pullenti.Morph.MorphNumber.Plural)) == Pullenti.Morph.MorphNumber.Plural)
                {
                    defCo += 3;
                }
                if (res == null || defCo > defCoef)
                {
                    res     = res1;
                    defCoef = defCo;
                    if (defCo > 0)
                    {
                        break;
                    }
                }
            }
            if (res != null)
            {
                return(this._corrChars(res, keepChars));
            }
            if (res == null && BeginToken == EndToken)
            {
                res = BeginToken.GetNormalCaseText(mc, num, gender, keepChars);
            }
            else if (res == null)
            {
                res = BeginToken.GetNormalCaseText(mc, num, gender, keepChars);
                if (res == null)
                {
                    res = Pullenti.Ner.Core.MiscHelper.GetTextValueOfMetaToken(this, (keepChars ? Pullenti.Ner.Core.GetTextAttr.KeepRegister : Pullenti.Ner.Core.GetTextAttr.No));
                }
                else
                {
                    res = string.Format("{0} {1}", res, Pullenti.Ner.Core.MiscHelper.GetTextValue(BeginToken.Next, EndToken, (keepChars ? Pullenti.Ner.Core.GetTextAttr.KeepRegister : Pullenti.Ner.Core.GetTextAttr.No)));
                }
            }
            return(res ?? "?");
        }