Esempio n. 1
0
        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);
        }