Esempio n. 1
0
 internal Pullenti.Ner.Core.Internal.TextsCompareType CompareWith(TextAnnotation loc)
 {
     if (loc.Sofa != Sofa)
     {
         return(Pullenti.Ner.Core.Internal.TextsCompareType.Noncomparable);
     }
     return(this.Compare(loc.BeginChar, loc.EndChar));
 }
Esempio n. 2
0
 /// <summary>
 /// Добавить аннотацию
 /// </summary>
 /// <param name="anno">аннотация</param>
 public void AddOccurence(TextAnnotation anno)
 {
     foreach (TextAnnotation l in Occurrence)
     {
         Pullenti.Ner.Core.Internal.TextsCompareType typ = l.CompareWith(anno);
         if (typ == Pullenti.Ner.Core.Internal.TextsCompareType.Noncomparable)
         {
             continue;
         }
         if (typ == Pullenti.Ner.Core.Internal.TextsCompareType.Equivalent || typ == Pullenti.Ner.Core.Internal.TextsCompareType.Contains)
         {
             return;
         }
         if (typ == Pullenti.Ner.Core.Internal.TextsCompareType.In || typ == Pullenti.Ner.Core.Internal.TextsCompareType.Intersect)
         {
             l.Merge(anno);
             return;
         }
     }
     if (anno.OccurenceOf != this && anno.OccurenceOf != null)
     {
         anno = new TextAnnotation()
         {
             BeginChar = anno.BeginChar, EndChar = anno.EndChar, Sofa = anno.Sofa
         }
     }
     ;
     if (m_Occurrence == null)
     {
         m_Occurrence = new List <TextAnnotation>();
     }
     anno.OccurenceOf = this;
     if (m_Occurrence.Count == 0)
     {
         anno.EssentialForOccurence = true;
         m_Occurrence.Add(anno);
         return;
     }
     if (anno.BeginChar < m_Occurrence[0].BeginChar)
     {
         m_Occurrence.Insert(0, anno);
         return;
     }
     if (anno.BeginChar >= m_Occurrence[m_Occurrence.Count - 1].BeginChar)
     {
         m_Occurrence.Add(anno);
         return;
     }
     for (int i = 0; i < (m_Occurrence.Count - 1); i++)
     {
         if (anno.BeginChar >= m_Occurrence[i].BeginChar && anno.BeginChar <= m_Occurrence[i + 1].BeginChar)
         {
             m_Occurrence.Insert(i + 1, anno);
             return;
         }
     }
     m_Occurrence.Add(anno);
 }
Esempio n. 3
0
        public void Deserialize(Stream stream, List <Referent> all, SourceOfAnalysis sofa)
        {
            string typ = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeString(stream);
            int    cou = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);

            for (int i = 0; i < cou; i++)
            {
                typ = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeString(stream);
                int    c   = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
                int    id  = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
                object val = null;
                if ((id < 0) && all != null)
                {
                    int id1 = (-id) - 1;
                    if (id1 < all.Count)
                    {
                        val = all[id1];
                    }
                }
                else if (id > 0)
                {
                    stream.Position -= 4;
                    val              = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeString(stream);
                }
                this.AddSlot(typ, val, false, c);
            }
            cou          = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
            m_Occurrence = new List <TextAnnotation>();
            for (int i = 0; i < cou; i++)
            {
                TextAnnotation a = new TextAnnotation()
                {
                    Sofa = sofa, OccurenceOf = this
                };
                m_Occurrence.Add(a);
                a.BeginChar = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
                a.EndChar   = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
                int attr = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);
                if (((attr & 1)) != 0)
                {
                    a.EssentialForOccurence = true;
                }
            }
        }
Esempio n. 4
0
 internal void Merge(TextAnnotation loc)
 {
     if (loc.Sofa != Sofa)
     {
         return;
     }
     if (loc.BeginChar < BeginChar)
     {
         BeginChar = loc.BeginChar;
     }
     if (EndChar < loc.EndChar)
     {
         EndChar = loc.EndChar;
     }
     if (loc.EssentialForOccurence)
     {
         EssentialForOccurence = true;
     }
 }
Esempio n. 5
0
        public virtual void SaveToLocalOntology()
        {
            if (Data == null)
            {
                return;
            }
            Referent r = Data.RegisterReferent(Referent);

            Data = null;
            if (r != null)
            {
                Referent = r;
                TextAnnotation anno = new TextAnnotation();
                anno.Sofa        = Kit.Sofa;
                anno.OccurenceOf = Referent;
                anno.BeginChar   = BeginChar;
                anno.EndChar     = EndChar;
                Referent.AddOccurence(anno);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Найти ближайшую к токену аннотацию
        /// </summary>
        /// <param name="t">токен</param>
        /// <return>ближайшая аннотация</return>
        public TextAnnotation FindNearOccurence(Token t)
        {
            int            min = -1;
            TextAnnotation res = null;

            foreach (TextAnnotation oc in Occurrence)
            {
                if (oc.Sofa == t.Kit.Sofa)
                {
                    int len = oc.BeginChar - t.BeginChar;
                    if (len < 0)
                    {
                        len = -len;
                    }
                    if ((min < 0) || (len < min))
                    {
                        min = len;
                        res = oc;
                    }
                }
            }
            return(res);
        }