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; } } }