Пример #1
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ)
        {
            NamedEntityReferent ent = obj as NamedEntityReferent;

            if (ent == null)
            {
                return(false);
            }
            if (ent.Kind != Kind)
            {
                return(false);
            }
            List <string> names   = this.GetStringValues(ATTR_NAME);
            List <string> names2  = obj.GetStringValues(ATTR_NAME);
            bool          eqNames = false;

            if ((names != null && names.Count > 0 && names2 != null) && names2.Count > 0)
            {
                foreach (string n in names)
                {
                    if (names2.Contains(n))
                    {
                        eqNames = true;
                    }
                }
                if (!eqNames)
                {
                    return(false);
                }
            }
            List <string> typs   = this.GetStringValues(ATTR_TYPE);
            List <string> typs2  = obj.GetStringValues(ATTR_TYPE);
            bool          eqTyps = false;

            if ((typs != null && typs.Count > 0 && typs2 != null) && typs2.Count > 0)
            {
                foreach (string ty in typs)
                {
                    if (typs2.Contains(ty))
                    {
                        eqTyps = true;
                    }
                }
                if (!eqTyps)
                {
                    return(false);
                }
            }
            if (!eqTyps && !eqNames)
            {
                return(false);
            }
            Pullenti.Ner.Referent re1 = this.GetSlotValue(ATTR_REF) as Pullenti.Ner.Referent;
            Pullenti.Ner.Referent re2 = obj.GetSlotValue(ATTR_REF) as Pullenti.Ner.Referent;
            if (re1 != null && re2 != null)
            {
                if (!re1.CanBeEquals(re2, typ))
                {
                    return(false);
                }
            }
            else if (re1 != null || re2 != null)
            {
            }
            return(true);
        }
Пример #2
0
        static Pullenti.Ner.ReferentToken _tryAttach(List <Pullenti.Ner.Named.Internal.NamedItemToken> toks)
        {
            Pullenti.Ner.Named.Internal.NamedItemToken        typ  = null;
            Pullenti.Ner.Named.Internal.NamedItemToken        re   = null;
            List <Pullenti.Ner.Named.Internal.NamedItemToken> nams = null;
            NamedEntityKind ki = NamedEntityKind.Undefined;
            int             i;

            for (i = 0; i < toks.Count; i++)
            {
                if (toks[i].TypeValue != null)
                {
                    if (nams != null && toks[i].NameValue != null)
                    {
                        break;
                    }
                    if (typ == null)
                    {
                        typ = toks[i];
                        ki  = typ.Kind;
                    }
                    else if (typ.Kind != toks[i].Kind)
                    {
                        break;
                    }
                }
                if (toks[i].NameValue != null)
                {
                    if (typ != null && toks[i].Kind != NamedEntityKind.Undefined && toks[i].Kind != typ.Kind)
                    {
                        break;
                    }
                    if (nams == null)
                    {
                        nams = new List <Pullenti.Ner.Named.Internal.NamedItemToken>();
                    }
                    else if (nams[0].IsWellknown != toks[i].IsWellknown)
                    {
                        break;
                    }
                    if (ki == NamedEntityKind.Undefined)
                    {
                        ki = toks[i].Kind;
                    }
                    nams.Add(toks[i]);
                }
                if (toks[i].TypeValue == null && toks[i].NameValue == null)
                {
                    break;
                }
                if (re == null && canBeRef(ki, toks[i].Ref))
                {
                    re = toks[i];
                }
            }
            if ((i < toks.Count) && toks[i].Ref != null)
            {
                if (canBeRef(ki, toks[i].Ref))
                {
                    re = toks[i];
                    i++;
                }
            }
            bool ok = false;

            if (typ != null)
            {
                if (nams == null)
                {
                    if (re == null)
                    {
                        ok = false;
                    }
                    else
                    {
                        ok = true;
                    }
                }
                else if ((nams[0].BeginChar < typ.EndChar) && !nams[0].IsWellknown)
                {
                    if (re != null)
                    {
                        ok = true;
                    }
                    else if ((nams[0].Chars.IsCapitalUpper && !Pullenti.Ner.Core.MiscHelper.CanBeStartOfSentence(nams[0].BeginToken) && typ.Morph.Number != Pullenti.Morph.MorphNumber.Plural) && typ.Morph.Case.IsNominative)
                    {
                        ok = true;
                    }
                }
                else
                {
                    ok = true;
                }
            }
            else if (nams != null)
            {
                if (nams.Count == 1 && nams[0].Chars.IsAllLower)
                {
                }
                else if (nams[0].IsWellknown)
                {
                    ok = true;
                }
            }
            if (!ok || ki == NamedEntityKind.Undefined)
            {
                return(null);
            }
            NamedEntityReferent nam = new NamedEntityReferent()
            {
                Kind = ki
            };

            if (typ != null)
            {
                nam.AddSlot(NamedEntityReferent.ATTR_TYPE, typ.TypeValue.ToLower(), false, 0);
            }
            if (nams != null)
            {
                if (nams.Count == 1 && nams[0].IsWellknown && nams[0].TypeValue != null)
                {
                    nam.AddSlot(NamedEntityReferent.ATTR_TYPE, nams[0].TypeValue.ToLower(), false, 0);
                }
                if (typ != null && (typ.EndChar < nams[0].BeginChar))
                {
                    string str = Pullenti.Ner.Core.MiscHelper.GetTextValue(nams[0].BeginToken, nams[nams.Count - 1].EndToken, Pullenti.Ner.Core.GetTextAttr.No);
                    nam.AddSlot(NamedEntityReferent.ATTR_NAME, str, false, 0);
                }
                StringBuilder tmp = new StringBuilder();
                foreach (Pullenti.Ner.Named.Internal.NamedItemToken n in nams)
                {
                    if (tmp.Length > 0)
                    {
                        tmp.Append(' ');
                    }
                    tmp.Append(n.NameValue);
                }
                nam.AddSlot(NamedEntityReferent.ATTR_NAME, tmp.ToString(), false, 0);
            }
            if (re != null)
            {
                nam.AddSlot(NamedEntityReferent.ATTR_REF, re.Ref, false, 0);
            }
            return(new Pullenti.Ner.ReferentToken(nam, toks[0].BeginToken, toks[i - 1].EndToken));
        }