/// чтение файла со словами /// path - полный путь к файлу /// nounType - тип существительного private void ReadWords(string filename, MorphoAttributeEnum nounType) { var lines = ReadFile(filename); foreach (var line in lines) { var array = line.Split(WORDS_DICTIONARY_SEPARATOR, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 3) { _ModelLoadingErrorCallback("Wrong line format", line); continue; } MorphoType morphoType = GetMorphoTypeByName(array[1]); if (morphoType == null) { _ModelLoadingErrorCallback("Unknown morpho-type", line); } else if (array[2] != _PartOfSpeechStringDictionary[morphoType.PartOfSpeech]) { _ModelLoadingErrorCallback("Wrong part-of-speech", line); } else { var word = array[0]; var _nounType = default(MorphoAttributePair?); if ((morphoType.MorphoAttributeGroup & MorphoAttributeGroupEnum.NounType) == MorphoAttributeGroupEnum.NounType) { _nounType = _MorphoAttributeList.GetMorphoAttributePair(MorphoAttributeGroupEnum.NounType, nounType); } _TreeDictionary.AddWord(word, morphoType, _nounType); } } }
/// чтение файла со словами /// path - полный путь к файлу /// nounType - тип существи тельного private void ReadWords(string filename, MorphoAttributeEnum nounType) { var lines = ReadFile(filename); var plw = default(ParsedLineWords_unsafe); foreach (var line in lines) { fixed(char *lineBase = line) { if (!ParseLineWords(lineBase, ref plw)) { _ModelLoadingErrorCallback("Wrong line format", line); continue; } MorphoTypeNative morphoType = GetMorphoTypeByName((IntPtr)plw.MorphoTypeName); if (morphoType == null) { _ModelLoadingErrorCallback("Unknown morpho-type", line); continue; } if (!StringsHelper.IsEqual((IntPtr)plw.PartOfSpeech, _PartOfSpeechToNativeStringMapper[morphoType.PartOfSpeech])) { _ModelLoadingErrorCallback("Wrong part-of-speech", line); continue; } if (morphoType.HasMorphoForms) { var nounTypePair = default(MorphoAttributePair?); if ((morphoType.MorphoAttributeGroup & MorphoAttributeGroupEnum.NounType) == MorphoAttributeGroupEnum.NounType) { nounTypePair = _MorphoAttributeList.GetMorphoAttributePair(MorphoAttributeGroupEnum.NounType, nounType); } #region Allocate native-memory for baseOfWord var len = plw.WordLength - StringsHelper.GetLength(morphoType.FirstEnding); len = ((0 <= len) ? len : plw.WordLength); IntPtr lineBasePtr; if (0 < len) { *(lineBase + len) = '\0'; lineBasePtr = new IntPtr(lineBase); if (_EndingDictionary.TryGetValue(lineBasePtr, out IntPtr existsPtr)) { lineBasePtr = existsPtr; } else { AllocHGlobalAndCopy(lineBase, len, out lineBasePtr); _EndingDictionary.Add(lineBasePtr, lineBasePtr); } } else { lineBasePtr = _EMPTY_STRING; } #endregion _TreeDictionary.AddWord((char *)lineBasePtr, morphoType, ref nounTypePair); } } } }