예제 #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(MorphoType_pair_t?);

            foreach (var line in lines)
            {
                //if ( line == "Pronoun, MORPHO_TYPE:что" )
                //  System.Diagnostics.Debugger.Break();

                MorphoType_pair_t?_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);
                            //---morphoTypePairLast.Value.MorphoType.AddMorphoForm( morphoForm );
                        }
                        else
                        {
                            _ModelLoadingErrorCallback("Wrong line format", line);   //throw (new MorphoFormatException());
                        }
                    }
                    catch (MorphoFormatException /*ex*/)
                    {
                        _ModelLoadingErrorCallback("Wrong line format", line);
                    }
                }
                else
                {
                    _ModelLoadingErrorCallback("Null MorphoType", line);   //throw (new NullPointerException());
                }
            }

            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))
                {
                    var morphoAttribute = default(MorphoAttributeEnum);
                    if (Enum.TryParse(attr, true, out morphoAttribute))
                    {
                        //---morphoAttributePairs.Add( _MorphoAttributeList.GetMorphoAttributePair( morphoType.MorphoAttributeGroup, 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 'lingvo-[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);
        }