Exemple #1
0
        /// инициализация морфо-модели
        /// информация для инициализации морфо-модели
        private void Initialization(MorphoModelConfig config)
        {
            #region init fields
            base.Initialization();
            if (config.ModelLoadingErrorCallback == null)
            {
                _ModelLoadingErrorCallback = (s1, s2) => { };
            }
            else
            {
                _ModelLoadingErrorCallback = config.ModelLoadingErrorCallback;
            }
            _MorphoTypesDictionary        = new Dictionary <string, MorphoType>();
            _MorphoAttributeList          = new MorphoAttributeList();
            _PartOfSpeechList             = new PartOfSpeechList();
            _PartOfSpeechStringDictionary = Enum.GetValues(typeof(PartOfSpeechEnum))
                                            .Cast <PartOfSpeechEnum>()
                                            .ToDictionary(pos => pos, pos => pos.ToString());
            #endregion

            foreach (var morphoTypesFilename in config.MorphoTypesFilenames)
            {
                var filename = GetFullFilename(config.BaseDirectory, morphoTypesFilename);
                ReadMorphoTypes(filename);
            }

            foreach (var properNamesFilename in config.ProperNamesFilenames)
            {
                var filename = GetFullFilename(config.BaseDirectory, properNamesFilename);
                ReadWords(filename, MorphoAttributeEnum.Proper);
            }

            foreach (var commonFilename in config.CommonFilenames)
            {
                var filename = GetFullFilename(config.BaseDirectory, commonFilename);
                ReadWords(filename, MorphoAttributeEnum.Common);
            }

            #region uninit fields
            base.UnInitialization();
            _ModelLoadingErrorCallback    = null;
            _MorphoTypesDictionary        = null;
            _MorphoAttributeList          = null;
            _PartOfSpeechList             = null;
            _PartOfSpeechStringDictionary = null;
            #endregion

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        }
 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;
 }
            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
            }