Пример #1
0
        /// чтение файла морфотипов
        /// path - полный путь к файлу
        private void ReadMorphoTypes(string filename)
        {
            var lines = ReadFile(filename);
            var morphoAttributePairs = new List <MorphoAttributePair>();
            var morphoForms          = new List <MorphoForm>();

            var morphoTypePairLast = default(MorphoTypePair?);

            foreach (var line in lines)
            {
                MorphoTypePair?_morphoTypePair = CreateMorphoTypePair(line);
                if (_morphoTypePair != null) /// новый морфо-тип
                {
                    if (morphoTypePairLast != null)
                    {
                        morphoTypePairLast.Value.MorphoType.SetMorphoForms(morphoForms);

                        AddMorphoType2Dictionary(morphoTypePairLast);
                    }
                    morphoForms.Clear();

                    morphoTypePairLast = _morphoTypePair;
                }
                else /// словоформа
                if (morphoTypePairLast != null)
                {
                    try
                    {
                        MorphoForm morphoForm = CreateMorphoForm(morphoTypePairLast.Value.MorphoType, line, morphoAttributePairs);
                        if (morphoForm != null)
                        {
                            morphoForms.Add(morphoForm);
                        }
                        else
                        {
                            _ModelLoadingErrorCallback("Wrong line format", line);
                        }
                    }
                    catch (MorphoFormatException)
                    {
                        _ModelLoadingErrorCallback("Wrong line format", line);
                    }
                }
                else
                {
                    _ModelLoadingErrorCallback("Null MorphoType", line);
                }
            }

            if (morphoTypePairLast != null)
            {
                morphoTypePairLast.Value.MorphoType.SetMorphoForms(morphoForms);

                AddMorphoType2Dictionary(morphoTypePairLast);
            }
        }
Пример #2
0
        /// создание морфоформы из строки
        private MorphoForm CreateMorphoForm(MorphoType morphoType, string line, List <MorphoAttributePair> morphoAttributePairs)
        {
            int index = line.IndexOf(':');

            if (index < 0)
            {
                throw (new MorphoFormatException());
            }

            var ending = StringsHelper.ToLowerInvariant(line.Substring(0, index).Trim());

            if (ending == EMPTY_ENDING)
            {
                ending = string.Empty;
            }

            morphoAttributePairs.Clear();
            var attributes = line.Substring(index + 1).Split(MORPHO_ATTRIBUTE_SEPARATOR, StringSplitOptions.RemoveEmptyEntries);

            foreach (var attribute in attributes)
            {
                var attr = attribute.Trim();
                if (!string.IsNullOrEmpty(attr))
                {
                    if (Enum.TryParse(attr, true, out MorphoAttributeEnum morphoAttribute))
                    {
                        var map = _MorphoAttributeList.TryGetMorphoAttributePair(morphoType.MorphoAttributeGroup, morphoAttribute);
                        if (map.HasValue)
                        {
                            morphoAttributePairs.Add(map.Value);
                        }
#if DEBUG
                        //TOO MANY ERRORS AFTER last (2016.12.28) getting morpho-dcitionaries from 'LangAnalyzerStd-[ilook]'
                        else
                        {
                            _ModelLoadingErrorCallback("Error in morpho-attribute: '" + attr + '\'', line);
                        }
#endif
                    }
                    else
                    {
                        _ModelLoadingErrorCallback("Unknown morpho-attribute: '" + attr + '\'', line);
                    }
                }
            }
            var morphoForm = new MorphoForm(ending, morphoAttributePairs);
            return(morphoForm);
        }
Пример #3
0
        /// получение морфологической информации по форме слова
        /// pWordFormInfo - морфологическая информация о форме слова
        /// morphologyPropertyCount [out] - количество атрибутов
        unsafe public static MorphoAttributeEnum GetMorphoAttribute(BaseMorphoForm baseMorphoForm, MorphoForm morphoForm)
        {
            var result = default(MorphoAttributeEnum);

            var morphoAttributeGroup = baseMorphoForm.MorphoAttributeGroup;

            fixed(MorphoAttributePair *map_ptr = morphoForm.MorphoAttributePairs)
            {
                for (int i = 0, len = morphoForm.MorphoAttributePairs.Length; i < len; i++)
                {
                    var morphoAttributePair = (map_ptr + i);
                    if ((morphoAttributeGroup & morphoAttributePair->MorphoAttributeGroup) == morphoAttributePair->MorphoAttributeGroup)
                    {
                        result |= morphoAttributePair->MorphoAttribute;
                    }
                    else
                    {
                        throw new WrongAttributeException();
                    }
                }
            }

            if (baseMorphoForm.NounType.HasValue)
            {
                var morphoAttributePair = baseMorphoForm.NounType.Value;
                if ((morphoAttributeGroup & morphoAttributePair.MorphoAttributeGroup) == morphoAttributePair.MorphoAttributeGroup)
                {
                    result |= morphoAttributePair.MorphoAttribute;
                }
                else
                {
                    throw new WrongAttributeException();
                }
            }

            return(result);
        }