public static List <UnitToken> TryParseList(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, bool parseUnknownUnits = false) { UnitToken ut = TryParse(t, addUnits, null, parseUnknownUnits); if (ut == null) { return(null); } List <UnitToken> res = new List <UnitToken>(); res.Add(ut); for (Pullenti.Ner.Token tt = ut.EndToken.Next; tt != null; tt = tt.Next) { ut = TryParse(tt, addUnits, res[res.Count - 1], true); if (ut == null) { break; } if (ut.Unit != null && ut.Unit.Kind != Pullenti.Ner.Measure.MeasureKind.Undefined) { if (res[res.Count - 1].Unit != null && res[res.Count - 1].Unit.Kind == ut.Unit.Kind) { break; } } res.Add(ut); tt = ut.EndToken; if (res.Count > 2) { break; } } for (int i = 0; i < res.Count; i++) { if (res[i].Unit != null && res[i].Unit.BaseUnit != null && res[i].Unit.MultUnit != null) { UnitToken ut2 = new UnitToken(res[i].BeginToken, res[i].EndToken); ut2.Unit = res[i].Unit.MultUnit; res.Insert(i + 1, ut2); res[i].Unit = res[i].Unit.BaseUnit; } } if (res.Count > 1) { foreach (UnitToken r in res) { r.IsDoubt = false; } } return(res); }
public static Pullenti.Ner.Measure.MeasureKind CalcKind(List <UnitToken> units) { if (units == null || units.Count == 0) { return(Pullenti.Ner.Measure.MeasureKind.Undefined); } UnitToken u0 = units[0]; if (u0.Unit == null) { return(Pullenti.Ner.Measure.MeasureKind.Undefined); } if (units.Count == 1) { if (u0.Pow == 1) { return(u0.Unit.Kind); } if (u0.Pow == 2) { if (u0.Unit.Kind == Pullenti.Ner.Measure.MeasureKind.Length) { return(Pullenti.Ner.Measure.MeasureKind.Area); } } if (u0.Pow == 3) { if (u0.Unit.Kind == Pullenti.Ner.Measure.MeasureKind.Length) { return(Pullenti.Ner.Measure.MeasureKind.Volume); } } return(Pullenti.Ner.Measure.MeasureKind.Undefined); } if (units.Count == 2) { if (units[1].Unit == null) { return(Pullenti.Ner.Measure.MeasureKind.Undefined); } if ((u0.Unit.Kind == Pullenti.Ner.Measure.MeasureKind.Length && u0.Pow == 1 && units[1].Unit.Kind == Pullenti.Ner.Measure.MeasureKind.Time) && units[1].Pow == -1) { return(Pullenti.Ner.Measure.MeasureKind.Speed); } } return(Pullenti.Ner.Measure.MeasureKind.Undefined); }
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; } } } }
public static UnitToken TryParse(Pullenti.Ner.Token t, Pullenti.Ner.Core.TerminCollection addUnits, UnitToken prev, bool parseUnknownUnits = false) { if (t == null) { return(null); } Pullenti.Ner.Token t0 = t; int pow = 1; bool isNeg = false; if ((t.IsCharOf("\\/") || t.IsValue("НА", null) || t.IsValue("OF", null)) || t.IsValue("PER", null)) { isNeg = true; t = t.Next; } else if (t.IsValue("В", null) && prev != null) { isNeg = true; t = t.Next; } else if (MeasureHelper.IsMultChar(t)) { t = t.Next; } Pullenti.Ner.TextToken tt = t as Pullenti.Ner.TextToken; if (tt == null) { return(null); } if (tt.Term == "КВ" || tt.Term == "КВАДР" || tt.IsValue("КВАДРАТНЫЙ", null)) { pow = 2; tt = tt.Next as Pullenti.Ner.TextToken; if (tt != null && tt.IsChar('.')) { tt = tt.Next as Pullenti.Ner.TextToken; } if (tt == null) { return(null); } } else if (tt.Term == "КУБ" || tt.Term == "КУБИЧ" || tt.IsValue("КУБИЧЕСКИЙ", null)) { pow = 3; tt = tt.Next as Pullenti.Ner.TextToken; if (tt != null && tt.IsChar('.')) { tt = tt.Next as Pullenti.Ner.TextToken; } if (tt == null) { return(null); } } else if (tt.Term == "µ") { UnitToken res = TryParse(tt.Next, addUnits, prev, false); if (res != null) { foreach (Unit u in UnitsHelper.Units) { if (u.Factor == UnitsFactors.Micro && string.Compare("мк" + u.NameCyr, res.Unit.NameCyr, true) == 0) { res.Unit = u; res.BeginToken = tt; res.Pow = pow; if (isNeg) { res.Pow = -pow; } return(res); } } } } List <Pullenti.Ner.Core.TerminToken> toks = UnitsHelper.Termins.TryParseAll(tt, Pullenti.Ner.Core.TerminParseAttr.No); if (toks != null) { if ((prev != null && tt == t0 && toks.Count == 1) && t.IsWhitespaceBefore) { return(null); } if (toks[0].BeginToken == toks[0].EndToken && tt.Morph.Class.IsPreposition && (tt.WhitespacesAfterCount < 3)) { if (Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.ParsePreposition, 0, null) != null) { return(null); } if (tt.Next is Pullenti.Ner.NumberToken) { if ((tt.Next as Pullenti.Ner.NumberToken).Typ != Pullenti.Ner.NumberSpellingType.Digit) { return(null); } } UnitToken nex = TryParse(tt.Next, addUnits, null, false); if (nex != null) { return(null); } } if (toks[0].BeginToken == toks[0].EndToken && ((toks[0].BeginToken.IsValue("М", null) || toks[0].BeginToken.IsValue("M", null))) && toks[0].BeginToken.Chars.IsAllLower) { if (prev != null && prev.Unit != null && prev.Unit.Kind == Pullenti.Ner.Measure.MeasureKind.Length) { UnitToken res = new UnitToken(t0, toks[0].EndToken) { Unit = UnitsHelper.uMinute }; res.Pow = pow; if (isNeg) { res.Pow = -pow; } return(res); } } List <UnitToken> uts = new List <UnitToken>(); foreach (Pullenti.Ner.Core.TerminToken tok in toks) { UnitToken res = new UnitToken(t0, tok.EndToken) { Unit = tok.Termin.Tag as Unit }; res.Pow = pow; if (isNeg) { res.Pow = -pow; } if (res.Unit.BaseMultiplier == 1000000 && (t0 is Pullenti.Ner.TextToken) && char.IsLower((t0 as Pullenti.Ner.TextToken).GetSourceText()[0])) { foreach (Unit u in UnitsHelper.Units) { if (u.Factor == UnitsFactors.Milli && string.Compare(u.NameCyr, res.Unit.NameCyr, true) == 0) { res.Unit = u; break; } } } res._correct(); res._checkDoubt(); uts.Add(res); } int max = 0; UnitToken best = null; foreach (UnitToken ut in uts) { if (ut.Keyword != null) { if (ut.Keyword.BeginChar >= max) { max = ut.Keyword.BeginChar; best = ut; } } } if (best != null) { return(best); } foreach (UnitToken ut in uts) { if (!ut.IsDoubt) { return(ut); } } return(uts[0]); } Pullenti.Ner.Token t1 = null; if (t.IsCharOf("º°")) { t1 = t; } else if ((t.IsChar('<') && t.Next != null && t.Next.Next != null) && t.Next.Next.IsChar('>') && ((t.Next.IsValue("О", null) || t.Next.IsValue("O", null) || (((t.Next is Pullenti.Ner.NumberToken) && (t.Next as Pullenti.Ner.NumberToken).Value == "0"))))) { t1 = t.Next.Next; } if (t1 != null) { UnitToken res = new UnitToken(t0, t1) { Unit = UnitsHelper.uGradus }; res._checkDoubt(); t = t1.Next; if (t != null && t.IsComma) { t = t.Next; } if (t != null && t.IsValue("ПО", null)) { t = t.Next; } if (t is Pullenti.Ner.TextToken) { string vv = (t as Pullenti.Ner.TextToken).Term; if (vv == "C" || vv == "С" || vv.StartsWith("ЦЕЛЬС")) { res.Unit = UnitsHelper.uGradusC; res.IsDoubt = false; res.EndToken = t; } if (vv == "F" || vv.StartsWith("ФАР")) { res.Unit = UnitsHelper.uGradusF; res.IsDoubt = false; res.EndToken = t; } } return(res); } if ((t is Pullenti.Ner.TextToken) && ((t.IsValue("ОС", null) || t.IsValue("OC", null)))) { string str = t.GetSourceText(); if (str == "оС" || str == "oC") { UnitToken res = new UnitToken(t, t) { Unit = UnitsHelper.uGradusC, IsDoubt = false }; return(res); } } if (t.IsChar('%')) { Pullenti.Ner.Token tt1 = t.Next; if (tt1 != null && tt1.IsChar('(')) { tt1 = tt1.Next; } if ((tt1 is Pullenti.Ner.TextToken) && (tt1 as Pullenti.Ner.TextToken).Term.StartsWith("ОБ")) { UnitToken re = new UnitToken(t, tt1) { Unit = UnitsHelper.uAlco }; if (re.EndToken.Next != null && re.EndToken.Next.IsChar('.')) { re.EndToken = re.EndToken.Next; } if (re.EndToken.Next != null && re.EndToken.Next.IsChar(')') && t.Next.IsChar('(')) { re.EndToken = re.EndToken.Next; } return(re); } return(new UnitToken(t, t) { Unit = UnitsHelper.uPercent }); } if (addUnits != null) { Pullenti.Ner.Core.TerminToken tok = addUnits.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No); if (tok != null) { UnitToken res = new UnitToken(t0, tok.EndToken) { ExtOnto = tok.Termin.Tag as Pullenti.Ner.Measure.UnitReferent }; if (tok.EndToken.Next != null && tok.EndToken.Next.IsChar('.')) { tok.EndToken = tok.EndToken.Next; } res.Pow = pow; if (isNeg) { res.Pow = -pow; } res._correct(); return(res); } } if (!parseUnknownUnits) { return(null); } if ((t.WhitespacesBeforeCount > 2 || !t.Chars.IsLetter || t.LengthChar > 5) || !(t is Pullenti.Ner.TextToken)) { return(null); } if (Pullenti.Ner.Core.MiscHelper.CanBeStartOfSentence(t)) { return(null); } t1 = t; if (t.Next != null && t.Next.IsChar('.')) { t1 = t; } bool ok = false; if (t1.Next == null || t1.WhitespacesAfterCount > 2) { ok = true; } else if (t1.Next.IsComma || t1.Next.IsCharOf("\\/") || t1.Next.IsTableControlChar) { ok = true; } else if (MeasureHelper.IsMultChar(t1.Next)) { ok = true; } if (!ok) { return(null); } Pullenti.Morph.MorphClass mc = t.GetMorphClassInDictionary(); if (mc.IsUndefined) { } else if (t.LengthChar > 7) { return(null); } UnitToken res1 = new UnitToken(t0, t1) { Pow = pow, IsDoubt = true }; res1.UnknownName = (t as Pullenti.Ner.TextToken).GetSourceText(); res1._correct(); return(res1); }
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); }
public List <Pullenti.Ner.ReferentToken> CreateRefenetsTokensWithRegister(Pullenti.Ner.Core.AnalyzerData ad, string name, bool regist = true) { if (name == "T =") { name = "ТЕМПЕРАТУРА"; } List <Pullenti.Ner.ReferentToken> res = new List <Pullenti.Ner.ReferentToken>(); foreach (UnitToken u in Units) { Pullenti.Ner.ReferentToken rt = new Pullenti.Ner.ReferentToken(u.CreateReferentWithRegister(ad), u.BeginToken, u.EndToken); res.Add(rt); } Pullenti.Ner.Measure.MeasureReferent mr = new Pullenti.Ner.Measure.MeasureReferent(); string templ = "1"; if (SingleVal != null) { mr.AddValue(SingleVal.Value); if (PlusMinus != null) { templ = string.Format("[1 ±2{0}]", (PlusMinusPercent ? "%" : "")); mr.AddValue(PlusMinus.Value); } else if (About) { templ = "~1"; } } else { if (Not && ((FromVal == null || ToVal == null))) { bool b = FromInclude; FromInclude = ToInclude; ToInclude = b; double?v = FromVal; FromVal = ToVal; ToVal = v; } int num = 1; if (FromVal != null) { mr.AddValue(FromVal.Value); templ = (FromInclude ? "[1" : "]1"); num++; } else { templ = "]"; } if (ToVal != null) { mr.AddValue(ToVal.Value); templ = string.Format("{0} .. {1}{2}", templ, num, (ToInclude ? ']' : '[')); } else { templ += " .. ["; } } mr.Template = templ; foreach (Pullenti.Ner.ReferentToken rt in res) { mr.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_UNIT, rt.Referent, false, 0); } if (name != null) { mr.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_NAME, name, false, 0); } if (DivNum != null) { List <Pullenti.Ner.ReferentToken> dn = DivNum.CreateRefenetsTokensWithRegister(ad, null, true); res.AddRange(dn); mr.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_REF, dn[dn.Count - 1].Referent, false, 0); } Pullenti.Ner.Measure.MeasureKind ki = UnitToken.CalcKind(Units); if (ki != Pullenti.Ner.Measure.MeasureKind.Undefined) { mr.Kind = ki; } if (regist && ad != null) { mr = ad.RegisterReferent(mr) as Pullenti.Ner.Measure.MeasureReferent; } res.Add(new Pullenti.Ner.ReferentToken(mr, BeginToken, EndToken)); return(res); }
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); }