Example #1
0
        public static IMorphoModel Create(MorphoModelConfig config)
        {
            config.ThrowIfNull("config");

            switch (config.TreeDictionaryType)
            {
            case MorphoModelConfig.TreeDictionaryTypeEnum.Classic:
            case MorphoModelConfig.TreeDictionaryTypeEnum.FastMemPlenty:
            {
                var model = new MorphoModel(config);

                return(model);
            }

            case MorphoModelConfig.TreeDictionaryTypeEnum.Native:
            {
                var model = new MorphoModelNative(config);

                return(model);
            }

            default:
                throw (new ArgumentException(config.TreeDictionaryType.ToString()));
            }
        }
Example #2
0
 private static void CheckConfig(MorphoModelConfig config)
 {
     config.ThrowIfNull("config");
     config.MorphoTypesFilenames.ThrowIfNullOrWhiteSpaceAnyElement("config.MorphoTypesFilenames");
     config.ProperNamesFilenames.ThrowIfNullOrWhiteSpaceAnyElement("config.ProperNamesFilenames");
     config.CommonFilenames.ThrowIfNullOrWhiteSpaceAnyElement("config.CommonFilenames");
 }
Example #3
0
        public MorphoModelNative(MorphoModelConfig config) : base(config)
        {
            _TreeDictionary = new TreeDictionaryNative();

            using (var loader = new ModelLoader(config, _TreeDictionary))
            {
                _EndingsNativeKeeper = loader.Run();
            }
        }
Example #4
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);
        }
Example #5
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;
 }
Example #6
0
        public MorphoModel(MorphoModelConfig config) : base(config)
        {
            switch (config.TreeDictionaryType)
            {
            case MorphoModelConfig.TreeDictionaryTypeEnum.Classic:
                _TreeDictionary = new TreeDictionaryClassic();
                break;

            case MorphoModelConfig.TreeDictionaryTypeEnum.FastMemPlenty:
                _TreeDictionary = new TreeDictionaryFastMemPlenty();
                break;

            default:
                throw (new ArgumentException(config.TreeDictionaryType.ToString()));
            }

            Initialization(config);
        }
Example #7
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
            }
Example #8
0
 protected MorphoModelBase(MorphoModelConfig config)
 {
     CheckConfig(config);
 }