Exemplo n.º 1
0
        public override string ToString(bool shortVariant, Pullenti.Morph.MorphLang lang = null, int lev = 0)
        {
            StringBuilder res = new StringBuilder();

            if (Name != null)
            {
                res.Append(Name);
            }
            foreach (Pullenti.Ner.Slot r in Slots)
            {
                if (r.TypeName == ATTR_ATTR && r.Value != null)
                {
                    res.AppendFormat(", {0}", r.Value.ToString());
                }
            }
            foreach (Pullenti.Ner.Slot r in Slots)
            {
                if (r.TypeName == ATTR_REF && (r.Value is Pullenti.Ner.Referent) && (lev < 10))
                {
                    res.AppendFormat("; {0}", (r.Value as Pullenti.Ner.Referent).ToString(shortVariant, lang, lev + 1));
                }
            }
            PersonPropertyReferent hi = Higher;

            if (hi != null && hi != this && this.CheckCorrectHigher(hi, 0))
            {
                res.AppendFormat("; {0}", hi.ToString(shortVariant, lang, lev + 1));
            }
            return(res.ToString());
        }
Exemplo n.º 2
0
        PersonPropertyReferent _getHigher(int lev)
        {
            PersonPropertyReferent hi = this.GetSlotValue(ATTR_HIGHER) as PersonPropertyReferent;

            if (hi == null)
            {
                return(null);
            }
            if (!this.CheckCorrectHigher(hi, lev + 1))
            {
                return(null);
            }
            return(hi);
        }
Exemplo n.º 3
0
        void CorrectAttrs()
        {
            List <PersonPropertyReferent> attrs = new List <PersonPropertyReferent>();

            foreach (Pullenti.Ner.Slot s in Slots)
            {
                if (s.TypeName == ATTR_ATTR && (s.Value is PersonPropertyReferent))
                {
                    attrs.Add(s.Value as PersonPropertyReferent);
                }
            }
            if (attrs.Count < 2)
            {
                return;
            }
            foreach (PersonPropertyReferent a in attrs)
            {
                a.Tag = null;
            }
            for (int i = 0; i < (attrs.Count - 1); i++)
            {
                for (int j = i + 1; j < attrs.Count; j++)
                {
                    if (attrs[i].GeneralReferent == attrs[j] || attrs[j].CanBeGeneralFor(attrs[i]))
                    {
                        attrs[j].Tag = attrs[i];
                    }
                    else if (attrs[j].GeneralReferent == attrs[i] || attrs[i].CanBeGeneralFor(attrs[j]))
                    {
                        attrs[i].Tag = attrs[j];
                    }
                }
            }
            for (int i = Slots.Count - 1; i >= 0; i--)
            {
                if (Slots[i].TypeName == ATTR_ATTR && (Slots[i].Value is PersonPropertyReferent))
                {
                    if ((Slots[i].Value as PersonPropertyReferent).Tag != null)
                    {
                        PersonPropertyReferent pr = (Slots[i].Value as PersonPropertyReferent).Tag as PersonPropertyReferent;
                        if (pr != null && pr.GeneralReferent == null)
                        {
                            pr.GeneralReferent = Slots[i].Value as PersonPropertyReferent;
                        }
                        Slots.RemoveAt(i);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override bool CanBeGeneralFor(Pullenti.Ner.Referent obj)
        {
            PersonPropertyReferent pr = obj as PersonPropertyReferent;

            if (pr == null)
            {
                return(false);
            }
            string n1 = Name;
            string n2 = pr.Name;

            if (n1 == null || n2 == null)
            {
                return(false);
            }
            if (this.FindSlot(ATTR_REF, null, true) != null || Higher != null)
            {
                if (n1 != n2 && n1.StartsWith(n2))
                {
                    return(this.CanBeEquals(obj, Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts));
                }
                return(false);
            }
            if (n1 == n2)
            {
                if (pr.FindSlot(ATTR_REF, null, true) != null || pr.Higher != null)
                {
                    return(true);
                }
                return(false);
            }
            if (n2.StartsWith(n1))
            {
                if (n2.StartsWith(n1 + " "))
                {
                    return(this.CanBeEquals(obj, Pullenti.Ner.Core.ReferentsEqualType.WithinOneText));
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        bool CheckCorrectHigher(PersonPropertyReferent hi, int lev)
        {
            if (hi == null)
            {
                return(true);
            }
            if (hi == this)
            {
                return(false);
            }
            if (lev > 20)
            {
                return(false);
            }
            PersonPropertyReferent hii = hi._getHigher(lev + 1);

            if (hii == null)
            {
                return(true);
            }
            if (hii == this)
            {
                return(false);
            }
            List <PersonPropertyReferent> li = new List <PersonPropertyReferent>();

            li.Add(this);
            for (PersonPropertyReferent pr = hi; pr != null; pr = pr._getHigher(lev + 1))
            {
                if (li.Contains(pr))
                {
                    return(false);
                }
                else
                {
                    li.Add(pr);
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        string _findShortestKingTitul(bool doName = false)
        {
            string res = null;

            foreach (Pullenti.Ner.Slot s in Slots)
            {
                if (s.Value is PersonPropertyReferent)
                {
                    PersonPropertyReferent pr = s.Value as PersonPropertyReferent;
                    if (pr.Kind != PersonPropertyKind.King)
                    {
                        continue;
                    }
                    foreach (Pullenti.Ner.Slot ss in pr.Slots)
                    {
                        if (ss.TypeName == PersonPropertyReferent.ATTR_NAME)
                        {
                            string n = ss.Value as string;
                            if (res == null)
                            {
                                res = n;
                            }
                            else if (res.Length > n.Length)
                            {
                                res = n;
                            }
                        }
                    }
                }
            }
            if (res != null || !doName)
            {
                return(res);
            }
            return(null);
        }
Exemplo n.º 7
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ)
        {
            PersonPropertyReferent pr = obj as PersonPropertyReferent;

            if (pr == null)
            {
                return(false);
            }
            string n1 = Name;
            string n2 = pr.Name;

            if (n1 == null || n2 == null)
            {
                return(false);
            }
            bool eqBosses = false;

            if (n1 != n2)
            {
                if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts)
                {
                    return(false);
                }
                if (m_Bosses0.Contains(n1) && m_Bosses1.Contains(n2))
                {
                    eqBosses = true;
                }
                else if (m_Bosses1.Contains(n1) && m_Bosses0.Contains(n2))
                {
                    eqBosses = true;
                }
                else
                {
                    if (!n1.StartsWith(n2 + " ") && !n2.StartsWith(n1 + " "))
                    {
                        return(false);
                    }
                    eqBosses = true;
                }
                for (PersonPropertyReferent hi = Higher; hi != null; hi = hi.Higher)
                {
                    if ((++_tmpStack) > 20)
                    {
                    }
                    else if (hi.CanBeEquals(pr, typ))
                    {
                        _tmpStack--;
                        return(false);
                    }
                    _tmpStack--;
                }
                for (PersonPropertyReferent hi = pr.Higher; hi != null; hi = hi.Higher)
                {
                    if ((++_tmpStack) > 20)
                    {
                    }
                    else if (hi.CanBeEquals(this, typ))
                    {
                        _tmpStack--;
                        return(false);
                    }
                    _tmpStack--;
                }
            }
            if (Higher != null && pr.Higher != null)
            {
                if ((++_tmpStack) > 20)
                {
                }
                else if (!Higher.CanBeEquals(pr.Higher, typ))
                {
                    _tmpStack--;
                    return(false);
                }
                _tmpStack--;
            }
            if (this.FindSlot("@GENERAL", null, true) != null || pr.FindSlot("@GENERAL", null, true) != null)
            {
                return(this.ToString() == pr.ToString());
            }
            if (this.FindSlot(ATTR_REF, null, true) != null || pr.FindSlot(ATTR_REF, null, true) != null)
            {
                List <object> refs1 = new List <object>();
                List <object> refs2 = new List <object>();
                foreach (Pullenti.Ner.Slot s in Slots)
                {
                    if (s.TypeName == ATTR_REF)
                    {
                        refs1.Add(s.Value);
                    }
                }
                foreach (Pullenti.Ner.Slot s in pr.Slots)
                {
                    if (s.TypeName == ATTR_REF)
                    {
                        refs2.Add(s.Value);
                    }
                }
                bool eq   = false;
                bool noeq = false;
                for (int i = 0; i < refs1.Count; i++)
                {
                    if (refs2.Contains(refs1[i]))
                    {
                        eq = true;
                        continue;
                    }
                    noeq = true;
                    if (refs1[i] is Pullenti.Ner.Referent)
                    {
                        foreach (object rr in refs2)
                        {
                            if (rr is Pullenti.Ner.Referent)
                            {
                                if ((rr as Pullenti.Ner.Referent).CanBeEquals(refs1[i] as Pullenti.Ner.Referent, typ))
                                {
                                    noeq = false;
                                    eq   = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                for (int i = 0; i < refs2.Count; i++)
                {
                    if (refs1.Contains(refs2[i]))
                    {
                        eq = true;
                        continue;
                    }
                    noeq = true;
                    if (refs2[i] is Pullenti.Ner.Referent)
                    {
                        foreach (object rr in refs1)
                        {
                            if (rr is Pullenti.Ner.Referent)
                            {
                                if ((rr as Pullenti.Ner.Referent).CanBeEquals(refs2[i] as Pullenti.Ner.Referent, typ))
                                {
                                    noeq = false;
                                    eq   = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (eq && !noeq)
                {
                }
                else if (noeq && ((eq || refs1.Count == 0 || refs2.Count == 0)))
                {
                    if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts || n1 != n2)
                    {
                        return(false);
                    }
                    if (Higher != null || pr.Higher != null)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else if (!eqBosses && n1 != n2)
            {
                return(false);
            }
            return(true);
        }