Пример #1
0
        public override Pullenti.Ner.ReferentToken ProcessOntologyItem(Pullenti.Ner.Token begin)
        {
            if (!(begin is Pullenti.Ner.TextToken))
            {
                return(null);
            }
            Pullenti.Ner.Measure.Internal.UnitToken ut = Pullenti.Ner.Measure.Internal.UnitToken.TryParse(begin, null, null, false);
            if (ut != null)
            {
                return(new Pullenti.Ner.ReferentToken(ut.CreateReferentWithRegister(null), ut.BeginToken, ut.EndToken));
            }
            UnitReferent u = new UnitReferent();

            u.AddSlot(UnitReferent.ATTR_NAME, begin.GetSourceText(), false, 0);
            return(new Pullenti.Ner.ReferentToken(u, begin, begin));
        }
Пример #2
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ = Pullenti.Ner.Core.ReferentsEqualType.WithinOneText)
        {
            UnitReferent ur = obj as UnitReferent;

            if (ur == null)
            {
                return(false);
            }
            foreach (Pullenti.Ner.Slot s in Slots)
            {
                if (ur.FindSlot(s.TypeName, s.Value, true) == null)
                {
                    return(false);
                }
            }
            foreach (Pullenti.Ner.Slot s in ur.Slots)
            {
                if (this.FindSlot(s.TypeName, s.Value, true) == null)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
 public override void Process(Pullenti.Ner.Core.AnalysisKit kit)
 {
     Pullenti.Ner.Core.AnalyzerData     ad       = kit.GetAnalyzerData(this);
     Pullenti.Ner.Core.TerminCollection addunits = null;
     if (kit.Ontology != null)
     {
         addunits = new Pullenti.Ner.Core.TerminCollection();
         foreach (Pullenti.Ner.ExtOntologyItem r in kit.Ontology.Items)
         {
             UnitReferent uu = r.Referent as UnitReferent;
             if (uu == null)
             {
                 continue;
             }
             if (uu.m_Unit != null)
             {
                 continue;
             }
             foreach (Pullenti.Ner.Slot s in uu.Slots)
             {
                 if (s.TypeName == UnitReferent.ATTR_NAME || s.TypeName == UnitReferent.ATTR_FULLNAME)
                 {
                     addunits.Add(new Pullenti.Ner.Core.Termin(s.Value as string)
                     {
                         Tag = uu
                     });
                 }
             }
         }
     }
     for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next)
     {
         Pullenti.Ner.Measure.Internal.MeasureToken mt = Pullenti.Ner.Measure.Internal.MeasureToken.TryParseMinimal(t, addunits, false);
         if (mt == null)
         {
             mt = Pullenti.Ner.Measure.Internal.MeasureToken.TryParse(t, addunits, true, false, false, false);
         }
         if (mt == null)
         {
             continue;
         }
         List <Pullenti.Ner.ReferentToken> rts = mt.CreateRefenetsTokensWithRegister(ad, true);
         if (rts == null)
         {
             continue;
         }
         for (int i = 0; i < rts.Count; i++)
         {
             Pullenti.Ner.ReferentToken rt = rts[i];
             t.Kit.EmbedToken(rt);
             t = rt;
             for (int j = i + 1; j < rts.Count; j++)
             {
                 if (rts[j].BeginToken == rt.BeginToken)
                 {
                     rts[j].BeginToken = t;
                 }
                 if (rts[j].EndToken == rt.EndToken)
                 {
                     rts[j].EndToken = t;
                 }
             }
         }
     }
     if (kit.Ontology != null)
     {
         foreach (Pullenti.Ner.Referent e in ad.Referents)
         {
             UnitReferent u = e as UnitReferent;
             if (u == null)
             {
                 continue;
             }
             foreach (Pullenti.Ner.ExtOntologyItem r in kit.Ontology.Items)
             {
                 UnitReferent uu = r.Referent as UnitReferent;
                 if (uu == null)
                 {
                     continue;
                 }
                 bool ok = false;
                 foreach (Pullenti.Ner.Slot s in uu.Slots)
                 {
                     if (s.TypeName == UnitReferent.ATTR_NAME || s.TypeName == UnitReferent.ATTR_FULLNAME)
                     {
                         if (u.FindSlot(null, s.Value, true) != null)
                         {
                             ok = true;
                             break;
                         }
                     }
                 }
                 if (ok)
                 {
                     u.OntologyItems = new List <Pullenti.Ner.ExtOntologyItem>();
                     u.OntologyItems.Add(r);
                     break;
                 }
             }
         }
     }
 }