Пример #1
0
        public static NumbersWithUnitToken TryParse(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool canOmitNumber = false, bool not = false, bool canBeNan = false, bool isResctriction = false)
        {
            if (t == null)
            {
                return(null);
            }
            NumbersWithUnitToken res = _tryParse(t, addUnits, isResctriction, canOmitNumber, canBeNan);

            if (res != null)
            {
                res.Not = not;
            }
            return(res);
        }
Пример #2
0
        public static MeasureToken TryParseMinimal(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool canOmitNumber = false)
        {
            if (t == null || (t is Pullenti.Ner.ReferentToken))
            {
                return(null);
            }
            List <NumbersWithUnitToken> mt = NumbersWithUnitToken.TryParseMulti(t, addUnits, canOmitNumber, false, false, false);

            if (mt == null)
            {
                return(null);
            }
            if (mt[0].Units.Count == 0)
            {
                return(null);
            }
            if ((mt.Count == 1 && mt[0].Units.Count == 1 && mt[0].Units[0].IsDoubt) && !mt[0].IsNewlineBefore)
            {
                return(null);
            }
            MeasureToken res;

            if (mt.Count == 1)
            {
                res = new MeasureToken(mt[0].BeginToken, mt[mt.Count - 1].EndToken)
                {
                    Nums = mt[0]
                };
                res._parseInternals(addUnits);
                return(res);
            }
            res = new MeasureToken(mt[0].BeginToken, mt[mt.Count - 1].EndToken);
            foreach (NumbersWithUnitToken m in mt)
            {
                res.Internals.Add(new MeasureToken(m.BeginToken, m.EndToken)
                {
                    Nums = m
                });
            }
            return(res);
        }
Пример #3
0
 void _parseInternals(Pullenti.Ner.Core.TerminCollection addUnits)
 {
     if (EndToken.Next != null && ((EndToken.Next.IsCharOf("\\/") || EndToken.Next.IsValue("ПРИ", null))))
     {
         MeasureToken mt1 = TryParse(EndToken.Next.Next, addUnits, true, false, false, false);
         if (mt1 != null)
         {
             Internals.Add(mt1);
             EndToken = mt1.EndToken;
         }
         else
         {
             NumbersWithUnitToken mt = NumbersWithUnitToken.TryParse(EndToken.Next.Next, addUnits, false, false, false, false);
             if (mt != null && mt.Units.Count > 0 && !UnitToken.CanBeEquals(Nums.Units, mt.Units))
             {
                 Internals.Add(new MeasureToken(mt.BeginToken, mt.EndToken)
                 {
                     Nums = mt
                 });
                 EndToken = mt.EndToken;
             }
         }
     }
 }
Пример #4
0
        public static MeasureToken TryParse(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool canBeSet = true, bool canUnitsAbsent = false, bool isResctriction = false, bool isSubval = false)
        {
            if (!(t is Pullenti.Ner.TextToken))
            {
                return(null);
            }
            if (t.IsTableControlChar)
            {
                return(null);
            }
            Pullenti.Ner.Token     t0  = t;
            Pullenti.Ner.MetaToken whd = null;
            int minmax = 0;

            Pullenti.Ner.Token tt = NumbersWithUnitToken._isMinOrMax(t0, ref minmax);
            if (tt != null)
            {
                t = tt.Next;
            }
            Pullenti.Ner.Core.NounPhraseToken npt = Pullenti.Ner.Core.NounPhraseHelper.TryParse(t, Pullenti.Ner.Core.NounPhraseParseAttr.ParsePreposition | Pullenti.Ner.Core.NounPhraseParseAttr.IgnoreBrackets, 0, null);
            if (npt == null)
            {
                whd = NumbersWithUnitToken._tryParseWHL(t);
                if (whd != null)
                {
                    npt = new Pullenti.Ner.Core.NounPhraseToken(t0, whd.EndToken);
                }
                else if (t0.IsValue("КПД", null))
                {
                    npt = new Pullenti.Ner.Core.NounPhraseToken(t0, t0);
                }
                else if ((t0 is Pullenti.Ner.TextToken) && t0.LengthChar > 3 && t0.GetMorphClassInDictionary().IsUndefined)
                {
                    npt = new Pullenti.Ner.Core.NounPhraseToken(t0, t0);
                }
                else if (t0.IsValue("T", null) && t0.Chars.IsAllLower)
                {
                    npt = new Pullenti.Ner.Core.NounPhraseToken(t0, t0);
                    t   = t0;
                    if (t.Next != null && t.Next.IsChar('='))
                    {
                        npt.EndToken = t.Next;
                    }
                }
                else if ((t0 is Pullenti.Ner.TextToken) && t0.Chars.IsLetter && isSubval)
                {
                    if (NumbersWithUnitToken.TryParse(t, addUnits, false, false, false, false) != null)
                    {
                        return(null);
                    }
                    npt = new Pullenti.Ner.Core.NounPhraseToken(t0, t0);
                    for (t = t0.Next; t != null; t = t.Next)
                    {
                        if (t.WhitespacesBeforeCount > 2)
                        {
                            break;
                        }
                        else if (!(t is Pullenti.Ner.TextToken))
                        {
                            break;
                        }
                        else if (!t.Chars.IsLetter)
                        {
                            Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(t, Pullenti.Ner.Core.BracketParseAttr.No, 100);
                            if (br != null)
                            {
                                npt.EndToken = (t = br.EndToken);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (NumbersWithUnitToken.TryParse(t, addUnits, false, false, false, false) != null)
                        {
                            break;
                        }
                        else
                        {
                            npt.EndToken = t;
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (Pullenti.Ner.Core.NumberHelper.TryParseRealNumber(t, true, false) != null)
            {
                return(null);
            }
            else
            {
                Pullenti.Ner.Date.Internal.DateItemToken dtok = Pullenti.Ner.Date.Internal.DateItemToken.TryAttach(t, null, false);
                if (dtok != null)
                {
                    return(null);
                }
            }
            Pullenti.Ner.Token t1 = npt.EndToken;
            t = npt.EndToken;
            Pullenti.Ner.MetaToken name = new Pullenti.Ner.MetaToken(npt.BeginToken, npt.EndToken)
            {
                Morph = npt.Morph
            };
            List <UnitToken>    units     = null;
            List <UnitToken>    units2    = null;
            List <MeasureToken> internals = new List <MeasureToken>();
            bool not = false;

            for (tt = t1.Next; tt != null; tt = tt.Next)
            {
                if (tt.IsNewlineBefore)
                {
                    break;
                }
                if (tt.IsTableControlChar)
                {
                    break;
                }
                Pullenti.Ner.Token tt2 = NumbersWithUnitToken._isMinOrMax(tt, ref minmax);
                if (tt2 != null)
                {
                    t1 = (t = (tt = tt2));
                    continue;
                }
                if ((tt.IsValue("БЫТЬ", null) || tt.IsValue("ДОЛЖЕН", null) || tt.IsValue("ДОЛЖНЫЙ", null)) || tt.IsValue("МОЖЕТ", null) || ((tt.IsValue("СОСТАВЛЯТЬ", null) && !tt.GetMorphClassInDictionary().IsAdjective)))
                {
                    t1 = (t = tt);
                    if (tt.Previous.IsValue("НЕ", null))
                    {
                        not = true;
                    }
                    continue;
                }
                Pullenti.Ner.MetaToken www = NumbersWithUnitToken._tryParseWHL(tt);
                if (www != null)
                {
                    whd = www;
                    t1  = (t = (tt = www.EndToken));
                    continue;
                }
                if (tt.IsValue("ПРИ", null))
                {
                    MeasureToken mt1 = TryParse(tt.Next, addUnits, false, false, true, false);
                    if (mt1 != null)
                    {
                        internals.Add(mt1);
                        t1 = (t = (tt = mt1.EndToken));
                        continue;
                    }
                    NumbersWithUnitToken n1 = NumbersWithUnitToken.TryParse(tt.Next, addUnits, false, false, false, false);
                    if (n1 != null && n1.Units.Count > 0)
                    {
                        mt1 = new MeasureToken(n1.BeginToken, n1.EndToken)
                        {
                            Nums = n1
                        };
                        internals.Add(mt1);
                        t1 = (t = (tt = mt1.EndToken));
                        continue;
                    }
                }
                if (tt.IsValue("ПО", null) && tt.Next != null && tt.Next.IsValue("U", null))
                {
                    t1 = (t = (tt = tt.Next));
                    continue;
                }
                if (internals.Count > 0)
                {
                    if (tt.IsChar(':'))
                    {
                        break;
                    }
                    MeasureToken mt1 = TryParse(tt.Next, addUnits, false, false, true, false);
                    if (mt1 != null && mt1.Reliable)
                    {
                        internals.Add(mt1);
                        t1 = (t = (tt = mt1.EndToken));
                        continue;
                    }
                }
                if ((tt is Pullenti.Ner.NumberToken) && (tt as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Words)
                {
                    Pullenti.Ner.Core.NounPhraseToken npt3 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.ParseNumericAsAdjective, 0, null);
                    if (npt3 != null)
                    {
                        t1 = (tt = npt3.EndToken);
                        if (internals.Count == 0)
                        {
                            name.EndToken = t1;
                        }
                        continue;
                    }
                }
                if (((tt.IsHiphen && !tt.IsWhitespaceBefore && !tt.IsWhitespaceAfter) && (tt.Next is Pullenti.Ner.NumberToken) && (tt.Previous is Pullenti.Ner.TextToken)) && tt.Previous.Chars.IsAllUpper)
                {
                    t1 = (tt = (t = tt.Next));
                    if (internals.Count == 0)
                    {
                        name.EndToken = t1;
                    }
                    continue;
                }
                if (((tt is Pullenti.Ner.NumberToken) && !tt.IsWhitespaceBefore && (tt.Previous is Pullenti.Ner.TextToken)) && tt.Previous.Chars.IsAllUpper)
                {
                    t1 = (t = tt);
                    if (internals.Count == 0)
                    {
                        name.EndToken = t1;
                    }
                    continue;
                }
                if ((((tt is Pullenti.Ner.NumberToken) && !tt.IsWhitespaceAfter && tt.Next.IsHiphen) && !tt.Next.IsWhitespaceAfter && (tt.Next.Next is Pullenti.Ner.TextToken)) && tt.Next.Next.LengthChar > 2)
                {
                    t1 = (t = (tt = tt.Next.Next));
                    Pullenti.Ner.Core.NounPhraseToken npt1 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.No, 0, null);
                    if (npt1 != null && npt1.EndChar > tt.EndChar)
                    {
                        t1 = (t = (tt = npt1.EndToken));
                    }
                    if (internals.Count == 0)
                    {
                        name.EndToken = t1;
                    }
                    continue;
                }
                if ((tt is Pullenti.Ner.NumberToken) && tt.Previous != null)
                {
                    if (tt.Previous.IsValue("USB", null))
                    {
                        t1 = (t = tt);
                        if (internals.Count == 0)
                        {
                            name.EndToken = t1;
                        }
                        for (Pullenti.Ner.Token ttt = tt.Next; ttt != null; ttt = ttt.Next)
                        {
                            if (ttt.IsWhitespaceBefore)
                            {
                                break;
                            }
                            if (ttt.IsCharOf(",:"))
                            {
                                break;
                            }
                            t1 = (t = (tt = ttt));
                            if (internals.Count == 0)
                            {
                                name.EndToken = t1;
                            }
                        }
                        continue;
                    }
                }
                NumbersWithUnitToken mt0 = NumbersWithUnitToken.TryParse(tt, addUnits, false, false, false, false);
                if (mt0 != null)
                {
                    Pullenti.Ner.Core.NounPhraseToken npt1 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.ParseNumericAsAdjective | Pullenti.Ner.Core.NounPhraseParseAttr.ParsePreposition, 0, null);
                    if (npt1 != null && npt1.EndChar > mt0.EndChar)
                    {
                        t1 = (t = (tt = npt1.EndToken));
                        if (internals.Count == 0)
                        {
                            name.EndToken = t1;
                        }
                        continue;
                    }
                    break;
                }
                if (((tt.IsComma || tt.IsChar('('))) && tt.Next != null)
                {
                    www = NumbersWithUnitToken._tryParseWHL(tt.Next);
                    if (www != null)
                    {
                        whd = www;
                        t1  = (t = (tt = www.EndToken));
                        if (tt.Next != null && tt.Next.IsComma)
                        {
                            t1 = (tt = tt.Next);
                        }
                        if (tt.Next != null && tt.Next.IsChar(')'))
                        {
                            t1 = (tt = tt.Next);
                            continue;
                        }
                    }
                    List <UnitToken> uu = UnitToken.TryParseList(tt.Next, addUnits, false);
                    if (uu != null)
                    {
                        t1    = (t = uu[uu.Count - 1].EndToken);
                        units = uu;
                        if (tt.IsChar('(') && t1.Next != null && t1.Next.IsChar(')'))
                        {
                            t1 = (t = (tt = t1.Next));
                            continue;
                        }
                        else if (t1.Next != null && t1.Next.IsChar('('))
                        {
                            uu = UnitToken.TryParseList(t1.Next.Next, addUnits, false);
                            if (uu != null && uu[uu.Count - 1].EndToken.Next != null && uu[uu.Count - 1].EndToken.Next.IsChar(')'))
                            {
                                units2 = uu;
                                t1     = (t = (tt = uu[uu.Count - 1].EndToken.Next));
                                continue;
                            }
                            www = NumbersWithUnitToken._tryParseWHL(t1.Next);
                            if (www != null)
                            {
                                whd = www;
                                t1  = (t = (tt = www.EndToken));
                                continue;
                            }
                        }
                        if (uu != null && uu.Count > 0 && !uu[0].IsDoubt)
                        {
                            break;
                        }
                        if (t1.Next != null)
                        {
                            if (t1.Next.IsTableControlChar || t1.IsNewlineAfter)
                            {
                                break;
                            }
                        }
                        units = null;
                    }
                }
                if (Pullenti.Ner.Core.BracketHelper.CanBeStartOfSequence(tt, false, false) && !(tt.Next is Pullenti.Ner.NumberToken))
                {
                    Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(tt, Pullenti.Ner.Core.BracketParseAttr.No, 100);
                    if (br != null)
                    {
                        t1 = (t = (tt = br.EndToken));
                        continue;
                    }
                }
                if (tt.IsValue("НЕ", null) && tt.Next != null)
                {
                    Pullenti.Morph.MorphClass mc = tt.Next.GetMorphClassInDictionary();
                    if (mc.IsAdverb || mc.IsMisc)
                    {
                        break;
                    }
                    continue;
                }
                if (tt.IsValue("ЯМЗ", null))
                {
                }
                Pullenti.Ner.Core.NounPhraseToken npt2 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.ParsePreposition | Pullenti.Ner.Core.NounPhraseParseAttr.IgnoreBrackets | Pullenti.Ner.Core.NounPhraseParseAttr.ParsePronouns, 0, null);
                if (npt2 == null)
                {
                    if (tt.Morph.Class.IsPreposition || tt.Morph.Class.IsConjunction)
                    {
                        Pullenti.Ner.Core.TerminToken to = NumbersWithUnitToken.m_Termins.TryParse(tt, Pullenti.Ner.Core.TerminParseAttr.No);
                        if (to != null)
                        {
                            if ((to.EndToken.Next is Pullenti.Ner.TextToken) && to.EndToken.Next.IsLetters)
                            {
                            }
                            else
                            {
                                break;
                            }
                        }
                        t1 = tt;
                        continue;
                    }
                    Pullenti.Morph.MorphClass mc = tt.GetMorphClassInDictionary();
                    if (((tt is Pullenti.Ner.TextToken) && tt.Chars.IsLetter && tt.LengthChar > 1) && (((tt.Chars.IsAllUpper || mc.IsAdverb || mc.IsUndefined) || mc.IsAdjective)))
                    {
                        List <UnitToken> uu = UnitToken.TryParseList(tt, addUnits, false);
                        if (uu != null)
                        {
                            if (uu[0].LengthChar > 1 || uu.Count > 1)
                            {
                                units = uu;
                                t1    = (t = uu[uu.Count - 1].EndToken);
                                break;
                            }
                        }
                        t1 = (t = tt);
                        if (internals.Count == 0)
                        {
                            name.EndToken = tt;
                        }
                        continue;
                    }
                    if (tt.IsComma)
                    {
                        continue;
                    }
                    if (tt.IsChar('.'))
                    {
                        if (!Pullenti.Ner.Core.MiscHelper.CanBeStartOfSentence(tt.Next))
                        {
                            continue;
                        }
                        List <UnitToken> uu = UnitToken.TryParseList(tt.Next, addUnits, false);
                        if (uu != null)
                        {
                            if (uu[0].LengthChar > 2 || uu.Count > 1)
                            {
                                units = uu;
                                t1    = (t = uu[uu.Count - 1].EndToken);
                                break;
                            }
                        }
                    }
                    break;
                }
                t1 = (t = (tt = npt2.EndToken));
                if (internals.Count > 0)
                {
                }
                else if (t.IsValue("ПРЕДЕЛ", null) || t.IsValue("ГРАНИЦА", null) || t.IsValue("ДИАПАЗОН", null))
                {
                }
                else if (t.Chars.IsLetter)
                {
                    name.EndToken = t1;
                }
            }
            Pullenti.Ner.Token t11 = t1;
            for (t1 = t1.Next; t1 != null; t1 = t1.Next)
            {
                if (t1.IsTableControlChar)
                {
                }
                else if (t1.IsCharOf(":,_"))
                {
                    if (isResctriction)
                    {
                        return(null);
                    }
                    Pullenti.Ner.MetaToken www = NumbersWithUnitToken._tryParseWHL(t1.Next);
                    if (www != null)
                    {
                        whd = www;
                        t1  = (t = www.EndToken);
                        continue;
                    }
                    List <UnitToken> uu = UnitToken.TryParseList(t1.Next, addUnits, false);
                    if (uu != null)
                    {
                        if (uu[0].LengthChar > 1 || uu.Count > 1)
                        {
                            units = uu;
                            t1    = (t = uu[uu.Count - 1].EndToken);
                            continue;
                        }
                    }
                    if (t1.IsChar(':'))
                    {
                        List <MeasureToken> li = new List <MeasureToken>();
                        for (Pullenti.Ner.Token ttt = t1.Next; ttt != null; ttt = ttt.Next)
                        {
                            if (ttt.IsHiphen || ttt.IsTableControlChar)
                            {
                                continue;
                            }
                            if ((ttt is Pullenti.Ner.TextToken) && !ttt.Chars.IsLetter)
                            {
                                continue;
                            }
                            MeasureToken mt1 = TryParse(ttt, addUnits, true, true, false, true);
                            if (mt1 == null)
                            {
                                break;
                            }
                            li.Add(mt1);
                            ttt = mt1.EndToken;
                            if (ttt.Next != null && ttt.Next.IsChar(';'))
                            {
                                ttt = ttt.Next;
                            }
                            if (ttt.IsChar(';'))
                            {
                            }
                            else if (ttt.IsNewlineAfter && mt1.IsNewlineBefore)
                            {
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (li.Count > 1)
                        {
                            MeasureToken res0 = new MeasureToken(t0, li[li.Count - 1].EndToken)
                            {
                                Internals = li, IsEmpty = true
                            };
                            if (internals != null && internals.Count > 0)
                            {
                                res0.InternalEx = internals[0];
                            }
                            string nam = Pullenti.Ner.Core.MiscHelper.GetTextValueOfMetaToken(name, Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominative);
                            li[0].BeginToken = t0;
                            foreach (MeasureToken v in li)
                            {
                                v.Name = string.Format("{0} ({1})", nam, v.Name ?? "").Trim();
                                if (v.Nums != null && v.Nums.Units.Count == 0 && units != null)
                                {
                                    v.Nums.Units = units;
                                }
                            }
                            return(res0);
                        }
                    }
                }
                else if (t1.IsHiphen && t1.IsWhitespaceAfter && t1.IsWhitespaceBefore)
                {
                }
                else if (t1.IsHiphen && t1.Next != null && t1.Next.IsChar('('))
                {
                }
                else
                {
                    break;
                }
            }
            if (t1 == null)
            {
                return(null);
            }
            List <NumbersWithUnitToken> mts = NumbersWithUnitToken.TryParseMulti(t1, addUnits, false, not, true, isResctriction);

            if (mts == null)
            {
                if (units != null && units.Count > 0)
                {
                    if (t1 == null || t1.Previous.IsChar(':'))
                    {
                        mts = new List <NumbersWithUnitToken>();
                        if (t1 == null)
                        {
                            for (t1 = t11; t1 != null && t1.Next != null; t1 = t1.Next)
                            {
                            }
                        }
                        else
                        {
                            t1 = t1.Previous;
                        }
                        mts.Add(new NumbersWithUnitToken(t0, t1)
                        {
                            SingleVal = double.NaN
                        });
                    }
                }
                if (mts == null)
                {
                    return(null);
                }
            }
            NumbersWithUnitToken mt = mts[0];

            if (mt.BeginToken == mt.EndToken && !(mt.BeginToken is Pullenti.Ner.NumberToken))
            {
                return(null);
            }
            if (!isSubval && name.BeginToken.Morph.Class.IsPreposition)
            {
                name.BeginToken = name.BeginToken.Next;
            }
            if (mt.WHL != null)
            {
                whd = mt.WHL;
            }
            for (int kk = 0; kk < 10; kk++)
            {
                if (whd != null && whd.EndToken == name.EndToken)
                {
                    name.EndToken = whd.BeginToken.Previous;
                    continue;
                }
                if (units != null)
                {
                    if (units[units.Count - 1].EndToken == name.EndToken)
                    {
                        name.EndToken = units[0].BeginToken.Previous;
                        continue;
                    }
                }
                break;
            }
            if (mts.Count > 1 && internals.Count == 0)
            {
                if (mt.Units.Count == 0)
                {
                    if (units != null)
                    {
                        foreach (NumbersWithUnitToken m in mts)
                        {
                            m.Units = units;
                        }
                    }
                }
                MeasureToken res1 = new MeasureToken(t0, mts[mts.Count - 1].EndToken)
                {
                    Morph = name.Morph, Reliable = true
                };
                res1.Name = Pullenti.Ner.Core.MiscHelper.GetTextValueOfMetaToken(name, Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominative);
                for (int k = 0; k < mts.Count; k++)
                {
                    MeasureToken ttt = new MeasureToken(mts[k].BeginToken, mts[k].EndToken)
                    {
                        Nums = mts[k]
                    };
                    if (whd != null)
                    {
                        List <string> nams = whd.Tag as List <string>;
                        if (k < nams.Count)
                        {
                            ttt.Name = nams[k];
                        }
                    }
                    res1.Internals.Add(ttt);
                }
                Pullenti.Ner.Token tt1 = res1.EndToken.Next;
                if (tt1 != null && tt1.IsChar('±'))
                {
                    NumbersWithUnitToken nn = NumbersWithUnitToken._tryParse(tt1, addUnits, true, false, false);
                    if (nn != null && nn.PlusMinusPercent)
                    {
                        res1.EndToken = nn.EndToken;
                        res1.Nums     = nn;
                        if (nn.Units.Count > 0 && units == null && mt.Units.Count == 0)
                        {
                            foreach (NumbersWithUnitToken m in mts)
                            {
                                m.Units = nn.Units;
                            }
                        }
                    }
                }
                return(res1);
            }
            if (!mt.IsWhitespaceBefore)
            {
                if (mt.BeginToken.Previous == null)
                {
                    return(null);
                }
                if (mt.BeginToken.Previous.IsCharOf(":),") || mt.BeginToken.Previous.IsTableControlChar || mt.BeginToken.Previous.IsValue("IP", null))
                {
                }
                else if (mt.BeginToken.IsHiphen && mt.Units.Count > 0 && !mt.Units[0].IsDoubt)
                {
                }
                else
                {
                    return(null);
                }
            }
            if (mt.Units.Count == 0 && units != null)
            {
                mt.Units = units;
                if (mt.DivNum != null && units.Count > 1 && mt.DivNum.Units.Count == 0)
                {
                    for (int i = 1; i < units.Count; i++)
                    {
                        if (units[i].Pow == -1)
                        {
                            for (int j = i; j < units.Count; j++)
                            {
                                mt.DivNum.Units.Add(units[j]);
                                units[j].Pow = -units[j].Pow;
                            }
                            mt.Units.RemoveRange(i, units.Count - i);
                            break;
                        }
                    }
                }
            }
            if ((minmax < 0) && mt.SingleVal != null)
            {
                mt.FromVal     = mt.SingleVal;
                mt.FromInclude = true;
                mt.SingleVal   = null;
            }
            if (minmax > 0 && mt.SingleVal != null)
            {
                mt.ToVal     = mt.SingleVal;
                mt.ToInclude = true;
                mt.SingleVal = null;
            }
            if (mt.Units.Count == 0)
            {
                units = UnitToken.TryParseList(mt.EndToken.Next, addUnits, true);
                if (units == null)
                {
                    if (canUnitsAbsent)
                    {
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    mt.Units = units;
                }
            }
            MeasureToken res = new MeasureToken(t0, mt.EndToken)
            {
                Morph = name.Morph, Internals = internals
            };

            if (((!t0.IsWhitespaceBefore && t0.Previous != null && t0 == name.BeginToken) && t0.Previous.IsHiphen && !t0.Previous.IsWhitespaceBefore) && (t0.Previous.Previous is Pullenti.Ner.TextToken))
            {
                name.BeginToken = (res.BeginToken = name.BeginToken.Previous.Previous);
            }
            res.Name = Pullenti.Ner.Core.MiscHelper.GetTextValueOfMetaToken(name, (!isSubval ? Pullenti.Ner.Core.GetTextAttr.FirstNounGroupToNominative : Pullenti.Ner.Core.GetTextAttr.No));
            res.Nums = mt;
            foreach (UnitToken u in res.Nums.Units)
            {
                if (u.Keyword != null)
                {
                    if (u.Keyword.BeginChar >= res.BeginChar)
                    {
                        res.Reliable = true;
                    }
                }
            }
            res._parseInternals(addUnits);
            if (res.Internals.Count > 0 || !canBeSet)
            {
                return(res);
            }
            t1 = res.EndToken.Next;
            if (t1 != null && t1.IsCommaAnd)
            {
                t1 = t1.Next;
            }
            List <NumbersWithUnitToken> mts1 = NumbersWithUnitToken.TryParseMulti(t1, addUnits, false, false, false, false);

            if ((mts1 != null && mts1.Count == 1 && (t1.WhitespacesBeforeCount < 3)) && mts1[0].Units.Count > 0 && !UnitToken.CanBeEquals(mts[0].Units, mts1[0].Units))
            {
                res.IsSet = true;
                res.Nums  = null;
                res.Internals.Add(new MeasureToken(mt.BeginToken, mt.EndToken)
                {
                    Nums = mt
                });
                res.Internals.Add(new MeasureToken(mts1[0].BeginToken, mts1[0].EndToken)
                {
                    Nums = mts1[0]
                });
                res.EndToken = mts1[0].EndToken;
            }
            return(res);
        }
Пример #5
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);
        }
Пример #6
0
        public static List <NumbersWithUnitToken> TryParseMulti(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool canOmitNumber = false, bool not = false, bool canBeNon = false, bool isResctriction = false)
        {
            if (t == null || (t is Pullenti.Ner.ReferentToken))
            {
                return(null);
            }
            Pullenti.Ner.Token tt0 = t;
            if (tt0.IsChar('('))
            {
                Pullenti.Ner.MetaToken whd = _tryParseWHL(tt0);
                if (whd != null)
                {
                    tt0 = whd.EndToken;
                }
                List <NumbersWithUnitToken> res0 = TryParseMulti(tt0.Next, addUnits, false, canOmitNumber, canBeNon, false);
                if (res0 != null)
                {
                    res0[0].WHL = whd;
                    Pullenti.Ner.Token tt2 = res0[res0.Count - 1].EndToken.Next;
                    if (tt2 != null && tt2.IsCharOf(","))
                    {
                        tt2 = tt2.Next;
                    }
                    if (whd != null)
                    {
                        return(res0);
                    }
                    if (tt2 != null && tt2.IsChar(')'))
                    {
                        res0[res0.Count - 1].EndToken = tt2;
                        return(res0);
                    }
                }
            }
            NumbersWithUnitToken mt = TryParse(t, addUnits, canOmitNumber, not, canBeNon, isResctriction);

            if (mt == null)
            {
                return(null);
            }
            List <NumbersWithUnitToken> res = new List <NumbersWithUnitToken>();

            Pullenti.Ner.Token nnn = null;
            if (mt.WhitespacesAfterCount < 2)
            {
                if (MeasureHelper.IsMultChar(mt.EndToken.Next))
                {
                    nnn = mt.EndToken.Next.Next;
                }
                else if ((mt.EndToken is Pullenti.Ner.NumberToken) && MeasureHelper.IsMultChar((mt.EndToken as Pullenti.Ner.NumberToken).EndToken))
                {
                    nnn = mt.EndToken.Next;
                }
            }
            if (nnn != null)
            {
                NumbersWithUnitToken mt2 = NumbersWithUnitToken.TryParse(nnn, addUnits, not, false, false, false);
                if (mt2 != null)
                {
                    NumbersWithUnitToken mt3 = null;
                    nnn = null;
                    if (mt2.WhitespacesAfterCount < 2)
                    {
                        if (MeasureHelper.IsMultChar(mt2.EndToken.Next))
                        {
                            nnn = mt2.EndToken.Next.Next;
                        }
                        else if ((mt2.EndToken is Pullenti.Ner.NumberToken) && MeasureHelper.IsMultChar((mt2.EndToken as Pullenti.Ner.NumberToken).EndToken))
                        {
                            nnn = mt2.EndToken.Next;
                        }
                    }
                    if (nnn != null)
                    {
                        mt3 = NumbersWithUnitToken.TryParse(nnn, addUnits, false, false, false, false);
                    }
                    if (mt3 == null)
                    {
                        Pullenti.Ner.Token tt2 = mt2.EndToken.Next;
                        if (tt2 != null && !tt2.IsWhitespaceBefore)
                        {
                            if (!tt2.IsCharOf(",.;"))
                            {
                                return(null);
                            }
                        }
                    }
                    if (mt3 != null && mt3.Units.Count > 0)
                    {
                        if (mt2.Units.Count == 0)
                        {
                            mt2.Units = mt3.Units;
                        }
                    }
                    res.Add(mt);
                    if (mt2 != null)
                    {
                        if (mt2.Units.Count > 0 && mt.Units.Count == 0)
                        {
                            mt.Units = mt2.Units;
                        }
                        res.Add(mt2);
                        if (mt3 != null)
                        {
                            res.Add(mt3);
                        }
                    }
                    return(res);
                }
            }
            if ((!mt.IsWhitespaceAfter && MeasureHelper.IsMultCharEnd(mt.EndToken.Next) && (mt.EndToken.Next.Next is Pullenti.Ner.NumberToken)) && mt.Units.Count == 0)
            {
                string utxt = (mt.EndToken.Next as Pullenti.Ner.TextToken).Term;
                utxt = utxt.Substring(0, utxt.Length - 1);
                List <Pullenti.Ner.Core.Termin> terms = UnitsHelper.Termins.FindTerminsByString(utxt, null);
                if (terms != null && terms.Count > 0)
                {
                    mt.Units.Add(new UnitToken(mt.EndToken.Next, mt.EndToken.Next)
                    {
                        Unit = terms[0].Tag as Unit
                    });
                    mt.EndToken = mt.EndToken.Next;
                    List <NumbersWithUnitToken> res1 = TryParseMulti(mt.EndToken.Next, addUnits, false, false, false, false);
                    if (res1 != null)
                    {
                        res1.Insert(0, mt);
                        return(res1);
                    }
                }
            }
            res.Add(mt);
            return(res);
        }