static bool _checkRoundDep(GeoReferent d) { if (d == null) { return(true); } GeoReferent d0 = d; List <GeoReferent> li = new List <GeoReferent>(); for (d = d.Higher; d != null; d = d.Higher) { if (d == d0) { return(true); } if (li.Contains(d)) { return(true); } li.Add(d); } return(false); }
public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ) { GeoReferent geo = obj as GeoReferent; if (geo == null) { return(false); } if (geo.Alpha2 != null && geo.Alpha2 == Alpha2) { return(true); } if (IsCity != geo.IsCity) { return(false); } if (IsUnion != geo.IsUnion) { return(false); } if (IsUnion) { foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_REF) { if (obj.FindSlot(ATTR_REF, s.Value, true) == null) { return(false); } } } foreach (Pullenti.Ner.Slot s in obj.Slots) { if (s.TypeName == ATTR_REF) { if (this.FindSlot(ATTR_REF, s.Value, true) == null) { return(false); } } } return(true); } Pullenti.Ner.Referent ref1 = this.GetSlotValue(ATTR_REF) as Pullenti.Ner.Referent; Pullenti.Ner.Referent ref2 = geo.GetSlotValue(ATTR_REF) as Pullenti.Ner.Referent; if (ref1 != null && ref2 != null) { if (ref1 != ref2) { return(false); } } bool r = IsRegion || IsState; bool r1 = geo.IsRegion || geo.IsState; if (r != r1) { if (IsTerritory != geo.IsTerritory) { return(false); } return(false); } bool eqNames = false; foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_NAME) { if (geo.FindSlot(s.TypeName, s.Value, true) != null) { eqNames = true; break; } } } if (!eqNames) { return(false); } if (IsRegion && geo.IsRegion) { List <string> typs1 = Typs; List <string> typs2 = geo.Typs; bool ok = false; foreach (string t in typs1) { if (typs2.Contains(t)) { ok = true; } else { foreach (string tt in typs2) { if (Pullenti.Morph.LanguageHelper.EndsWith(tt, t) || Pullenti.Morph.LanguageHelper.EndsWith(t, tt)) { ok = true; } } } } if (!ok) { return(false); } } if (Higher != null && geo.Higher != null) { if (_checkRoundDep(this) || _checkRoundDep(geo)) { return(false); } if (Higher.CanBeEquals(geo.Higher, typ)) { } else if (geo.Higher.Higher != null && Higher.CanBeEquals(geo.Higher.Higher, typ)) { } else if (Higher.Higher != null && Higher.Higher.CanBeEquals(geo.Higher, typ)) { } else { return(false); } } return(true); }
void _recalcTmpBits() { m_TmpBits = 1; m_Higher = null; GeoReferent hi = this.GetSlotValue(ATTR_HIGHER) as GeoReferent; if (hi == this || hi == null) { } else { List <Pullenti.Ner.Referent> li = null; bool err = false; for (Pullenti.Ner.Referent r = hi.GetSlotValue(ATTR_HIGHER) as Pullenti.Ner.Referent; r != null; r = r.GetSlotValue(ATTR_HIGHER) as Pullenti.Ner.Referent) { if (r == hi || r == this) { err = true; break; } if (li == null) { li = new List <Pullenti.Ner.Referent>(); } else if (li.Contains(r)) { err = true; break; } li.Add(r); } if (!err) { m_Higher = hi; } } int isState = -1; int isReg = -1; foreach (Pullenti.Ner.Slot t in Slots) { if (t.TypeName == ATTR_TYPE) { string val = t.Value as string; if (val == "территория" || val == "територія" || val == "territory") { m_TmpBits = 1 | BIT_ISTERRITORY; return; } if (_isCity(val)) { m_TmpBits |= BIT_ISCITY; if ((val == "город" || val == "місто" || val == "city") || val == "town") { m_TmpBits |= BIT_ISBIGCITY; } continue; } if ((val == "государство" || val == "держава" || val == "империя") || val == "імперія" || val == "country") { m_TmpBits |= BIT_ISSTATE; isReg = 0; continue; } if (_isRegion(val)) { if (isState < 0) { isState = 0; } if (isReg < 0) { isReg = 1; } } } else if (t.TypeName == ATTR_ALPHA2) { m_TmpBits = 1 | BIT_ISSTATE; if (this.FindSlot(ATTR_TYPE, "город", true) != null || this.FindSlot(ATTR_TYPE, "місто", true) != null || this.FindSlot(ATTR_TYPE, "city", true) != null) { m_TmpBits |= (BIT_ISBIGCITY | BIT_ISCITY); } return; } } if (isState != 0) { if ((isState < 0) && ((m_TmpBits & BIT_ISCITY)) != 0) { } else { m_TmpBits |= BIT_ISSTATE; } } if (isReg != 0) { if ((isState < 0) && ((m_TmpBits & BIT_ISCITY)) != 0) { } else { m_TmpBits |= BIT_ISREGION; } } }
// Добавляем ссылку на организацию, также добавляем имена internal void AddOrgReferent(Pullenti.Ner.Referent org) { if (org == null) { return; } bool nam = false; this.AddSlot(ATTR_REF, org, false, 0); GeoReferent geo = null; string specTyp = null; string num = org.GetStringValue("NUMBER"); foreach (Pullenti.Ner.Slot s in org.Slots) { if (s.TypeName == "NAME") { if (num == null) { this.AddName(s.Value as string); } else { this.AddName(string.Format("{0}-{1}", s.Value, num)); } nam = true; } else if (s.TypeName == "TYPE") { string v = s.Value as string; if (v == "СЕЛЬСКИЙ СОВЕТ") { this.AddTyp("сельский округ"); } else if (v == "ГОРОДСКОЙ СОВЕТ") { this.AddTyp("городской округ"); } else if (v == "ПОСЕЛКОВЫЙ СОВЕТ") { this.AddTyp("поселковый округ"); } else if (v == "аэропорт") { specTyp = v.ToUpper(); } } else if (s.TypeName == "GEO" && (s.Value is GeoReferent)) { geo = s.Value as GeoReferent; } } if (!nam) { foreach (Pullenti.Ner.Slot s in org.Slots) { if (s.TypeName == "EPONYM") { if (num == null) { this.AddName((s.Value as string).ToUpper()); } else { this.AddName(string.Format("{0}-{1}", (s.Value as string).ToUpper(), num)); } nam = true; } } } if (!nam && num != null) { foreach (Pullenti.Ner.Slot s in org.Slots) { if (s.TypeName == "TYPE") { this.AddName(string.Format("{0}-{1}", (s.Value as string).ToUpper(), num)); nam = true; } } } if (geo != null && !nam) { foreach (string n in geo.GetStringValues(ATTR_NAME)) { this.AddName(n); if (specTyp != null) { this.AddName(string.Format("{0} {1}", n, specTyp)); this.AddName(string.Format("{0} {1}", specTyp, n)); } nam = true; } } if (!nam) { this.AddName(org.ToString(true, Pullenti.Morph.MorphLang.Unknown, 0).ToUpper()); } }