Beispiel #1
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)
 {
     Pullenti.Ner.Core.GetTextAttr attr = Pullenti.Ner.Core.GetTextAttr.No;
     if (num == Pullenti.Morph.MorphNumber.Singular)
     {
         attr |= Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominativeSingle;
     }
     else
     {
         attr |= Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominative;
     }
     if (keepChars)
     {
         attr |= Pullenti.Ner.Core.GetTextAttr.KeepRegister;
     }
     if (BeginToken == EndToken)
     {
         return(BeginToken.GetNormalCaseText(mc, num, gender, keepChars));
     }
     else
     {
         return(Pullenti.Ner.Core.MiscHelper.GetTextValue(BeginToken, EndToken, attr));
     }
 }
Beispiel #2
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 ?? "?");
        }