Exemplo n.º 1
0
        /// <summary>
        /// Добавить элемент
        /// </summary>
        /// <param name="extId">произвольный объект</param>
        /// <param name="typeName">имя типа сущности</param>
        /// <param name="definition">текстовое определение. Определение может содержать несколько
        /// отдельных фрагментов, которые разделяются точкой с запятой.
        /// Например, Министерство Обороны России; Минобороны</param>
        /// <return>если null, то не получилось...</return>
        public ExtOntologyItem Add(object extId, string typeName, string definition)
        {
            if (typeName == null || definition == null)
            {
                return(null);
            }
            List <Referent> rs = this._createReferent(typeName, definition);

            if (rs == null)
            {
                return(null);
            }
            m_Hash = null;
            ExtOntologyItem res = new ExtOntologyItem()
            {
                ExtId = extId, Referent = rs[0], TypeName = typeName
            };

            if (rs.Count > 1)
            {
                rs.RemoveAt(0);
                res.Refs = rs;
            }
            Items.Add(res);
            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Обновить существующий элемент онтологии новой сущностью
        /// </summary>
        /// <param name="item">обновляемый элемент</param>
        /// <param name="newReferent">сущность</param>
        /// <return>признак успешности обновления</return>
        public bool Refresh(ExtOntologyItem item, Referent newReferent)
        {
            if (item == null)
            {
                return(false);
            }
            Analyzer analyzer = null;

            if (!m_AnalByType.TryGetValue(item.TypeName, out analyzer))
            {
                return(false);
            }
            if (analyzer.PersistAnalizerData == null)
            {
                return(true);
            }
            if (item.Referent != null)
            {
                analyzer.PersistAnalizerData.RemoveReferent(item.Referent);
            }
            Referent oldReferent = item.Referent;

            newReferent   = analyzer.PersistAnalizerData.RegisterReferent(newReferent);
            item.Referent = newReferent;
            m_Hash        = null;
            if (oldReferent != null && newReferent != null)
            {
                foreach (Analyzer a in m_Processor.Analyzers)
                {
                    if (a.PersistAnalizerData != null)
                    {
                        foreach (Referent rr in a.PersistAnalizerData.Referents)
                        {
                            foreach (Slot s in newReferent.Slots)
                            {
                                if (s.Value == oldReferent)
                                {
                                    newReferent.UploadSlot(s, rr);
                                }
                            }
                            foreach (Slot s in rr.Slots)
                            {
                                if (s.Value == oldReferent)
                                {
                                    rr.UploadSlot(s, newReferent);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Восстановить словарь из потока
        /// </summary>
        /// <param name="stream">поток для десериализации</param>
        public void Deserialize(Stream stream)
        {
            m_Specs = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeString(stream);
            this._init();
            int cou = Pullenti.Ner.Core.Internal.SerializerHelper.DeserializeInt(stream);

            for (; cou > 0; cou--)
            {
                ExtOntologyItem it = new ExtOntologyItem();
                it.Deserialize(stream);
                Items.Add(it);
            }
            this._initHash();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Обновить существующий элемент онтологии
        /// </summary>
        /// <param name="definition">новое определение</param>
        /// <return>признак успешности обновления</return>
        public bool Refresh(ExtOntologyItem item, string definition)
        {
            if (item == null)
            {
                return(false);
            }
            List <Referent> rs = this._createReferent(item.TypeName, definition);

            if (rs == null)
            {
                return(false);
            }
            return(this.Refresh(item, rs[0]));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Добавить готовую сущность
        /// </summary>
        /// <param name="extId">произвольный объект</param>
        /// <param name="referent">готовая сущность (например, сфомированная явно)</param>
        /// <return>новая запись словаря</return>
        public ExtOntologyItem AddReferent(object extId, Referent referent)
        {
            if (referent == null)
            {
                return(null);
            }
            m_Hash = null;
            ExtOntologyItem res = new ExtOntologyItem()
            {
                ExtId = extId, Referent = referent, TypeName = referent.TypeName
            };

            Items.Add(res);
            return(res);
        }