static Pullenti.Ner.Measure.UnitReferent _createReferent(Unit u) { Pullenti.Ner.Measure.UnitReferent ur = new Pullenti.Ner.Measure.UnitReferent(); ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_NAME, u.NameCyr, false, 0); ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_NAME, u.NameLat, false, 0); ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_FULLNAME, u.FullnameCyr, false, 0); ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_FULLNAME, u.FullnameLat, false, 0); ur.Tag = u; ur.m_Unit = u; return(ur); }
public Pullenti.Ner.Measure.UnitReferent CreateReferentWithRegister(Pullenti.Ner.Core.AnalyzerData ad) { Pullenti.Ner.Measure.UnitReferent ur = ExtOnto; if (Unit != null) { ur = _createReferent(Unit); } else if (UnknownName != null) { ur = new Pullenti.Ner.Measure.UnitReferent(); ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_NAME, UnknownName, false, 0); ur.IsUnknown = true; } if (Pow != 1) { ur.AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_POW, Pow.ToString(), false, 0); } List <Pullenti.Ner.Measure.UnitReferent> owns = new List <Pullenti.Ner.Measure.UnitReferent>(); owns.Add(ur); if (Unit != null) { for (Unit uu = Unit.BaseUnit; uu != null; uu = uu.BaseUnit) { Pullenti.Ner.Measure.UnitReferent ur0 = _createReferent(uu); owns.Add(ur0); } } for (int i = owns.Count - 1; i >= 0; i--) { if (ad != null) { owns[i] = ad.RegisterReferent(owns[i]) as Pullenti.Ner.Measure.UnitReferent; } if (i > 0) { owns[i - 1].AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_BASEUNIT, owns[i], false, 0); if ((owns[i - 1].Tag as Unit).BaseMultiplier != 0) { owns[i - 1].AddSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_BASEFACTOR, Pullenti.Ner.Core.NumberHelper.DoubleToString((owns[i - 1].Tag as Unit).BaseMultiplier), false, 0); } } } return(owns[0]); }
void _checkDoubt() { IsDoubt = false; if (Pow != 1) { return; } if (BeginToken.LengthChar < 3) { IsDoubt = true; if ((BeginToken.Chars.IsCapitalUpper || BeginToken.Chars.IsAllUpper || BeginToken.Chars.IsLastLower) || BeginToken.Chars.IsAllLower) { } else if (Unit.Psevdo.Count > 0) { } else { IsDoubt = false; } } int cou = 0; for (Pullenti.Ner.Token t = BeginToken.Previous; t != null && (cou < 30); t = t.Previous, cou++) { Pullenti.Ner.Measure.MeasureReferent mr = t.GetReferent() as Pullenti.Ner.Measure.MeasureReferent; if (mr != null) { foreach (Pullenti.Ner.Slot s in mr.Slots) { if (s.Value is Pullenti.Ner.Measure.UnitReferent) { Pullenti.Ner.Measure.UnitReferent ur = s.Value as Pullenti.Ner.Measure.UnitReferent; for (Unit u = Unit; u != null; u = u.BaseUnit) { if (ur.FindSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_NAME, u.NameCyr, true) != null) { IsDoubt = false; } else if (Unit.Psevdo.Count > 0) { foreach (Unit uu in Unit.Psevdo) { if (ur.FindSlot(Pullenti.Ner.Measure.UnitReferent.ATTR_NAME, uu.NameCyr, true) != null) { Unit = uu; IsDoubt = false; return; } } } } } } } if (!(t is Pullenti.Ner.TextToken) || (t.LengthChar < 3)) { continue; } for (Unit u = Unit; u != null; u = u.BaseUnit) { foreach (string k in u.Keywords) { if (t.IsValue(k, null)) { Keyword = t; IsDoubt = false; return; } } foreach (Unit uu in u.Psevdo) { foreach (string k in uu.Keywords) { if (t.IsValue(k, null)) { Unit = uu; Keyword = t; IsDoubt = false; return; } } } } } }
public List <Pullenti.Ner.ReferentToken> CreateRefenetsTokensWithRegister(Pullenti.Ner.Core.AnalyzerData ad, bool register = true) { if (Internals.Count == 0 && !Reliable) { if (Nums.Units.Count == 1 && Nums.Units[0].IsDoubt) { if (Nums.Units[0].UnknownName != null) { } else if (Nums.IsNewlineBefore) { } else if (Nums.Units[0].BeginToken.LengthChar > 1 && Nums.Units[0].BeginToken.GetMorphClassInDictionary().IsUndefined) { } else if (Nums.FromVal == null || Nums.ToVal == null) { return(null); } } } List <Pullenti.Ner.ReferentToken> res = new List <Pullenti.Ner.ReferentToken>(); if (((Nums == null || Nums.PlusMinusPercent)) && Internals.Count > 0) { List <Pullenti.Ner.ReferentToken> liEx = null; if (InternalEx != null) { liEx = InternalEx.CreateRefenetsTokensWithRegister(ad, true); if (liEx != null) { res.AddRange(liEx); } } Pullenti.Ner.Measure.MeasureReferent mr = new Pullenti.Ner.Measure.MeasureReferent(); string templ0 = "1"; string templ = null; if (Name != null) { mr.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_NAME, Name, false, 0); } List <Pullenti.Ner.Measure.MeasureReferent> ints = new List <Pullenti.Ner.Measure.MeasureReferent>(); for (int k = 0; k < Internals.Count; k++) { MeasureToken ii = Internals[k]; ii.Reliable = true; List <Pullenti.Ner.ReferentToken> li = ii.CreateRefenetsTokensWithRegister(ad, false); if (li == null) { continue; } res.AddRange(li); Pullenti.Ner.Measure.MeasureReferent mr0 = res[res.Count - 1].Referent as Pullenti.Ner.Measure.MeasureReferent; if (liEx != null) { mr0.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_REF, liEx[liEx.Count - 1], false, 0); } if (k == 0 && !IsEmpty) { templ0 = mr0.Template; mr0.Template = "1"; } if (ad != null) { mr0 = ad.RegisterReferent(mr0) as Pullenti.Ner.Measure.MeasureReferent; } mr.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_VALUE, mr0, false, 0); ints.Add(mr0); if (templ == null) { templ = "1"; } else { int nu = mr.GetStringValues(Pullenti.Ner.Measure.MeasureReferent.ATTR_VALUE).Count; templ = string.Format("{0}{1}{2}", templ, (IsSet ? ", " : " × "), nu); } } if (IsSet) { templ = "{" + templ + "}"; } if (templ0 != "1") { templ = templ0.Replace("1", templ); } if (Nums != null && Nums.PlusMinusPercent && Nums.SingleVal != null) { templ = string.Format("[{0} ±{1}%]", templ, Internals.Count + 1); mr.AddValue(Nums.SingleVal.Value); } mr.Template = templ; int i; bool hasLength = false; Pullenti.Ner.Measure.UnitReferent uref = null; for (i = 0; i < ints.Count; i++) { if (ints[i].Kind == Pullenti.Ner.Measure.MeasureKind.Length) { hasLength = true; uref = ints[i].GetSlotValue(Pullenti.Ner.Measure.MeasureReferent.ATTR_UNIT) as Pullenti.Ner.Measure.UnitReferent; } else if (ints[i].Units.Count > 0) { break; } } if (ints.Count > 1 && hasLength && uref != null) { foreach (Pullenti.Ner.Measure.MeasureReferent ii in ints) { if (ii.FindSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_UNIT, null, true) == null) { ii.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_UNIT, uref, false, 0); ii.Kind = Pullenti.Ner.Measure.MeasureKind.Length; } } } if (ints.Count == 3) { if (ints[0].Kind == Pullenti.Ner.Measure.MeasureKind.Length && ints[1].Kind == Pullenti.Ner.Measure.MeasureKind.Length && ints[2].Kind == Pullenti.Ner.Measure.MeasureKind.Length) { mr.Kind = Pullenti.Ner.Measure.MeasureKind.Volume; } else if (ints[0].Units.Count == 0 && ints[1].Units.Count == 0 && ints[2].Units.Count == 0) { string nam = mr.GetStringValue(Pullenti.Ner.Measure.MeasureReferent.ATTR_NAME); if (nam != null) { if (nam.Contains("РАЗМЕР") || nam.Contains("ГАБАРИТ")) { mr.Kind = Pullenti.Ner.Measure.MeasureKind.Volume; } } } } if (ints.Count == 2) { if (ints[0].Kind == Pullenti.Ner.Measure.MeasureKind.Length && ints[1].Kind == Pullenti.Ner.Measure.MeasureKind.Length) { mr.Kind = Pullenti.Ner.Measure.MeasureKind.Area; } } if (!IsEmpty) { if (ad != null) { mr = ad.RegisterReferent(mr) as Pullenti.Ner.Measure.MeasureReferent; } res.Add(new Pullenti.Ner.ReferentToken(mr, BeginToken, EndToken)); } return(res); } List <Pullenti.Ner.ReferentToken> re2 = Nums.CreateRefenetsTokensWithRegister(ad, Name, register); foreach (MeasureToken ii in Internals) { List <Pullenti.Ner.ReferentToken> li = ii.CreateRefenetsTokensWithRegister(ad, true); if (li == null) { continue; } res.AddRange(li); re2[re2.Count - 1].Referent.AddSlot(Pullenti.Ner.Measure.MeasureReferent.ATTR_REF, res[res.Count - 1].Referent, false, 0); } re2[re2.Count - 1].BeginToken = BeginToken; re2[re2.Count - 1].EndToken = EndToken; res.AddRange(re2); return(res); }