Пример #1
0
        public MorphoModelNative(MorphoModelConfig config) : base(config)
        {
            _TreeDictionary = new TreeDictionaryNative();

            using (var loader = new ModelLoader(config, _TreeDictionary))
            {
                _EndingsNativeKeeper = loader.Run();
            }
        }
Пример #2
0
 private void DisposeNativeResources()
 {
     _TreeDictionary = null;
     TreeDictionaryNative.EndLoad();
     _LOWER_INVARIANT_MAP_GCHandle.Free(); _LOWER_INVARIANT_MAP = null;
     _ENDING_LOWER_BUFFER_GCHandle.Free(); _ENDING_LOWER_BUFFER = null;
     _ENDING_UPPER_BUFFER_GCHandle.Free(); _ENDING_UPPER_BUFFER = null;
     _EndingDictionary          = null;
     _ModelLoadingErrorCallback = null;
     _MorphoTypesDictionary     = null;
     _MorphoAttributeList.Dispose(); _MorphoAttributeList = null;
     _PartOfSpeechList = null;
     _PartOfSpeechToNativeStringMapper.Dispose(); _PartOfSpeechToNativeStringMapper = null;
     _MorphoAttributePairs_Buffer = null;
     _EnumParserMorphoAttribute   = null;
     _EnumParserPartOfSpeech      = null;
     _Config = default;
 }
Пример #3
0
            public ModelLoader(MorphoModelConfig config, TreeDictionaryNative treeDictionary)
            {
                const int ENDING_DICTIONARY_CAPACITY           = 350003;
                const int MORPHOTYPES_DICTIONARY_CAPACITY      = 4001;
                const int MORPHOATTRIBUTEPAIRS_BUFFER_CAPACITY = 100;

                _TreeDictionary = treeDictionary;
                TreeDictionaryNative.BeginLoad();
                _Config                           = config;
                _EndingDictionary                 = new Dictionary <IntPtr, IntPtr>(ENDING_DICTIONARY_CAPACITY, default(CharIntPtr_IEqualityComparer));
                _MorphoTypesDictionary            = new Dictionary <IntPtr, MorphoTypeNative>(MORPHOTYPES_DICTIONARY_CAPACITY, default(CharIntPtr_IEqualityComparer));
                _MorphoAttributeList              = new MorphoAttributeList();
                _PartOfSpeechList                 = new PartOfSpeechList();
                _PartOfSpeechToNativeStringMapper = new PartOfSpeechToNativeStringMapper();
                _MorphoAttributePairs_Buffer      = new List <MorphoAttributePair>(MORPHOATTRIBUTEPAIRS_BUFFER_CAPACITY);
                _EnumParserMorphoAttribute        = new EnumParser <MorphoAttributeEnum>();
                _EnumParserPartOfSpeech           = new EnumParser <PartOfSpeechEnum>();
                _EndingDictionary.Add(_EMPTY_STRING, _EMPTY_STRING);
                #region ModelLoadingErrorCallback
                if (config.ModelLoadingErrorCallback == null)
                {
                    _ModelLoadingErrorCallback = (s1, s2) => { };
                }
                else
                {
                    _ModelLoadingErrorCallback = config.ModelLoadingErrorCallback;
                }
                #endregion
                #region LOWER_INVARIANT_MAP
                var lower_invariant_map = Xlat.Create_LOWER_INVARIANT_MAP();
                _LOWER_INVARIANT_MAP_GCHandle = GCHandle.Alloc(lower_invariant_map, GCHandleType.Pinned);
                _LOWER_INVARIANT_MAP          = (char *)_LOWER_INVARIANT_MAP_GCHandle.AddrOfPinnedObject().ToPointer();
                #endregion
                #region ENDING_LOWER_BUFFER
                var ending_lower_buffer = new char[ENDING_BUFFER_SIZE];
                _ENDING_LOWER_BUFFER_GCHandle = GCHandle.Alloc(ending_lower_buffer, GCHandleType.Pinned);
                _ENDING_LOWER_BUFFER          = (char *)_ENDING_LOWER_BUFFER_GCHandle.AddrOfPinnedObject().ToPointer();
                #endregion
                #region ENDING_UPPER_BUFFER
                var ending_upper_buffer = new char[ENDING_BUFFER_SIZE];
                _ENDING_UPPER_BUFFER_GCHandle = GCHandle.Alloc(ending_upper_buffer, GCHandleType.Pinned);
                _ENDING_UPPER_BUFFER          = (char *)_ENDING_UPPER_BUFFER_GCHandle.AddrOfPinnedObject().ToPointer();
                #endregion
            }
Пример #4
0
        /// добавление слова и всех его форм в словарь
        /// wordBase   - marshaled-слово
        /// morphoType - морфотип
        /// nounType   - тип сущетсвительного
        public void AddWord(char *wordBase, MorphoTypeNative morphoType, ref MorphoAttributePair?nounType)
        {
            var baseMorphoForm = new BaseMorphoFormNative(wordBase, morphoType);

            for (TreeDictionaryNative _this = this, _this_next; ;)
            {
                var first_char = _UPPER_INVARIANT_MAP[*wordBase];

                #region [.сохранение характеристик if end-of-word.]
                if (first_char == '\0')
                {
                    var len = morphoType.MorphoFormEndingUpperAndMorphoAttributes.Length;
                    SortedListIntPtrKey <Pair[]> .Tuple[] tuples;
                    int tuplesOffset;
                    if (!_this.HasEndings())
                    {
                        tuplesOffset = 0;
                        tuples       = new SortedListIntPtrKey <Pair[]> .Tuple[len];
                    }
                    else
                    {
                        tuplesOffset = _this._endings.Count;
                        tuples       = new SortedListIntPtrKey <Pair[]> .Tuple[len + tuplesOffset];

                        for (int i = 0; i < tuplesOffset; i++)
                        {
                            tuples[i] = _this._endings.Array[i];
                        }
                    }

                    for (int i = 0; i < len; i++)
                    {
                        var p = morphoType.MorphoFormEndingUpperAndMorphoAttributes[i];
                        var pairs_current_len = p.MorphoAttributes.Length;
                        var pairs_current     = new Pair[pairs_current_len];
                        for (int j = 0; j < pairs_current_len; j++)
                        {
                            var ma = MorphoAttributePair.GetMorphoAttribute(morphoType, p.MorphoAttributes[j], ref nounType);
                            pairs_current[j] = new Pair(baseMorphoForm, ma);
                        }
                        tuples[i + tuplesOffset] = new SortedListIntPtrKey <Pair[]> .Tuple()
                        {
                            Key = p.EndingUpper, Value = pairs_current
                        };
                    }

                    ShellSortAscending(tuples);
                    MergeSorted(ref tuples);
                    _this._endings.SetArray(tuples);
                    return;
                }
                #endregion

                if (!_this._slots.TryGetValue(first_char, out _this_next))
                {
                    /// добавление новой буквы
                    _this_next = new TreeDictionaryNative();
                    _this._slots.Add(first_char, _this_next);
                }
                _this = _this_next;
                wordBase++;
            }
        }