Esempio n. 1
0
 void _calcList()
 {
     Pullenti.Morph.MorphCase cas0 = FromMorph.Case;
     if (To == null)
     {
         if (ToVerb == null)
         {
             return;
         }
         return;
     }
     if (From.Source.Typ != To.Source.Typ)
     {
         if (From.Source.Prep == To.Source.Prep && ((From.Source.Typ == SentItemType.Noun || From.Source.Typ == SentItemType.PartBefore || From.Source.Typ == SentItemType.PartAfter)) && ((To.Source.Typ == SentItemType.Noun || To.Source.Typ == SentItemType.PartBefore || To.Source.Typ == SentItemType.PartAfter)))
         {
         }
         else
         {
             return;
         }
     }
     Pullenti.Morph.MorphCase cas1 = ToMorph.Case;
     if (!((cas0 & cas1)).IsUndefined)
     {
         Coef = Pullenti.Semantic.SemanticService.Params.List;
         if (string.IsNullOrEmpty(FromPrep) && !string.IsNullOrEmpty(To.Source.Prep))
         {
             Coef /= 2;
         }
         else if (!string.IsNullOrEmpty(FromPrep) && string.IsNullOrEmpty(To.Source.Prep))
         {
             Coef /= 4;
         }
     }
     else
     {
         if (!cas0.IsUndefined && !cas1.IsUndefined)
         {
             return;
         }
         if (!string.IsNullOrEmpty(FromPrep) && string.IsNullOrEmpty(To.Source.Prep))
         {
             return;
         }
         Coef = Pullenti.Semantic.SemanticService.Params.List;
     }
     Pullenti.Ner.TextToken t1 = From.Source.EndToken as Pullenti.Ner.TextToken;
     Pullenti.Ner.TextToken t2 = To.Source.EndToken as Pullenti.Ner.TextToken;
     if (t1 != null && t2 != null)
     {
         if (t1.IsValue(t2.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false), null))
         {
             Coef *= 10;
         }
     }
     if (From.Source.Typ != To.Source.Typ)
     {
         Coef /= 2;
     }
 }
Esempio n. 2
0
        static bool _compareListItemTails(Pullenti.Ner.MetaToken mt1, Pullenti.Ner.MetaToken mt2)
        {
            Pullenti.Ner.TextToken t1 = mt1.EndToken as Pullenti.Ner.TextToken;
            Pullenti.Ner.TextToken t2 = mt2.EndToken as Pullenti.Ner.TextToken;
            if (t1 == null || t2 == null)
            {
                return(true);
            }
            int k  = 0;
            int i1 = t1.Term.Length - 1;
            int i2 = t2.Term.Length - 1;

            for (; i1 > 0 && i2 > 0; i1--, i2--, k++)
            {
                if (t1.Term[i1] != t2.Term[i2])
                {
                    break;
                }
            }
            if (k >= 2)
            {
                return(true);
            }
            string nn = t2.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false);

            if (t1.IsValue(nn, null))
            {
                return(true);
            }
            if (((t1.Morph.Number & t2.Morph.Number)) == Pullenti.Morph.MorphNumber.Undefined)
            {
                return(false);
            }
            if (((t1.Morph.Case & t2.Morph.Case)).IsUndefined)
            {
                return(false);
            }
            if (t1.Morph.Class.IsVerb != t2.Morph.Class.IsVerb && t1.Morph.Class.IsAdjective != t2.Morph.Class.IsAdjective)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        static VerbPhraseToken TryParseRu(Pullenti.Ner.Token t, bool canBePartition, bool canBeAdjPartition, bool forceParse)
        {
            VerbPhraseToken res = null;

            Pullenti.Ner.Token t0         = t;
            Pullenti.Ner.Token not        = null;
            bool             hasVerb      = false;
            bool             verbBeBefore = false;
            PrepositionToken prep         = null;

            for (; t != null; t = t.Next)
            {
                if (!(t is Pullenti.Ner.TextToken))
                {
                    break;
                }
                Pullenti.Ner.TextToken tt = t as Pullenti.Ner.TextToken;
                bool isParticiple         = false;
                if (tt.Term == "НЕ")
                {
                    not = t;
                    continue;
                }
                int    ty   = 0;
                string norm = null;
                Pullenti.Morph.MorphClass mc = tt.GetMorphClassInDictionary();
                if (tt.Term == "НЕТ")
                {
                    if (hasVerb)
                    {
                        break;
                    }
                    ty = 1;
                }
                else if (tt.Term == "ДОПУСТИМО")
                {
                    ty = 3;
                }
                else if (mc.IsAdverb && !mc.IsVerb)
                {
                    ty = 2;
                }
                else if (tt.IsPureVerb || tt.IsVerbBe)
                {
                    ty = 1;
                    if (hasVerb)
                    {
                        if (!tt.Morph.ContainsAttr("инф.", null))
                        {
                            if (verbBeBefore)
                            {
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else if (mc.IsVerb)
                {
                    if (mc.IsPreposition || mc.IsMisc || mc.IsPronoun)
                    {
                    }
                    else if (mc.IsNoun)
                    {
                        if (tt.Term == "СТАЛИ" || tt.Term == "СТЕКЛО" || tt.Term == "БЫЛИ")
                        {
                            ty = 1;
                        }
                        else if (!tt.Chars.IsAllLower && !MiscHelper.CanBeStartOfSentence(tt))
                        {
                            ty = 1;
                        }
                        else if (mc.IsAdjective && canBePartition)
                        {
                            ty = 1;
                        }
                        else if (forceParse)
                        {
                            ty = 1;
                        }
                    }
                    else if (mc.IsProper)
                    {
                        if (tt.Chars.IsAllLower)
                        {
                            ty = 1;
                        }
                    }
                    else
                    {
                        ty = 1;
                    }
                    if (mc.IsAdjective)
                    {
                        isParticiple = true;
                    }
                    if (!tt.Morph.Case.IsUndefined)
                    {
                        isParticiple = true;
                    }
                    if (!canBePartition && isParticiple)
                    {
                        break;
                    }
                    if (hasVerb)
                    {
                        if (tt.Morph.ContainsAttr("инф.", null))
                        {
                        }
                        else if (!isParticiple)
                        {
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if ((mc.IsAdjective && tt.Morph.ContainsAttr("к.ф.", null) && tt.Term.EndsWith("О")) && NounPhraseHelper.TryParse(tt, NounPhraseParseAttr.No, 0, null) == null)
                {
                    ty = 2;
                }
                else if (mc.IsAdjective && ((canBePartition || canBeAdjPartition)))
                {
                    if (tt.Morph.ContainsAttr("к.ф.", null) && !canBeAdjPartition)
                    {
                        break;
                    }
                    norm = tt.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Masculine, false);
                    if (norm.EndsWith("ЙШИЙ"))
                    {
                    }
                    else
                    {
                        List <Pullenti.Semantic.Utils.DerivateGroup> grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(norm, true, null);
                        if (grs != null && grs.Count > 0)
                        {
                            bool hVerb = false;
                            bool hPart = false;
                            foreach (Pullenti.Semantic.Utils.DerivateGroup gr in grs)
                            {
                                foreach (Pullenti.Semantic.Utils.DerivateWord w in gr.Words)
                                {
                                    if (w.Class.IsAdjective && w.Class.IsVerb)
                                    {
                                        if (w.Spelling == norm)
                                        {
                                            hPart = true;
                                        }
                                    }
                                    else if (w.Class.IsVerb)
                                    {
                                        hVerb = true;
                                    }
                                }
                            }
                            if (hPart && hVerb)
                            {
                                ty = 3;
                            }
                            else if (canBeAdjPartition)
                            {
                                ty = 3;
                            }
                            if (ty != 3 && !string.IsNullOrEmpty(grs[0].Prefix) && norm.StartsWith(grs[0].Prefix))
                            {
                                hVerb = false;
                                hPart = false;
                                string norm1 = norm.Substring(grs[0].Prefix.Length);
                                grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(norm1, true, null);
                                if (grs != null && grs.Count > 0)
                                {
                                    foreach (Pullenti.Semantic.Utils.DerivateGroup gr in grs)
                                    {
                                        foreach (Pullenti.Semantic.Utils.DerivateWord w in gr.Words)
                                        {
                                            if (w.Class.IsAdjective && w.Class.IsVerb)
                                            {
                                                if (w.Spelling == norm1)
                                                {
                                                    hPart = true;
                                                }
                                            }
                                            else if (w.Class.IsVerb)
                                            {
                                                hVerb = true;
                                            }
                                        }
                                    }
                                }
                                if (hPart && hVerb)
                                {
                                    ty = 3;
                                }
                            }
                        }
                    }
                }
                if (ty == 0 && t == t0 && canBePartition)
                {
                    prep = PrepositionHelper.TryParse(t);
                    if (prep != null)
                    {
                        t = prep.EndToken;
                        continue;
                    }
                }
                if (ty == 0)
                {
                    break;
                }
                if (res == null)
                {
                    res = new VerbPhraseToken(t0, t);
                }
                res.EndToken = t;
                VerbPhraseItemToken it = new VerbPhraseItemToken(t, t)
                {
                    Morph = new Pullenti.Ner.MorphCollection(t.Morph)
                };
                if (not != null)
                {
                    it.BeginToken = not;
                    it.Not        = true;
                    not           = null;
                }
                it.IsAdverb = ty == 2;
                if (prep != null && !t.Morph.Case.IsUndefined && res.Items.Count == 0)
                {
                    if (((prep.NextCase & t.Morph.Case)).IsUndefined)
                    {
                        return(null);
                    }
                    it.Morph.RemoveItems(prep.NextCase);
                    res.Preposition = prep;
                }
                if (norm == null)
                {
                    norm = t.GetNormalCaseText((ty == 3 ? Pullenti.Morph.MorphClass.Adjective : (ty == 2 ? Pullenti.Morph.MorphClass.Adverb : Pullenti.Morph.MorphClass.Verb)), Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Masculine, false);
                    if (ty == 1 && !tt.Morph.Case.IsUndefined)
                    {
                        Pullenti.Morph.MorphWordForm mi = new Pullenti.Morph.MorphWordForm()
                        {
                            Case = Pullenti.Morph.MorphCase.Nominative, Number = Pullenti.Morph.MorphNumber.Singular, Gender = Pullenti.Morph.MorphGender.Masculine
                        };
                        foreach (Pullenti.Morph.MorphBaseInfo mit in tt.Morph.Items)
                        {
                            if (mit is Pullenti.Morph.MorphWordForm)
                            {
                                mi.Misc = (mit as Pullenti.Morph.MorphWordForm).Misc;
                                break;
                            }
                        }
                        string nnn = Pullenti.Morph.MorphologyService.GetWordform("КК" + (t as Pullenti.Ner.TextToken).Term, mi);
                        if (nnn != null)
                        {
                            norm = nnn.Substring(2);
                        }
                    }
                }
                it.Normal = norm;
                res.Items.Add(it);
                if (!hasVerb && ((ty == 1 || ty == 3)))
                {
                    res.Morph = it.Morph;
                    hasVerb   = true;
                }
                if (ty == 1 || ty == 3)
                {
                    if (ty == 1 && tt.IsVerbBe)
                    {
                        verbBeBefore = true;
                    }
                    else
                    {
                        verbBeBefore = false;
                    }
                }
            }
            if (!hasVerb)
            {
                return(null);
            }
            for (int i = res.Items.Count - 1; i > 0; i--)
            {
                if (res.Items[i].IsAdverb)
                {
                    res.Items.RemoveAt(i);
                    res.EndToken = res.Items[i - 1].EndToken;
                }
                else
                {
                    break;
                }
            }
            return(res);
        }
Esempio n. 4
0
        internal static NumbersWithUnitToken _tryParse(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool second, bool canOmitNumber, bool canBeNan)
        {
            if (t == null)
            {
                return(null);
            }
            while (t != null)
            {
                if (t.IsCommaAnd || t.IsValue("НО", null))
                {
                    t = t.Next;
                }
                else
                {
                    break;
                }
            }
            Pullenti.Ner.Token t0 = t;
            bool about            = false;
            bool hasKeyw          = false;
            bool isDiapKeyw       = false;
            int  minMax           = 0;

            Pullenti.Ner.Token ttt = _isMinOrMax(t, ref minMax);
            if (ttt != null)
            {
                t = ttt.Next;
                if (t == null)
                {
                    return(null);
                }
            }
            if (t == null)
            {
                return(null);
            }
            if (t.IsChar('~') || t.IsValue("ОКОЛО", null) || t.IsValue("ПРИМЕРНО", null))
            {
                t       = t.Next;
                about   = true;
                hasKeyw = true;
                if (t == null)
                {
                    return(null);
                }
            }
            if (t.IsValue("В", null) && t.Next != null)
            {
                if (t.Next.IsValue("ПРЕДЕЛ", null) || t.IsValue("ДИАПАЗОН", null))
                {
                    t = t.Next.Next;
                    if (t == null)
                    {
                        return(null);
                    }
                    isDiapKeyw = true;
                }
            }
            if (t0.IsChar('('))
            {
                NumbersWithUnitToken mt0 = _tryParse(t.Next, addUnits, false, false, false);
                if (mt0 != null && mt0.EndToken.Next != null && mt0.EndToken.Next.IsChar(')'))
                {
                    if (second)
                    {
                        if (mt0.FromVal != null && mt0.ToVal != null && mt0.FromVal.Value == (-mt0.ToVal.Value))
                        {
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    mt0.BeginToken = t0;
                    mt0.EndToken   = mt0.EndToken.Next;
                    List <UnitToken> uu = UnitToken.TryParseList(mt0.EndToken.Next, addUnits, false);
                    if (uu != null && mt0.Units.Count == 0)
                    {
                        mt0.Units    = uu;
                        mt0.EndToken = uu[uu.Count - 1].EndToken;
                    }
                    return(mt0);
                }
            }
            bool    plusminus  = false;
            bool    unitBefore = false;
            bool    isAge      = false;
            DiapTyp dty        = DiapTyp.Undefined;

            Pullenti.Ner.MetaToken whd = null;
            List <UnitToken>       uni = null;

            Pullenti.Ner.Core.TerminToken tok = (m_Termins == null ? null : m_Termins.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No));
            if (tok != null)
            {
                if (tok.EndToken.IsValue("СТАРШЕ", null) || tok.EndToken.IsValue("МЛАДШЕ", null))
                {
                    isAge = true;
                }
                t       = tok.EndToken.Next;
                dty     = (DiapTyp)tok.Termin.Tag;
                hasKeyw = true;
                if (!tok.IsWhitespaceAfter)
                {
                    if (t == null)
                    {
                        return(null);
                    }
                    if (t is Pullenti.Ner.NumberToken)
                    {
                        if (tok.BeginToken == tok.EndToken && !tok.Chars.IsAllLower)
                        {
                            return(null);
                        }
                    }
                    else if (t.IsComma && t.Next != null && t.Next.IsValue("ЧЕМ", null))
                    {
                        t = t.Next.Next;
                        if (t != null && t.Morph.Class.IsPreposition)
                        {
                            t = t.Next;
                        }
                    }
                    else if (t.IsCharOf(":,(") || t.IsTableControlChar)
                    {
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (t != null && t.IsChar('('))
                {
                    uni = UnitToken.TryParseList(t.Next, addUnits, false);
                    if (uni != null)
                    {
                        t = uni[uni.Count - 1].EndToken.Next;
                        while (t != null)
                        {
                            if (t.IsCharOf("):"))
                            {
                                t = t.Next;
                            }
                            else
                            {
                                break;
                            }
                        }
                        NumbersWithUnitToken mt0 = _tryParse(t, addUnits, false, canOmitNumber, false);
                        if (mt0 != null && mt0.Units.Count == 0)
                        {
                            mt0.BeginToken = t0;
                            mt0.Units      = uni;
                            return(mt0);
                        }
                    }
                    whd = _tryParseWHL(t);
                    if (whd != null)
                    {
                        t = whd.EndToken.Next;
                    }
                }
                else if (t != null && t.IsValue("IP", null))
                {
                    uni = UnitToken.TryParseList(t, addUnits, false);
                    if (uni != null)
                    {
                        t = uni[uni.Count - 1].EndToken.Next;
                    }
                }
                if ((t != null && t.IsHiphen && t.IsWhitespaceBefore) && t.IsWhitespaceAfter)
                {
                    t = t.Next;
                }
            }
            else if (t.IsChar('<'))
            {
                dty     = DiapTyp.Ls;
                t       = t.Next;
                hasKeyw = true;
                if (t != null && t.IsChar('='))
                {
                    t   = t.Next;
                    dty = DiapTyp.Le;
                }
            }
            else if (t.IsChar('>'))
            {
                dty     = DiapTyp.Gt;
                t       = t.Next;
                hasKeyw = true;
                if (t != null && t.IsChar('='))
                {
                    t   = t.Next;
                    dty = DiapTyp.Ge;
                }
            }
            else if (t.IsChar('≤'))
            {
                dty     = DiapTyp.Le;
                hasKeyw = true;
                t       = t.Next;
            }
            else if (t.IsChar('≥'))
            {
                dty     = DiapTyp.Ge;
                hasKeyw = true;
                t       = t.Next;
            }
            else if (t.IsValue("IP", null))
            {
                uni = UnitToken.TryParseList(t, addUnits, false);
                if (uni != null)
                {
                    t = uni[uni.Count - 1].EndToken.Next;
                }
            }
            else if (t.IsValue("ЗА", null) && (t.Next is Pullenti.Ner.NumberToken))
            {
                dty = DiapTyp.Ge;
                t   = t.Next;
            }
            while (t != null && ((t.IsCharOf(":,") || t.IsValue("ЧЕМ", null) || t.IsTableControlChar)))
            {
                t = t.Next;
            }
            if (t != null)
            {
                if (t.IsChar('+') || t.IsValue("ПЛЮС", null))
                {
                    t = t.Next;
                    if (t != null && !t.IsWhitespaceBefore)
                    {
                        if (t.IsHiphen)
                        {
                            t         = t.Next;
                            plusminus = true;
                        }
                        else if ((t.IsCharOf("\\/") && t.Next != null && !t.IsNewlineAfter) && t.Next.IsHiphen)
                        {
                            t         = t.Next.Next;
                            plusminus = true;
                        }
                    }
                }
                else if (second && (t.IsCharOf("\\/÷…~")))
                {
                    t = t.Next;
                }
                else if ((t.IsHiphen && t == t0 && !second) && m_Termins.TryParse(t.Next, Pullenti.Ner.Core.TerminParseAttr.No) != null)
                {
                    tok = m_Termins.TryParse(t.Next, Pullenti.Ner.Core.TerminParseAttr.No);
                    t   = tok.EndToken.Next;
                    dty = (DiapTyp)tok.Termin.Tag;
                }
                else if (t.IsHiphen && t == t0 && ((t.IsWhitespaceAfter || second)))
                {
                    t = t.Next;
                }
                else if (t.IsChar('±'))
                {
                    t         = t.Next;
                    plusminus = true;
                    hasKeyw   = true;
                }
                else if ((second && t.IsChar('.') && t.Next != null) && t.Next.IsChar('.'))
                {
                    t = t.Next.Next;
                    if (t != null && t.IsChar('.'))
                    {
                        t = t.Next;
                    }
                }
            }
            Pullenti.Ner.NumberToken num = Pullenti.Ner.Core.NumberHelper.TryParseRealNumber(t, true, false);
            if (num == null)
            {
                uni = UnitToken.TryParseList(t, addUnits, false);
                if (uni != null)
                {
                    unitBefore = true;
                    t          = uni[uni.Count - 1].EndToken.Next;
                    bool delim = false;
                    while (t != null)
                    {
                        if (t.IsCharOf(":,"))
                        {
                            delim = true;
                            t     = t.Next;
                        }
                        else if (t.IsHiphen && t.IsWhitespaceAfter)
                        {
                            delim = true;
                            t     = t.Next;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (!delim)
                    {
                        if (t == null)
                        {
                            if (hasKeyw && canBeNan)
                            {
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else if (!t.IsWhitespaceBefore)
                        {
                            return(null);
                        }
                        if (t.Next != null && t.IsHiphen && t.IsWhitespaceAfter)
                        {
                            delim = true;
                            t     = t.Next;
                        }
                    }
                    num = Pullenti.Ner.Core.NumberHelper.TryParseRealNumber(t, true, false);
                }
            }
            NumbersWithUnitToken res = null;
            double rval = (double)0;

            if (num == null)
            {
                Pullenti.Ner.Core.TerminToken tt = m_Spec.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No);
                if (tt != null)
                {
                    rval = (double)tt.Termin.Tag;
                    string unam = (string)tt.Termin.Tag2;
                    foreach (Unit u in UnitsHelper.Units)
                    {
                        if (u.FullnameCyr == unam)
                        {
                            uni = new List <UnitToken>();
                            uni.Add(new UnitToken(t, t)
                            {
                                Unit = u
                            });
                            break;
                        }
                    }
                    if (uni == null)
                    {
                        return(null);
                    }
                    res = new NumbersWithUnitToken(t0, tt.EndToken)
                    {
                        About = about
                    };
                    t = tt.EndToken.Next;
                }
                else
                {
                    if (!canOmitNumber && !hasKeyw && !canBeNan)
                    {
                        return(null);
                    }
                    if ((uni != null && uni.Count == 1 && uni[0].BeginToken == uni[0].EndToken) && uni[0].LengthChar > 3)
                    {
                        rval = 1;
                        res  = new NumbersWithUnitToken(t0, uni[uni.Count - 1].EndToken)
                        {
                            About = about
                        };
                        t = res.EndToken.Next;
                    }
                    else if (hasKeyw && canBeNan)
                    {
                        rval = double.NaN;
                        res  = new NumbersWithUnitToken(t0, t0)
                        {
                            About = about
                        };
                        if (t != null)
                        {
                            res.EndToken = t.Previous;
                        }
                        else
                        {
                            for (t = t0; t != null; t = t.Next)
                            {
                                res.EndToken = t;
                            }
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                if ((t == t0 && t0.IsHiphen && !t.IsWhitespaceBefore) && !t.IsWhitespaceAfter && (num.RealValue < 0))
                {
                    num = Pullenti.Ner.Core.NumberHelper.TryParseRealNumber(t.Next, true, false);
                    if (num == null)
                    {
                        return(null);
                    }
                }
                if (t == t0 && (t is Pullenti.Ner.NumberToken) && t.Morph.Class.IsAdjective)
                {
                    Pullenti.Ner.TextToken nn = (t as Pullenti.Ner.NumberToken).EndToken as Pullenti.Ner.TextToken;
                    if (nn == null)
                    {
                        return(null);
                    }
                    string norm = nn.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false);
                    if ((norm.EndsWith("Ь") || norm == "ЧЕТЫРЕ" || norm == "ТРИ") || norm == "ДВА")
                    {
                    }
                    else
                    {
                        Pullenti.Morph.MorphWordForm mi = Pullenti.Morph.MorphologyService.GetWordBaseInfo("КОКО" + nn.Term, null, false, false);
                        if (mi.Class.IsAdjective)
                        {
                            return(null);
                        }
                    }
                }
                t   = num.EndToken.Next;
                res = new NumbersWithUnitToken(t0, num.EndToken)
                {
                    About = about
                };
                rval = num.RealValue;
            }
            if (uni == null)
            {
                uni = UnitToken.TryParseList(t, addUnits, false);
                if (uni != null)
                {
                    if ((plusminus && second && uni.Count >= 1) && uni[0].Unit == UnitsHelper.uPercent)
                    {
                        res.EndToken         = uni[0].EndToken;
                        res.PlusMinusPercent = true;
                        Pullenti.Ner.Token tt1 = uni[0].EndToken.Next;
                        uni = UnitToken.TryParseList(tt1, addUnits, false);
                        if (uni != null)
                        {
                            res.Units    = uni;
                            res.EndToken = uni[uni.Count - 1].EndToken;
                        }
                    }
                    else
                    {
                        res.Units    = uni;
                        res.EndToken = uni[uni.Count - 1].EndToken;
                    }
                    t = res.EndToken.Next;
                }
            }
            else
            {
                res.Units = uni;
                if (uni.Count > 1)
                {
                    List <UnitToken> uni1 = UnitToken.TryParseList(t, addUnits, false);
                    if (((uni1 != null && uni1[0].Unit == uni[0].Unit && (uni1.Count < uni.Count)) && uni[uni1.Count].Pow == -1 && uni1[uni1.Count - 1].EndToken.Next != null) && uni1[uni1.Count - 1].EndToken.Next.IsCharOf("/\\"))
                    {
                        NumbersWithUnitToken num2 = _tryParse(uni1[uni1.Count - 1].EndToken.Next.Next, addUnits, false, false, false);
                        if (num2 != null && num2.Units != null && num2.Units[0].Unit == uni[uni1.Count].Unit)
                        {
                            res.Units    = uni1;
                            res.DivNum   = num2;
                            res.EndToken = num2.EndToken;
                        }
                    }
                }
            }
            res.WHL = whd;
            if (dty != DiapTyp.Undefined)
            {
                if (dty == DiapTyp.Ge || dty == DiapTyp.From)
                {
                    res.FromInclude = true;
                    res.FromVal     = rval;
                }
                else if (dty == DiapTyp.Gt)
                {
                    res.FromInclude = false;
                    res.FromVal     = rval;
                }
                else if (dty == DiapTyp.Le || dty == DiapTyp.To)
                {
                    res.ToInclude = true;
                    res.ToVal     = rval;
                }
                else if (dty == DiapTyp.Ls)
                {
                    res.ToInclude = false;
                    res.ToVal     = rval;
                }
            }
            bool isSecondMax = false;

            if (!second)
            {
                int iii = 0;
                ttt = _isMinOrMax(t, ref iii);
                if (ttt != null && iii > 0)
                {
                    isSecondMax = true;
                    t           = ttt.Next;
                }
            }
            NumbersWithUnitToken next = (second || plusminus || ((t != null && ((t.IsTableControlChar || t.IsNewlineBefore)))) ? null : _tryParse(t, addUnits, true, false, canBeNan));

            if (next != null && (t.Previous is Pullenti.Ner.NumberToken))
            {
                if (MeasureHelper.IsMultChar((t.Previous as Pullenti.Ner.NumberToken).EndToken))
                {
                    next = null;
                }
            }
            if (next != null && ((next.ToVal != null || next.SingleVal != null)) && next.FromVal == null)
            {
                if ((((next.BeginToken.IsChar('+') && next.SingleVal != null && !double.IsNaN(next.SingleVal.Value)) && next.EndToken.Next != null && next.EndToken.Next.IsCharOf("\\/")) && next.EndToken.Next.Next != null && next.EndToken.Next.Next.IsHiphen) && !hasKeyw && !double.IsNaN(rval))
                {
                    NumbersWithUnitToken next2 = _tryParse(next.EndToken.Next.Next.Next, addUnits, true, false, false);
                    if (next2 != null && next2.SingleVal != null && !double.IsNaN(next2.SingleVal.Value))
                    {
                        res.FromVal     = rval - next2.SingleVal.Value;
                        res.FromInclude = true;
                        res.ToVal       = rval + next.SingleVal.Value;
                        res.ToInclude   = true;
                        if (next2.Units != null && res.Units.Count == 0)
                        {
                            res.Units = next2.Units;
                        }
                        res.EndToken = next2.EndToken;
                        return(res);
                    }
                }
                if (next.Units.Count > 0)
                {
                    if (res.Units.Count == 0)
                    {
                        res.Units = next.Units;
                    }
                    else if (!UnitToken.CanBeEquals(res.Units, next.Units))
                    {
                        next = null;
                    }
                }
                else if (res.Units.Count > 0 && !unitBefore && !next.PlusMinusPercent)
                {
                    next = null;
                }
                if (next != null)
                {
                    res.EndToken = next.EndToken;
                }
                if (next != null && next.ToVal != null)
                {
                    res.ToVal     = next.ToVal;
                    res.ToInclude = next.ToInclude;
                }
                else if (next != null && next.SingleVal != null)
                {
                    if (next.BeginToken.IsCharOf("/\\"))
                    {
                        res.DivNum    = next;
                        res.SingleVal = rval;
                        return(res);
                    }
                    else if (next.PlusMinusPercent)
                    {
                        res.SingleVal        = rval;
                        res.PlusMinus        = next.SingleVal;
                        res.PlusMinusPercent = true;
                        res.ToInclude        = true;
                    }
                    else
                    {
                        res.ToVal     = next.SingleVal;
                        res.ToInclude = true;
                    }
                }
                if (next != null)
                {
                    if (res.FromVal == null)
                    {
                        res.FromVal     = rval;
                        res.FromInclude = true;
                    }
                    return(res);
                }
            }
            else if ((next != null && next.FromVal != null && next.ToVal != null) && next.ToVal.Value == (-next.FromVal.Value))
            {
                if (next.Units.Count == 1 && next.Units[0].Unit == UnitsHelper.uPercent && res.Units.Count > 0)
                {
                    res.SingleVal        = rval;
                    res.PlusMinus        = next.ToVal.Value;
                    res.PlusMinusPercent = true;
                    res.EndToken         = next.EndToken;
                    return(res);
                }
                if (next.Units.Count == 0)
                {
                    res.SingleVal = rval;
                    res.PlusMinus = next.ToVal.Value;
                    res.EndToken  = next.EndToken;
                    return(res);
                }
                res.FromVal     = next.FromVal + rval;
                res.FromInclude = true;
                res.ToVal       = next.ToVal + rval;
                res.ToInclude   = true;
                res.EndToken    = next.EndToken;
                if (next.Units.Count > 0)
                {
                    res.Units = next.Units;
                }
                return(res);
            }
            if (dty == DiapTyp.Undefined)
            {
                if (plusminus && ((!res.PlusMinusPercent || !second)))
                {
                    res.FromInclude = true;
                    res.FromVal     = -rval;
                    res.ToInclude   = true;
                    res.ToVal       = rval;
                }
                else
                {
                    res.SingleVal        = rval;
                    res.PlusMinusPercent = plusminus;
                }
            }
            if (isAge)
            {
                res.IsAge = true;
            }
            return(res);
        }