Exemplo n.º 1
0
 public static Pullenti.Ner.Core.NumberExToken TryAttachPostfixOnly(Pullenti.Ner.Token t)
 {
     if (t == null)
     {
         return(null);
     }
     Pullenti.Ner.Core.TerminToken   tok = m_Postfixes.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No);
     Pullenti.Ner.Core.NumberExToken res = null;
     if (tok != null)
     {
         res = new Pullenti.Ner.Core.NumberExToken(t, tok.EndToken, "", Pullenti.Ner.NumberSpellingType.Digit, (Pullenti.Ner.Core.NumberExType)tok.Termin.Tag)
         {
             Tag = tok.Termin
         }
     }
     ;
     else
     {
         res = _attachSpecPostfix(t);
     }
     if (res != null)
     {
         _correctExtTypes(res);
     }
     return(res);
 }
Exemplo n.º 2
0
        static void _correctExtTypes(Pullenti.Ner.Core.NumberExToken ex)
        {
            Pullenti.Ner.Token t = ex.EndToken.Next;
            if (t == null)
            {
                return;
            }
            Pullenti.Ner.Core.NumberExType ty = ex.ExTyp;
            Pullenti.Ner.Token             tt = _corrExTyp2(t, ref ty);
            if (tt != null)
            {
                ex.ExTyp    = ty;
                ex.EndToken = tt;
                t           = tt.Next;
            }
            if (t == null || t.Next == null)
            {
                return;
            }
            if (t.IsCharOf("/\\") || t.IsValue("НА", null))
            {
            }
            else
            {
                return;
            }
            Pullenti.Ner.Core.TerminToken tok = m_Postfixes.TryParse(t.Next, Pullenti.Ner.Core.TerminParseAttr.No);
            if (tok != null && (((Pullenti.Ner.Core.NumberExType)tok.Termin.Tag) != Pullenti.Ner.Core.NumberExType.Money))
            {
                ex.ExTyp2   = (Pullenti.Ner.Core.NumberExType)tok.Termin.Tag;
                ex.EndToken = tok.EndToken;
                ty          = ex.ExTyp2;
                tt          = _corrExTyp2(ex.EndToken.Next, ref ty);
                if (tt != null)
                {
                    ex.ExTyp2 = ty;

                    ex.EndToken = tt;
                    t           = tt.Next;
                }
            }
        }
Exemplo n.º 3
0
        public static Pullenti.Ner.MetaToken CheckNds(Pullenti.Ner.Token t, double nds = (double)18F, bool ndsMustbeMoney = false)
        {
            if (t == null || nds <= 0)
            {
                return(null);
            }
            Pullenti.Ner.Money.MoneyReferent m = t.GetReferent() as Pullenti.Ner.Money.MoneyReferent;
            if (m == null)
            {
                return(null);
            }
            bool hasNds     = false;
            bool hasNdsPerc = false;
            bool hasAll     = false;
            bool incl       = false;

            Pullenti.Ner.Token tt;
            Pullenti.Ner.Money.MoneyReferent m1 = null;
            Pullenti.Ner.Token ndsT0            = null;
            Pullenti.Ner.Token ndsT1            = null;
            for (tt = t.Next; tt != null; tt = tt.Next)
            {
                if (tt.IsValue("НДС", null))
                {
                    hasNds = true;
                    ndsT0  = (ndsT1 = tt);
                    continue;
                }
                if (tt is Pullenti.Ner.ReferentToken)
                {
                    m1 = tt.GetReferent() as Pullenti.Ner.Money.MoneyReferent;
                    break;
                }
                if (tt is Pullenti.Ner.NumberToken)
                {
                    Pullenti.Ner.Core.NumberExToken ne = Pullenti.Ner.Core.NumberHelper.TryParseNumberWithPostfix(tt);
                    if (ne != null && ne.ExTyp == Pullenti.Ner.Core.NumberExType.Percent)
                    {
                        if (Math.Abs(ne.RealValue - nds) > 0.0001)
                        {
                            bool ok = false;
                            if (hasNds)
                            {
                                ok = true;
                            }
                            if (ok)
                            {
                                return new Pullenti.Ner.MetaToken(tt, ne.EndToken)
                                       {
                                           Tag = string.Format("Размер НДС должен быть {0}%, а не {1}%", nds, ne.RealValue)
                                       }
                            }
                            ;
                        }
                        tt         = (ndsT1 = ne.EndToken);
                        hasNdsPerc = true;
                        continue;
                    }
                }
                if (tt.IsValue("ВСЕГО", null))
                {
                    hasAll = true;
                    continue;
                }
                if (tt.IsValue("ТОМ", null) || tt.IsValue("ЧИСЛО", null) || tt.IsValue("ВКЛЮЧАЯ", null))
                {
                    incl = true;
                    continue;
                }
                if ((tt.IsValue("КРОМЕ", null) || tt.IsValue("ТОГО", null) || tt.IsValue("РАЗМЕР", null)) || tt.IsValue("СУММА", null) || tt.IsValue("СТАВКА", null))
                {
                    continue;
                }
                if (((tt.IsValue("Т", null) && tt.Next != null && tt.Next.IsChar('.')) && tt.Next.Next != null && tt.Next.Next.IsValue("Ч", null)) && tt.Next.Next.Next != null && tt.Next.Next.Next.IsChar('.'))
                {
                    incl = true;
                    tt   = tt.Next.Next.Next;
                    continue;
                }
                if (!tt.Chars.IsLetter || tt.Morph.Class.IsPreposition)
                {
                    continue;
                }
                break;
            }
            if (!hasNds)
            {
                return(null);
            }
            if (m1 == null)
            {
                if (ndsMustbeMoney)
                {
                    return new Pullenti.Ner.MetaToken(ndsT0, ndsT1)
                           {
                               Tag = "Размер НДС должен быть в денежном выражении"
                           }
                }
                ;
                return(null);
            }
            if (hasAll)
            {
                return(null);
            }
            double mustBe = m.RealValue;

            mustBe = mustBe * ((nds / 100));
            if (incl)
            {
                mustBe /= ((1 + ((nds / 100))));
            }
            double dd = mustBe * 100;

            dd     -= ((long)dd);
            dd     /= 100;
            mustBe -= dd;
            if (dd >= 0.005)
            {
                mustBe += 0.01;
            }
            double real  = m1.RealValue;
            double delta = mustBe - real;

            if (delta < 0)
            {
                delta = -delta;
            }
            if (delta > 0.011)
            {
                if ((delta < 1) && m1.Rest == 0 && m.Rest == 0)
                {
                }
                else
                {
                    Pullenti.Ner.Money.MoneyReferent mr = new Pullenti.Ner.Money.MoneyReferent()
                    {
                        Currency = m1.Currency, RealValue = mustBe
                    };

                    return(new Pullenti.Ner.MetaToken(t, tt)
                    {
                        Tag = string.Format("Размер НДС должен быть {0}, а не {1}", _outMoney(mr), _outMoney(m1))
                    });
                }
            }
            if (incl)
            {
                return(null);
            }
            Pullenti.Ner.Money.MoneyReferent m2 = null;
            hasAll = false;
            for (tt = tt.Next; tt != null; tt = tt.Next)
            {
                if (tt is Pullenti.Ner.ReferentToken)
                {
                    m2 = tt.GetReferent() as Pullenti.Ner.Money.MoneyReferent;
                    break;
                }
                if (!tt.Chars.IsLetter || tt.Morph.Class.IsPreposition)
                {
                    continue;
                }
                if (tt.IsValue("ВСЕГО", null))
                {
                    hasAll = true;
                    continue;
                }
                if (tt.IsValue("НДС", null) || tt.IsValue("ВМЕСТЕ", null))
                {
                    continue;
                }
                break;
            }
            if (m2 != null && hasAll)
            {
                mustBe = m.RealValue + m1.RealValue;
                delta  = mustBe - m2.RealValue;
                if (delta < 0)
                {
                    delta = -delta;
                }
                if (delta > 0.01)
                {
                    Pullenti.Ner.Money.MoneyReferent mr = new Pullenti.Ner.Money.MoneyReferent()
                    {
                        Currency = m1.Currency, RealValue = mustBe
                    };
                    string err = string.Format("Всего с НДС должно быть {0}, а не {1}", _outMoney(mr), _outMoney(m2));
                    return(new Pullenti.Ner.MetaToken(t, tt)
                    {
                        Tag = err
                    });
                }
            }
            return(null);
        }
    }
}
Exemplo n.º 4
0
        public static Pullenti.Ner.ReferentToken TryParse(Pullenti.Ner.Token t)
        {
            if (t == null)
            {
                return(null);
            }
            if (!(t is Pullenti.Ner.NumberToken) && t.LengthChar != 1)
            {
                return(null);
            }
            Pullenti.Ner.Core.NumberExToken nex = Pullenti.Ner.Core.NumberHelper.TryParseNumberWithPostfix(t);
            if (nex == null || nex.ExTyp != Pullenti.Ner.Core.NumberExType.Money)
            {
                if ((t is Pullenti.Ner.NumberToken) && (t.Next is Pullenti.Ner.TextToken) && (t.Next.Next is Pullenti.Ner.NumberToken))
                {
                    if (t.Next.IsHiphen || t.Next.Morph.Class.IsPreposition)
                    {
                        Pullenti.Ner.Core.NumberExToken res1 = Pullenti.Ner.Core.NumberHelper.TryParseNumberWithPostfix(t.Next.Next);
                        if (res1 != null && res1.ExTyp == Pullenti.Ner.Core.NumberExType.Money)
                        {
                            MoneyReferent res0 = new MoneyReferent();
                            if ((t.Next.IsHiphen && res1.RealValue == 0 && res1.EndToken.Next != null) && res1.EndToken.Next.IsChar('('))
                            {
                                Pullenti.Ner.Core.NumberExToken nex2 = Pullenti.Ner.Core.NumberHelper.TryParseNumberWithPostfix(res1.EndToken.Next.Next);
                                if ((nex2 != null && nex2.ExTypParam == res1.ExTypParam && nex2.EndToken.Next != null) && nex2.EndToken.Next.IsChar(')'))
                                {
                                    if (nex2.Value == (t as Pullenti.Ner.NumberToken).Value)
                                    {
                                        res0.Currency = nex2.ExTypParam;
                                        res0.AddSlot(MoneyReferent.ATTR_VALUE, nex2.Value, true, 0);
                                        return(new Pullenti.Ner.ReferentToken(res0, t, nex2.EndToken.Next));
                                    }
                                    if (t.Previous is Pullenti.Ner.NumberToken)
                                    {
                                        if (nex2.Value == ((((t.Previous as Pullenti.Ner.NumberToken).RealValue * 1000) + (t as Pullenti.Ner.NumberToken).Value)))
                                        {
                                            res0.Currency = nex2.ExTypParam;
                                            res0.AddSlot(MoneyReferent.ATTR_VALUE, nex2.Value, true, 0);
                                            return(new Pullenti.Ner.ReferentToken(res0, t.Previous, nex2.EndToken.Next));
                                        }
                                        else if (t.Previous.Previous is Pullenti.Ner.NumberToken)
                                        {
                                            if (nex2.RealValue == ((((t.Previous.Previous as Pullenti.Ner.NumberToken).RealValue * 1000000) + ((t.Previous as Pullenti.Ner.NumberToken).RealValue * 1000) + (t as Pullenti.Ner.NumberToken).RealValue)))
                                            {
                                                res0.Currency = nex2.ExTypParam;
                                                res0.AddSlot(MoneyReferent.ATTR_VALUE, nex2.Value, true, 0);
                                                return(new Pullenti.Ner.ReferentToken(res0, t.Previous.Previous, nex2.EndToken.Next));
                                            }
                                        }
                                    }
                                }
                            }
                            res0.Currency = res1.ExTypParam;
                            res0.AddSlot(MoneyReferent.ATTR_VALUE, (t as Pullenti.Ner.NumberToken).Value, false, 0);
                            return(new Pullenti.Ner.ReferentToken(res0, t, t));
                        }
                    }
                }
                return(null);
            }
            MoneyReferent res = new MoneyReferent();

            res.Currency = nex.ExTypParam;
            string val = nex.Value;

            if (val.IndexOf('.') > 0)
            {
                val = val.Substring(0, val.IndexOf('.'));
            }
            res.AddSlot(MoneyReferent.ATTR_VALUE, val, true, 0);
            int re = (int)Math.Round(((nex.RealValue - res.Value)) * 100, 6);

            if (re != 0)
            {
                res.AddSlot(MoneyReferent.ATTR_REST, re.ToString(), true, 0);
            }
            if (nex.RealValue != nex.AltRealValue)
            {
                if (Math.Floor(res.Value) != Math.Floor(nex.AltRealValue))
                {
                    val = Pullenti.Ner.Core.NumberHelper.DoubleToString(nex.AltRealValue);
                    if (val.IndexOf('.') > 0)
                    {
                        val = val.Substring(0, val.IndexOf('.'));
                    }
                    res.AddSlot(MoneyReferent.ATTR_ALTVALUE, val, true, 0);
                }
                re = (int)Math.Round(((nex.AltRealValue - ((long)nex.AltRealValue))) * 100, 6);
                if (re != res.Rest && re != 0)
                {
                    res.AddSlot(MoneyReferent.ATTR_ALTREST, ((int)re).ToString(), true, 0);
                }
            }
            if (nex.AltRestMoney > 0)
            {
                res.AddSlot(MoneyReferent.ATTR_ALTREST, nex.AltRestMoney.ToString(), true, 0);
            }
            Pullenti.Ner.Token t1 = nex.EndToken;
            if (t1.Next != null && t1.Next.IsChar('('))
            {
                Pullenti.Ner.ReferentToken rt = TryParse(t1.Next.Next);
                if ((rt != null && rt.Referent.CanBeEquals(res, Pullenti.Ner.Core.ReferentsEqualType.WithinOneText) && rt.EndToken.Next != null) && rt.EndToken.Next.IsChar(')'))
                {
                    t1 = rt.EndToken.Next;
                }
                else
                {
                    rt = TryParse(t1.Next);
                    if (rt != null && rt.Referent.CanBeEquals(res, Pullenti.Ner.Core.ReferentsEqualType.WithinOneText))
                    {
                        t1 = rt.EndToken;
                    }
                }
            }
            if (res.AltValue != null && res.AltValue.Value > res.Value)
            {
                if (t.WhitespacesBeforeCount == 1 && (t.Previous is Pullenti.Ner.NumberToken))
                {
                    int delt = (int)((res.AltValue.Value - res.Value));
                    if ((((res.Value < 1000) && ((delt % 1000)) == 0)) || (((res.Value < 1000000) && ((delt % 1000000)) == 0)))
                    {
                        t = t.Previous;
                        res.AddSlot(MoneyReferent.ATTR_VALUE, res.GetStringValue(MoneyReferent.ATTR_ALTVALUE), true, 0);
                        res.AddSlot(MoneyReferent.ATTR_ALTVALUE, null, true, 0);
                    }
                }
            }
            return(new Pullenti.Ner.ReferentToken(res, t, t1));
        }
Exemplo n.º 5
0
        static Pullenti.Ner.Core.NumberExToken _correctMoney(Pullenti.Ner.Core.NumberExToken res, Pullenti.Ner.Token t1)
        {
            if (t1 == null)
            {
                return(null);
            }
            List <Pullenti.Ner.Core.TerminToken> toks = m_Postfixes.TryParseAll(t1, Pullenti.Ner.Core.TerminParseAttr.No);

            if (toks == null || toks.Count == 0)
            {
                return(null);
            }
            Pullenti.Ner.Token    tt = toks[0].EndToken.Next;
            Pullenti.Ner.Referent r  = (tt == null ? null : tt.GetReferent());
            string alpha2            = null;

            if (r != null && r.TypeName == "GEO")
            {
                alpha2 = r.GetStringValue("ALPHA2");
            }
            if (alpha2 != null && toks.Count > 0)
            {
                for (int i = toks.Count - 1; i >= 0; i--)
                {
                    if (!toks[i].Termin.CanonicText.StartsWith(alpha2))
                    {
                        toks.RemoveAt(i);
                    }
                }
                if (toks.Count == 0)
                {
                    toks = m_Postfixes.TryParseAll(t1, Pullenti.Ner.Core.TerminParseAttr.No);
                }
            }
            if (toks.Count > 1)
            {
                alpha2 = null;
                string str = toks[0].Termin.Terms[0].CanonicalText;
                if (str == "РУБЛЬ" || str == "RUBLE")
                {
                    alpha2 = "RU";
                }
                else if (str == "ДОЛЛАР" || str == "ДОЛАР" || str == "DOLLAR")
                {
                    alpha2 = "US";
                }
                else if (str == "ФУНТ" || str == "POUND")
                {
                    alpha2 = "UK";
                }
                if (alpha2 != null)
                {
                    for (int i = toks.Count - 1; i >= 0; i--)
                    {
                        if (!toks[i].Termin.CanonicText.StartsWith(alpha2) && toks[i].Termin.CanonicText != "GBP")
                        {
                            toks.RemoveAt(i);
                        }
                    }
                }
                alpha2 = null;
            }
            if (toks.Count < 1)
            {
                return(null);
            }
            res.ExTypParam = toks[0].Termin.CanonicText;
            if (alpha2 != null && tt != null)
            {
                res.EndToken = tt;
            }
            tt = res.EndToken.Next;
            if (tt != null && tt.IsCommaAnd)
            {
                tt = tt.Next;
            }
            if ((tt is Pullenti.Ner.NumberToken) && tt.Next != null && (tt.WhitespacesAfterCount < 4))
            {
                Pullenti.Ner.Token tt1 = tt.Next;
                if ((tt1 != null && tt1.IsChar('(') && (tt1.Next is Pullenti.Ner.NumberToken)) && tt1.Next.Next != null && tt1.Next.Next.IsChar(')'))
                {
                    if ((tt as Pullenti.Ner.NumberToken).Value == (tt1.Next as Pullenti.Ner.NumberToken).Value)
                    {
                        tt1 = tt1.Next.Next.Next;
                    }
                }
                Pullenti.Ner.Core.TerminToken tok = m_SmallMoney.TryParse(tt1, Pullenti.Ner.Core.TerminParseAttr.No);
                if (tok == null && tt1 != null && tt1.IsChar(')'))
                {
                    tok = m_SmallMoney.TryParse(tt1.Next, Pullenti.Ner.Core.TerminParseAttr.No);
                }
                if (tok != null && (tt as Pullenti.Ner.NumberToken).IntValue != null)
                {
                    int max = (int)tok.Termin.Tag;
                    int val = (tt as Pullenti.Ner.NumberToken).IntValue.Value;
                    if (val < max)
                    {
                        double f = (double)val;
                        f /= max;
                        double f0  = res.RealValue - ((long)res.RealValue);
                        int    re0 = (int)(((f0 * 100) + 0.0001));
                        if (re0 > 0 && val != re0)
                        {
                            res.AltRestMoney = val;
                        }
                        else if (f0 == 0)
                        {
                            res.RealValue += f;
                        }
                        f0  = res.AltRealValue - ((long)res.AltRealValue);
                        re0 = (int)(((f0 * 100) + 0.0001));
                        if (re0 > 0 && val != re0)
                        {
                            res.AltRestMoney = val;
                        }
                        else if (f0 == 0)
                        {
                            res.AltRealValue += f;
                        }
                        res.EndToken = tok.EndToken;
                    }
                }
            }
            else if ((tt is Pullenti.Ner.TextToken) && tt.IsValue("НОЛЬ", null))
            {
                Pullenti.Ner.Core.TerminToken tok = m_SmallMoney.TryParse(tt.Next, Pullenti.Ner.Core.TerminParseAttr.No);
                if (tok != null)
                {
                    res.EndToken = tok.EndToken;
                }
            }
            return(res);
        }
Exemplo n.º 6
0
        public static Pullenti.Ner.Core.NumberExToken TryParseNumberWithPostfix(Pullenti.Ner.Token t)
        {
            if (t == null)
            {
                return(null);
            }
            Pullenti.Ner.Token t0       = t;
            string             isDollar = null;

            if (t.LengthChar == 1 && t.Next != null)
            {
                if ((((isDollar = Pullenti.Ner.Core.NumberHelper.IsMoneyChar(t)))) != null)
                {
                    t = t.Next;
                }
            }
            Pullenti.Ner.NumberToken nt = t as Pullenti.Ner.NumberToken;
            if (nt == null)
            {
                if ((!(t.Previous is Pullenti.Ner.NumberToken) && t.IsChar('(') && (t.Next is Pullenti.Ner.NumberToken)) && t.Next.Next != null && t.Next.Next.IsChar(')'))
                {
                    Pullenti.Ner.Core.TerminToken toks1 = m_Postfixes.TryParse(t.Next.Next.Next, Pullenti.Ner.Core.TerminParseAttr.No);
                    if (toks1 != null && ((Pullenti.Ner.Core.NumberExType)toks1.Termin.Tag) == Pullenti.Ner.Core.NumberExType.Money)
                    {
                        Pullenti.Ner.NumberToken        nt0 = t.Next as Pullenti.Ner.NumberToken;
                        Pullenti.Ner.Core.NumberExToken res = new Pullenti.Ner.Core.NumberExToken(t, toks1.EndToken, nt0.Value, nt0.Typ, Pullenti.Ner.Core.NumberExType.Money)
                        {
                            AltRealValue = nt0.RealValue, Morph = toks1.BeginToken.Morph
                        };
                        return(_correctMoney(res, toks1.BeginToken));
                    }
                }
                Pullenti.Ner.TextToken tt = t as Pullenti.Ner.TextToken;
                if (tt == null || !tt.Morph.Class.IsAdjective)
                {
                    return(null);
                }
                string val = tt.Term;
                for (int i = 4; i < (val.Length - 5); i++)
                {
                    string v = val.Substring(0, i);
                    List <Pullenti.Ner.Core.Termin> li = Pullenti.Ner.Core.NumberHelper.m_Nums.FindTerminsByString(v, tt.Morph.Language);
                    if (li == null)
                    {
                        continue;
                    }
                    string vv = val.Substring(i);
                    List <Pullenti.Ner.Core.Termin> lii = m_Postfixes.FindTerminsByString(vv, tt.Morph.Language);
                    if (lii != null && lii.Count > 0)
                    {
                        Pullenti.Ner.Core.NumberExToken re = new Pullenti.Ner.Core.NumberExToken(t, t, ((int)li[0].Tag).ToString(), Pullenti.Ner.NumberSpellingType.Words, (Pullenti.Ner.Core.NumberExType)lii[0].Tag)
                        {
                            Morph = t.Morph
                        };
                        _correctExtTypes(re);
                        return(re);
                    }
                    break;
                }
                return(null);
            }
            if (t.Next == null && isDollar == null)
            {
                return(null);
            }
            double f = nt.RealValue;

            if (double.IsNaN(f))
            {
                return(null);
            }
            Pullenti.Ner.Token t1 = nt.Next;
            if (((t1 != null && t1.IsCharOf(",."))) || (((t1 is Pullenti.Ner.NumberToken) && (t1.WhitespacesBeforeCount < 3))))
            {
                double d;
                Pullenti.Ner.NumberToken tt11 = Pullenti.Ner.Core.NumberHelper.TryParseRealNumber(nt, false, false);
                if (tt11 != null)
                {
                    t1 = tt11.EndToken.Next;
                    f  = tt11.RealValue;
                }
            }
            if (t1 == null)
            {
                if (isDollar == null)
                {
                    return(null);
                }
            }
            else if ((t1.Next != null && t1.Next.IsValue("С", "З") && t1.Next.Next != null) && t1.Next.Next.IsValue("ПОЛОВИНА", null))
            {
                f += 0.5;
                t1 = t1.Next.Next;
            }
            if (t1 != null && t1.IsHiphen && t1.Next != null)
            {
                t1 = t1.Next;
            }
            bool   det  = false;
            double altf = f;

            if (((t1 is Pullenti.Ner.NumberToken) && t1.Previous != null && t1.Previous.IsHiphen) && (t1 as Pullenti.Ner.NumberToken).IntValue == 0 && t1.LengthChar == 2)
            {
                t1 = t1.Next;
            }
            if ((t1 != null && t1.Next != null && t1.IsChar('(')) && (((t1.Next is Pullenti.Ner.NumberToken) || t1.Next.IsValue("НОЛЬ", null))) && t1.Next.Next != null)
            {
                Pullenti.Ner.NumberToken nt1 = t1.Next as Pullenti.Ner.NumberToken;
                double val = (double)0;
                if (nt1 != null)
                {
                    val = nt1.RealValue;
                }
                if (Math.Floor(f) == Math.Floor(val))
                {
                    Pullenti.Ner.Token ttt = t1.Next.Next;
                    if (ttt.IsChar(')'))
                    {
                        t1  = ttt.Next;
                        det = true;
                        if ((t1 is Pullenti.Ner.NumberToken) && (t1 as Pullenti.Ner.NumberToken).IntValue != null && (t1 as Pullenti.Ner.NumberToken).IntValue.Value == 0)
                        {
                            t1 = t1.Next;
                        }
                    }
                    else if (((((ttt is Pullenti.Ner.NumberToken) && ((ttt as Pullenti.Ner.NumberToken).RealValue < 100) && ttt.Next != null) && ttt.Next.IsChar('/') && ttt.Next.Next != null) && ttt.Next.Next.GetSourceText() == "100" && ttt.Next.Next.Next != null) && ttt.Next.Next.Next.IsChar(')'))
                    {
                        int rest = GetDecimalRest100(f);
                        if ((ttt as Pullenti.Ner.NumberToken).IntValue != null && rest == (ttt as Pullenti.Ner.NumberToken).IntValue.Value)
                        {
                            t1  = ttt.Next.Next.Next.Next;
                            det = true;
                        }
                    }
                    else if ((ttt.IsValue("ЦЕЛЫХ", null) && (ttt.Next is Pullenti.Ner.NumberToken) && ttt.Next.Next != null) && ttt.Next.Next.Next != null && ttt.Next.Next.Next.IsChar(')'))
                    {
                        Pullenti.Ner.NumberToken num2 = ttt.Next as Pullenti.Ner.NumberToken;
                        altf = num2.RealValue;
                        if (ttt.Next.Next.IsValue("ДЕСЯТЫЙ", null))
                        {
                            altf /= 10;
                        }
                        else if (ttt.Next.Next.IsValue("СОТЫЙ", null))
                        {
                            altf /= 100;
                        }
                        else if (ttt.Next.Next.IsValue("ТЫСЯЧНЫЙ", null))
                        {
                            altf /= 1000;
                        }
                        else if (ttt.Next.Next.IsValue("ДЕСЯТИТЫСЯЧНЫЙ", null))
                        {
                            altf /= 10000;
                        }
                        else if (ttt.Next.Next.IsValue("СТОТЫСЯЧНЫЙ", null))
                        {
                            altf /= 100000;
                        }
                        else if (ttt.Next.Next.IsValue("МИЛЛИОННЫЙ", null))
                        {
                            altf /= 1000000;
                        }
                        if (altf < 1)
                        {
                            altf += val;
                            t1    = ttt.Next.Next.Next.Next;
                            det   = true;
                        }
                    }
                    else
                    {
                        Pullenti.Ner.Core.TerminToken toks1 = m_Postfixes.TryParse(ttt, Pullenti.Ner.Core.TerminParseAttr.No);
                        if (toks1 != null)
                        {
                            if (((Pullenti.Ner.Core.NumberExType)toks1.Termin.Tag) == Pullenti.Ner.Core.NumberExType.Money)
                            {
                                if (toks1.EndToken.Next != null && toks1.EndToken.Next.IsChar(')'))
                                {
                                    Pullenti.Ner.Core.NumberExToken res = new Pullenti.Ner.Core.NumberExToken(t, toks1.EndToken.Next, nt.Value, nt.Typ, Pullenti.Ner.Core.NumberExType.Money)
                                    {
                                        RealValue = f, AltRealValue = altf, Morph = toks1.BeginToken.Morph
                                    };
                                    return(_correctMoney(res, toks1.BeginToken));
                                }
                            }
                        }
                        Pullenti.Ner.Core.NumberExToken res2 = TryParseNumberWithPostfix(t1.Next);
                        if (res2 != null && res2.EndToken.Next != null && res2.EndToken.Next.IsChar(')'))
                        {
                            res2.BeginToken   = t;
                            res2.EndToken     = res2.EndToken.Next;
                            res2.AltRealValue = res2.RealValue;
                            res2.RealValue    = f;
                            _correctExtTypes(res2);
                            if (res2.WhitespacesAfterCount < 2)
                            {
                                Pullenti.Ner.Core.TerminToken toks2 = m_Postfixes.TryParse(res2.EndToken.Next, Pullenti.Ner.Core.TerminParseAttr.No);
                                if (toks2 != null)
                                {
                                    if (((Pullenti.Ner.Core.NumberExType)toks2.Termin.Tag) == Pullenti.Ner.Core.NumberExType.Money)
                                    {
                                        res2.EndToken = toks2.EndToken;
                                    }
                                }
                            }
                            return(res2);
                        }
                    }
                }
                else if (nt1 != null && nt1.Typ == Pullenti.Ner.NumberSpellingType.Words && nt.Typ == Pullenti.Ner.NumberSpellingType.Digit)
                {
                    altf = nt1.RealValue;
                    Pullenti.Ner.Token ttt = t1.Next.Next;
                    if (ttt.IsChar(')'))
                    {
                        t1  = ttt.Next;
                        det = true;
                    }
                    if (!det)
                    {
                        altf = f;
                    }
                }
            }
            if ((t1 != null && t1.IsChar('(') && t1.Next != null) && t1.Next.IsValue("СУММА", null))
            {
                Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(t1, Pullenti.Ner.Core.BracketParseAttr.No, 100);
                if (br != null)
                {
                    t1 = br.EndToken.Next;
                }
            }
            if (isDollar != null)
            {
                Pullenti.Ner.Token te = null;
                if (t1 != null)
                {
                    te = t1.Previous;
                }
                else
                {
                    for (t1 = t0; t1 != null; t1 = t1.Next)
                    {
                        if (t1.Next == null)
                        {
                            te = t1;
                        }
                    }
                }
                if (te == null)
                {
                    return(null);
                }
                if (te.IsHiphen && te.Next != null)
                {
                    if (te.Next.IsValue("МИЛЛИОННЫЙ", null))
                    {
                        f    *= 1000000;
                        altf *= 1000000;
                        te    = te.Next;
                    }
                    else if (te.Next.IsValue("МИЛЛИАРДНЫЙ", null))
                    {
                        f    *= 1000000000;
                        altf *= 1000000000;
                        te    = te.Next;
                    }
                }
                if (!te.IsWhitespaceAfter && (te.Next is Pullenti.Ner.TextToken))
                {
                    if (te.Next.IsValue("M", null))
                    {
                        f    *= 1000000;
                        altf *= 1000000;
                        te    = te.Next;
                    }
                    else if (te.Next.IsValue("BN", null))
                    {
                        f    *= 1000000000;
                        altf *= 1000000000;
                        te    = te.Next;
                    }
                }
                return(new Pullenti.Ner.Core.NumberExToken(t0, te, "", nt.Typ, Pullenti.Ner.Core.NumberExType.Money)
                {
                    RealValue = f, AltRealValue = altf, ExTypParam = isDollar
                });
            }
            if (t1 == null || ((t1.IsNewlineBefore && !det)))
            {
                return(null);
            }
            Pullenti.Ner.Core.TerminToken toks = m_Postfixes.TryParse(t1, Pullenti.Ner.Core.TerminParseAttr.No);
            if ((toks == null && det && (t1 is Pullenti.Ner.NumberToken)) && (t1 as Pullenti.Ner.NumberToken).Value == "0")
            {
                toks = m_Postfixes.TryParse(t1.Next, Pullenti.Ner.Core.TerminParseAttr.No);
            }
            if (toks == null && t1.IsChar('р'))
            {
                int cou = 10;
                for (Pullenti.Ner.Token ttt = t0.Previous; ttt != null && cou > 0; ttt = ttt.Previous, cou--)
                {
                    if (ttt.IsValue("СУММА", null) || ttt.IsValue("НАЛИЧНЫЙ", null) || ttt.IsValue("БАЛАНС", null))
                    {
                    }
                    else if (ttt.GetReferent() != null && ttt.GetReferent().TypeName == "MONEY")
                    {
                    }
                    else
                    {
                        continue;
                    }
                    toks = new Pullenti.Ner.Core.TerminToken(t1, t1)
                    {
                        Termin = m_Postfixes.FindTerminsByCanonicText("RUB")[0]
                    };
                    if (t1.Next != null && t1.Next.IsChar('.'))
                    {
                        toks.EndToken = t1.Next;
                    }
                    Pullenti.Ner.Core.NumberExType ty = (Pullenti.Ner.Core.NumberExType)toks.Termin.Tag;
                    return(new Pullenti.Ner.Core.NumberExToken(t, toks.EndToken, nt.Value, nt.Typ, ty)
                    {
                        RealValue = f, AltRealValue = altf, Morph = toks.BeginToken.Morph, ExTypParam = "RUB"
                    });
                }
            }
            if (toks != null)
            {
                t1 = toks.EndToken;
                if (!t1.IsChar('.') && t1.Next != null && t1.Next.IsChar('.'))
                {
                    if ((t1 is Pullenti.Ner.TextToken) && t1.IsValue(toks.Termin.Terms[0].CanonicalText, null))
                    {
                    }
                    else if (!t1.Chars.IsLetter)
                    {
                    }
                    else
                    {
                        t1 = t1.Next;
                    }
                }
                if (toks.Termin.CanonicText == "LTL")
                {
                    return(null);
                }
                if (toks.BeginToken == t1)
                {
                    if (t1.Morph.Class.IsPreposition || t1.Morph.Class.IsConjunction)
                    {
                        if (t1.IsWhitespaceBefore && t1.IsWhitespaceAfter)
                        {
                            return(null);
                        }
                    }
                }
                Pullenti.Ner.Core.NumberExType  ty  = (Pullenti.Ner.Core.NumberExType)toks.Termin.Tag;
                Pullenti.Ner.Core.NumberExToken res = new Pullenti.Ner.Core.NumberExToken(t, t1, nt.Value, nt.Typ, ty)
                {
                    RealValue = f, AltRealValue = altf, Morph = toks.BeginToken.Morph
                };
                if (ty != Pullenti.Ner.Core.NumberExType.Money)
                {
                    _correctExtTypes(res);
                    return(res);
                }
                return(_correctMoney(res, toks.BeginToken));
            }
            Pullenti.Ner.Core.NumberExToken pfx = _attachSpecPostfix(t1);
            if (pfx != null)
            {
                pfx.BeginToken   = t;
                pfx.Value        = nt.Value;
                pfx.Typ          = nt.Typ;
                pfx.RealValue    = f;
                pfx.AltRealValue = altf;
                return(pfx);
            }
            if (t1.Next != null && ((t1.Morph.Class.IsPreposition || t1.Morph.Class.IsConjunction)))
            {
                if (t1.IsValue("НА", null))
                {
                }
                else
                {
                    Pullenti.Ner.Core.NumberExToken nn = TryParseNumberWithPostfix(t1.Next);
                    if (nn != null)
                    {
                        return new Pullenti.Ner.Core.NumberExToken(t, t, nt.Value, nt.Typ, nn.ExTyp)
                               {
                                   RealValue = f, AltRealValue = altf, ExTyp2 = nn.ExTyp2, ExTypParam = nn.ExTypParam
                               }
                    }
                    ;
                }
            }
            if (!t1.IsWhitespaceAfter && (t1.Next is Pullenti.Ner.NumberToken) && (t1 is Pullenti.Ner.TextToken))
            {
                string term = (t1 as Pullenti.Ner.TextToken).Term;
                Pullenti.Ner.Core.NumberExType ty = Pullenti.Ner.Core.NumberExType.Undefined;
                if (term == "СМХ" || term == "CMX")
                {
                    ty = Pullenti.Ner.Core.NumberExType.Santimeter;
                }
                else if (term == "MX" || term == "МХ")
                {
                    ty = Pullenti.Ner.Core.NumberExType.Meter;
                }
                else if (term == "MMX" || term == "ММХ")
                {
                    ty = Pullenti.Ner.Core.NumberExType.Millimeter;
                }
                if (ty != Pullenti.Ner.Core.NumberExType.Undefined)
                {
                    return new Pullenti.Ner.Core.NumberExToken(t, t1, nt.Value, nt.Typ, ty)
                           {
                               RealValue = f, AltRealValue = altf, MultAfter = true
                           }
                }
                ;
            }
            return(null);
        }
Exemplo n.º 7
0
 static void _parseNumber(Pullenti.Ner.Token t, InstrToken1 res, InstrToken1 prev)
 {
     if (((t is Pullenti.Ner.NumberToken) && (t as Pullenti.Ner.NumberToken).IntValue != null && (t as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Digit) && ((t as Pullenti.Ner.NumberToken).IntValue.Value < 3000))
     {
         if (res.Numbers.Count >= 4)
         {
         }
         if (t.Morph.Class.IsAdjective && res.TypContainerRank == 0)
         {
             return;
         }
         Pullenti.Ner.Core.NumberExToken nwp = Pullenti.Ner.Core.NumberHelper.TryParseNumberWithPostfix(t);
         if (nwp != null)
         {
             if (nwp.EndToken.IsWhitespaceBefore)
             {
             }
             else
             {
                 return;
             }
         }
         if ((t.Next != null && (t.WhitespacesAfterCount < 3) && t.Next.Chars.IsLetter) && t.Next.Chars.IsAllLower)
         {
             if (!t.IsWhitespaceAfter && t.Next.LengthChar == 1)
             {
             }
             else if (res.Numbers.Count == 0)
             {
                 res.NumTyp = NumberTypes.Digit;
                 res.Numbers.Add((t as Pullenti.Ner.NumberToken).Value.ToString());
                 res.NumBeginToken = (res.NumEndToken = (res.EndToken = t));
                 return;
             }
             else
             {
                 return;
             }
         }
         if (res.NumTyp == NumberTypes.Undefined)
         {
             res.NumTyp = NumberTypes.Digit;
         }
         else
         {
             res.NumTyp = NumberTypes.Combo;
         }
         if (res.Numbers.Count > 0 && t.IsWhitespaceBefore)
         {
             return;
         }
         if (res.Numbers.Count == 0)
         {
             res.NumBeginToken = t;
         }
         if ((t.Next != null && t.Next.IsHiphen && (t.Next.Next is Pullenti.Ner.NumberToken)) && (t.Next.Next as Pullenti.Ner.NumberToken).IntValue != null && (t.Next.Next as Pullenti.Ner.NumberToken).IntValue.Value > (t as Pullenti.Ner.NumberToken).IntValue.Value)
         {
             res.MinNumber = (t as Pullenti.Ner.NumberToken).Value.ToString();
             t             = t.Next.Next;
         }
         else if (((t.Next != null && t.Next.IsCharOf(")") && t.Next.Next != null) && t.Next.Next.IsHiphen && (t.Next.Next.Next is Pullenti.Ner.NumberToken)) && (t.Next.Next.Next as Pullenti.Ner.NumberToken).IntValue != null && (t.Next.Next.Next as Pullenti.Ner.NumberToken).IntValue.Value > (t as Pullenti.Ner.NumberToken).IntValue.Value)
         {
             res.MinNumber = (t as Pullenti.Ner.NumberToken).Value.ToString();
             t             = t.Next.Next.Next;
         }
         res.Numbers.Add((t as Pullenti.Ner.NumberToken).Value.ToString());
         res.EndToken  = (res.NumEndToken = t);
         res.NumSuffix = null;
         for (Pullenti.Ner.Token ttt = t.Next; ttt != null && (res.Numbers.Count < 4); ttt = ttt.Next)
         {
             bool ok1 = false;
             bool ok2 = false;
             if ((ttt.IsCharOf("._") && !ttt.IsWhitespaceAfter && (ttt.Next is Pullenti.Ner.NumberToken)) && (((ttt.Next as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Digit || (((ttt.Next as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Words) && ttt.Next.Chars.IsLatinLetter && !ttt.IsWhitespaceAfter))))
             {
                 ok1 = true;
             }
             else if ((ttt.IsCharOf("(<") && (ttt.Next is Pullenti.Ner.NumberToken) && ttt.Next.Next != null) && ttt.Next.Next.IsCharOf(")>"))
             {
                 ok2 = true;
             }
             if (ok1 || ok2)
             {
                 ttt = ttt.Next;
                 res.Numbers.Add((ttt as Pullenti.Ner.NumberToken).Value.ToString());
                 res.NumTyp = (res.Numbers.Count == 2 ? NumberTypes.TwoDigits : (res.Numbers.Count == 3 ? NumberTypes.ThreeDigits : NumberTypes.FourDigits));
                 if ((ttt.Next != null && ttt.Next.IsCharOf(")>") && ttt.Next.Next != null) && ttt.Next.Next.IsChar('.'))
                 {
                     ttt = ttt.Next;
                 }
                 else if (ok2)
                 {
                     ttt = ttt.Next;
                 }
                 t = (res.EndToken = (res.NumEndToken = ttt));
                 continue;
             }
             if (((ttt is Pullenti.Ner.TextToken) && ttt.LengthChar == 1 && ttt.Chars.IsLetter) && !ttt.IsWhitespaceBefore && res.Numbers.Count == 1)
             {
                 res.Numbers.Add((ttt as Pullenti.Ner.TextToken).Term);
                 res.NumTyp = NumberTypes.Combo;
                 t          = (res.EndToken = (res.NumEndToken = ttt));
                 continue;
             }
             break;
         }
         if (t.Next != null && t.Next.IsCharOf(")."))
         {
             res.NumSuffix = t.Next.GetSourceText();
             t             = (res.EndToken = (res.NumEndToken = t.Next));
         }
         return;
     }
     if (((t is Pullenti.Ner.NumberToken) && (t as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Words && res.TypContainerRank > 0) && res.Numbers.Count == 0)
     {
         res.Numbers.Add((t as Pullenti.Ner.NumberToken).Value.ToString());
         res.NumTyp        = NumberTypes.Digit;
         res.NumBeginToken = t;
         if (t.Next != null && t.Next.IsChar('.'))
         {
             t             = t.Next;
             res.NumSuffix = ".";
         }
         res.EndToken = (res.NumEndToken = t);
         return;
     }
     Pullenti.Ner.NumberToken nt = Pullenti.Ner.Core.NumberHelper.TryParseRoman(t);
     if ((nt != null && nt.Value == "10" && t.Next != null) && t.Next.IsChar(')'))
     {
         nt = null;
     }
     if (nt != null && nt.Value == "100")
     {
         nt = null;
     }
     if (nt != null && nt.Typ == Pullenti.Ner.NumberSpellingType.Roman)
     {
         if (res.NumTyp == NumberTypes.Undefined)
         {
             res.NumTyp = NumberTypes.Roman;
         }
         else
         {
             res.NumTyp = NumberTypes.Combo;
         }
         if (res.Numbers.Count > 0 && t.IsWhitespaceBefore)
         {
             return;
         }
         if (res.Numbers.Count == 0)
         {
             res.NumBeginToken = t;
         }
         res.Numbers.Add(nt.Value.ToString());
         t = (res.EndToken = (res.NumEndToken = nt.EndToken));
         if (res.NumTyp == NumberTypes.Roman && ((res.Typ == InstrToken1.Types.Chapter || res.Typ == InstrToken1.Types.Section || res.Typ == InstrToken1.Types.Line)))
         {
             if ((t.Next != null && t.Next.IsCharOf("._<") && (t.Next.Next is Pullenti.Ner.NumberToken)) && (t.Next.Next as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Digit)
             {
                 t = t.Next.Next;
                 res.Numbers.Add((t as Pullenti.Ner.NumberToken).Value.ToString());
                 res.NumTyp = NumberTypes.TwoDigits;
                 if (t.Next != null && t.Next.IsChar('>'))
                 {
                     t = t.Next;
                 }
                 res.EndToken = (res.NumEndToken = t);
                 if ((t.Next != null && t.Next.IsCharOf("._<") && (t.Next.Next is Pullenti.Ner.NumberToken)) && (t.Next.Next as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Digit)
                 {
                     t = t.Next.Next;
                     res.Numbers.Add((t as Pullenti.Ner.NumberToken).Value.ToString());
                     res.NumTyp = NumberTypes.ThreeDigits;
                     if (t.Next != null && t.Next.IsChar('>'))
                     {
                         t = t.Next;
                     }
                     res.EndToken = (res.NumEndToken = t);
                 }
             }
         }
         if (t.Next != null && t.Next.IsCharOf(")."))
         {
             res.NumSuffix = t.Next.GetSourceText();
             t             = (res.EndToken = (res.NumEndToken = t.Next));
         }
         return;
     }
     if (((t is Pullenti.Ner.TextToken) && t.LengthChar == 1 && t.Chars.IsLetter) && t == res.BeginToken)
     {
         if ((!t.IsWhitespaceAfter && (t.Next is Pullenti.Ner.NumberToken) && t.Next.Next != null) && t.Next.Next.IsChar('.'))
         {
             res.NumBeginToken = t;
             res.NumTyp        = NumberTypes.Digit;
             res.Numbers.Add((t.Next as Pullenti.Ner.NumberToken).Value.ToString());
             res.NumSuffix = (t as Pullenti.Ner.TextToken).Term + ".";
             t             = (res.EndToken = (res.NumEndToken = t.Next.Next));
             return;
         }
         if (t.Next != null && t.Next.IsCharOf(".)"))
         {
             if (((t.Next.IsChar('.') && (t.Next.Next is Pullenti.Ner.NumberToken) && t.Next.Next.Next != null) && t.Next.Next.Next.IsChar(')') && !t.Next.IsWhitespaceAfter) && !t.Next.Next.IsWhitespaceAfter)
             {
                 res.NumTyp = NumberTypes.TwoDigits;
                 res.Numbers.Add((t as Pullenti.Ner.TextToken).Term);
                 res.Numbers.Add((t.Next.Next as Pullenti.Ner.NumberToken).Value.ToString());
                 res.NumSuffix     = ")";
                 res.NumBeginToken = t;
                 t = (res.EndToken = (res.NumEndToken = t.Next.Next.Next));
                 return;
             }
             if (t.Next.IsChar('.') && ((t.Chars.IsAllUpper || (t.Next.Next is Pullenti.Ner.NumberToken))))
             {
             }
             else
             {
                 InstrToken1 tmp1 = new InstrToken1(t, t.Next);
                 tmp1.Numbers.Add((t as Pullenti.Ner.TextToken).Term);
                 if (tmp1.LastNumber > 1 && t.Next.IsCharOf(".") && ((prev == null || (prev.LastNumber + 1) != tmp1.LastNumber)))
                 {
                 }
                 else
                 {
                     if (res.Numbers.Count == 0)
                     {
                         res.NumBeginToken = t;
                     }
                     res.NumTyp = NumberTypes.Letter;
                     res.Numbers.Add((t as Pullenti.Ner.TextToken).Term);
                     res.NumBeginToken = t;
                     t             = (res.EndToken = (res.NumEndToken = t.Next));
                     res.NumSuffix = t.GetSourceText();
                     return;
                 }
             }
         }
     }
 }