示例#1
0
        public override Pullenti.Ner.ReferentToken ProcessOntologyItem(Pullenti.Ner.Token begin)
        {
            if (begin == null)
            {
                return(null);
            }
            GoodAttributeReferent ga = new GoodAttributeReferent();

            if (begin.Chars.IsLatinLetter)
            {
                if (begin.IsValue("KEYWORD", null))
                {
                    ga.Typ = GoodAttrType.Keyword;
                    begin  = begin.Next;
                }
                else if (begin.IsValue("CHARACTER", null))
                {
                    ga.Typ = GoodAttrType.Character;
                    begin  = begin.Next;
                }
                else if (begin.IsValue("PROPER", null))
                {
                    ga.Typ = GoodAttrType.Proper;
                    begin  = begin.Next;
                }
                else if (begin.IsValue("MODEL", null))
                {
                    ga.Typ = GoodAttrType.Model;
                    begin  = begin.Next;
                }
                if (begin == null)
                {
                    return(null);
                }
            }
            Pullenti.Ner.ReferentToken res = new Pullenti.Ner.ReferentToken(ga, begin, begin);
            for (Pullenti.Ner.Token t = begin; t != null; t = t.Next)
            {
                if (t.IsChar(';'))
                {
                    ga.AddSlot(GoodAttributeReferent.ATTR_VALUE, Pullenti.Ner.Core.MiscHelper.GetTextValue(begin, t.Previous, Pullenti.Ner.Core.GetTextAttr.No), false, 0);
                    begin = t.Next;
                    continue;
                }
                res.EndToken = t;
            }
            if (res.EndChar > begin.BeginChar)
            {
                ga.AddSlot(GoodAttributeReferent.ATTR_VALUE, Pullenti.Ner.Core.MiscHelper.GetTextValue(begin, res.EndToken, Pullenti.Ner.Core.GetTextAttr.No), false, 0);
            }
            if (ga.Typ == GoodAttrType.Undefined)
            {
                if (!begin.Chars.IsAllLower)
                {
                    ga.Typ = GoodAttrType.Proper;
                }
            }
            return(res);
        }
示例#2
0
        public override void Process(Pullenti.Ner.Core.AnalysisKit kit)
        {
            Pullenti.Ner.Core.AnalyzerData ad = kit.GetAnalyzerData(this);
            int delta = 100000;
            int parts = (((kit.Sofa.Text.Length + delta) - 1)) / delta;

            if (parts == 0)
            {
                parts = 1;
            }
            int cur     = 0;
            int nextPos = 0;

            for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next)
            {
                if (t.BeginChar > nextPos)
                {
                    nextPos += delta;
                    cur++;
                    if (!this.OnProgress(cur, parts, kit))
                    {
                        break;
                    }
                }
                Pullenti.Ner.Goods.Internal.GoodAttrToken at = Pullenti.Ner.Goods.Internal.GoodAttrToken.TryParse(t, null, true, true);
                if (at == null)
                {
                    continue;
                }
                GoodAttributeReferent attr = at._createAttr();
                if (attr == null)
                {
                    t = at.EndToken;
                    continue;
                }
                Pullenti.Ner.ReferentToken rt = new Pullenti.Ner.ReferentToken(attr, at.BeginToken, at.EndToken);
                rt.Referent = ad.RegisterReferent(attr);
                kit.EmbedToken(rt);
                t = rt;
            }
        }
示例#3
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ = Pullenti.Ner.Core.ReferentsEqualType.WithinOneText)
        {
            GoodAttributeReferent a = obj as GoodAttributeReferent;

            if (a == null)
            {
                return(false);
            }
            if (a.Typ != Typ)
            {
                return(false);
            }
            string u1 = this.GetStringValue(ATTR_UNIT);
            string u2 = a.GetStringValue(ATTR_UNIT);

            if (u1 != null && u2 != null)
            {
                if (u1 != u2)
                {
                    if (u1.Length == (u2.Length + 1) && u1 == (u2 + "."))
                    {
                    }
                    else if (u2.Length == (u1.Length + 1) && u2 == (u1 + "."))
                    {
                    }
                    return(false);
                }
            }
            string nam1 = this.GetStringValue(ATTR_NAME);
            string nam2 = a.GetStringValue(ATTR_NAME);

            if (nam1 != null || nam2 != null)
            {
                if (nam1 != nam2)
                {
                    return(false);
                }
            }
            bool eq = false;

            if (Ref != null || a.Ref != null)
            {
                if (Ref == null || a.Ref == null)
                {
                    return(false);
                }
                if (!Ref.CanBeEquals(a.Ref, typ))
                {
                    return(false);
                }
                eq = true;
            }
            if (Typ != GoodAttrType.Numeric)
            {
                foreach (Pullenti.Ner.Slot s in Slots)
                {
                    if (s.TypeName == ATTR_VALUE || s.TypeName == ATTR_ALTVALUE)
                    {
                        if (a.FindSlot(ATTR_VALUE, s.Value, true) != null || a.FindSlot(ATTR_ALTVALUE, s.Value, true) != null)
                        {
                            eq = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                List <string> vals1 = Values;
                List <string> vals2 = a.Values;
                if (vals1.Count != vals2.Count)
                {
                    return(false);
                }
                foreach (string v in vals1)
                {
                    if (!vals2.Contains(v))
                    {
                        return(false);
                    }
                }
            }
            if (!eq)
            {
                return(false);
            }
            return(true);
        }