Пример #1
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;
                }
            }
        }
Пример #2
0
        internal AnalysisResult _process(SourceOfAnalysis text, bool ontoRegine, bool noLog, ExtOntology extOntology = null, Pullenti.Morph.MorphLang lang = null)
        {
            m_Breaked = false;
            this.PrepareProgress();
            Stopwatch sw0 = Stopwatch.StartNew();

            this.ManageReferentLinks();
            if (!noLog)
            {
                this.OnProgressHandler(this, new ProgressChangedEventArgs(0, "Морфологический анализ"));
            }
            Pullenti.Ner.Core.AnalysisKit kit = new Pullenti.Ner.Core.AnalysisKit(text, false, lang, OnProgressHandler)
            {
                Ontology = extOntology, Processor = this, OntoRegime = ontoRegine
            };
            AnalysisResult ar = new AnalysisResult();

            sw0.Stop();
            string msg;

            this.OnProgressHandler(this, new ProgressChangedEventArgs(100, string.Format("Морфологический анализ завершён")));
            int k = 0;

            for (Token t = kit.FirstToken; t != null; t = t.Next)
            {
                k++;
            }
            if (!noLog)
            {
                msg = string.Format("Из {0} символов текста выделено {1} термов за {2} ms", text.Text.Length, k, sw0.ElapsedMilliseconds);
                if (!kit.BaseLanguage.IsUndefined)
                {
                    msg += string.Format(", базовый язык {0}", kit.BaseLanguage.ToString());
                }
                this.OnMessage(msg);
                ar.Log.Add(msg);
                if (text.CrlfCorrectedCount > 0)
                {
                    ar.Log.Add(string.Format("{0} переходов на новую строку заменены на пробел", text.CrlfCorrectedCount));
                }
                if (kit.FirstToken == null)
                {
                    ar.Log.Add("Пустой текст");
                }
            }
            sw0.Start();
            if (kit.FirstToken != null)
            {
                this._process2(kit, ar, noLog);
            }
            if (!ontoRegine)
            {
                this._createRes(kit, ar, extOntology, noLog);
            }
            sw0.Stop();
            if (!noLog)
            {
                if (sw0.ElapsedMilliseconds > 5000)
                {
                    float f = (float)text.Text.Length;
                    f  /= sw0.ElapsedMilliseconds;
                    msg = string.Format("Обработка {0} знаков выполнена за {1} ({2} Kb/sec)", text.Text.Length, OutSecs(sw0.ElapsedMilliseconds), f);
                }
                else
                {
                    msg = string.Format("Обработка {0} знаков выполнена за {1}", text.Text.Length, OutSecs(sw0.ElapsedMilliseconds));
                }
                this.OnMessage(msg);
                ar.Log.Add(msg);
            }
            if (TimeoutSeconds > 0)
            {
                if (((DateTime.Now - kit.StartDate)).TotalSeconds > TimeoutSeconds)
                {
                    ar.IsTimeoutBreaked = true;
                }
            }
            ar.Sofa = text;
            if (!ontoRegine)
            {
                ar.Entities.AddRange(kit.Entities);
            }
            ar.FirstToken   = kit.FirstToken;
            ar.Ontology     = extOntology;
            ar.BaseLanguage = kit.BaseLanguage;
            return(ar);
        }
Пример #3
0
 /// <summary>
 /// Обработать текст
 /// </summary>
 /// <param name="text">входной контейнер текста</param>
 /// <param name="extOntology">внешняя онтология (null - не используется)</param>
 /// <param name="lang">язык (если не задан, то будет определён автоматически)</param>
 /// <return>аналитический контейнер с результатом</return>
 public AnalysisResult Process(SourceOfAnalysis text, ExtOntology extOntology = null, Pullenti.Morph.MorphLang lang = null)
 {
     return(this._process(text, false, false, extOntology, lang));
 }
Пример #4
0
        List <Referent> _createReferent(string typeName, string definition)
        {
            Analyzer analyzer = null;

            if (!m_AnalByType.TryGetValue(typeName, out analyzer))
            {
                return(null);
            }
            SourceOfAnalysis sf = new SourceOfAnalysis(definition);
            AnalysisResult   ar = m_Processor._process(sf, true, true, null, null);

            if (ar == null || ar.FirstToken == null)
            {
                return(null);
            }
            Referent r0 = ar.FirstToken.GetReferent();
            Token    t  = null;

            if (r0 != null)
            {
                if (r0.TypeName != typeName)
                {
                    r0 = null;
                }
            }
            if (r0 != null)
            {
                t = ar.FirstToken;
            }
            else
            {
                ReferentToken rt = analyzer.ProcessOntologyItem(ar.FirstToken);
                if (rt == null)
                {
                    return(null);
                }
                r0 = rt.Referent;
                t  = rt.EndToken;
            }
            for (t = t.Next; t != null; t = t.Next)
            {
                if (t.IsChar(';') && t.Next != null)
                {
                    Referent r1 = t.Next.GetReferent();
                    if (r1 == null)
                    {
                        ReferentToken rt = analyzer.ProcessOntologyItem(t.Next);
                        if (rt == null)
                        {
                            continue;
                        }
                        t  = rt.EndToken;
                        r1 = rt.Referent;
                    }
                    if (r1.TypeName == typeName)
                    {
                        r0.MergeSlots(r1, true);
                        r1.Tag = r0;
                    }
                }
            }
            if (r0 == null)
            {
                return(null);
            }
            r0.Tag = r0;
            r0     = analyzer.PersistAnalizerData.RegisterReferent(r0);
            m_Processor._createRes(ar.FirstToken.Kit, ar, null, true);
            List <Referent> res = new List <Referent>();

            res.Add(r0);
            foreach (Referent e in ar.Entities)
            {
                if (e.Tag == null)
                {
                    res.Add(e);
                }
            }
            return(res);
        }