コード例 #1
0
        public static byte get_Mood(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Imperative) == MorphoAttributeEnum.Imperative)
            {
                return((byte)'M');
            }
            if ((ma & MorphoAttributeEnum.Indicative) == MorphoAttributeEnum.Indicative)
            {
                return((byte)'N');
            }
            if ((ma & MorphoAttributeEnum.Subjunctive) == MorphoAttributeEnum.Subjunctive)
            {
                return((byte)'S');
            }
            if ((ma & MorphoAttributeEnum.Personal) == MorphoAttributeEnum.Personal)
            {
                return((byte)'P');
            }
            if ((ma & MorphoAttributeEnum.Impersonal) == MorphoAttributeEnum.Impersonal)
            {
                return((byte)'I');
            }
            if ((ma & MorphoAttributeEnum.Gerund) == MorphoAttributeEnum.Gerund)
            {
                return((byte)'G');
            }
            if ((ma & MorphoAttributeEnum.Participle) == MorphoAttributeEnum.Participle)
            {
                return((byte)'R');
            }

            return(U_BYTE);
        }
コード例 #2
0
        private static bool Case_2_TryFilterByMask(MorphoAttributeEnum mask, MorphoAttributeEnum ma, List <MorphoAmbiguityTuple_t> mats)
        {
            var len = mats.Count - 1;

            if (0 < len)
            {
                ma = ma & mask;
                for (var i = len; 0 <= i; i--)
                {
                    var mat = mats[i];
                    if (ma == (mat.WordFormMorphology.MorphoAttribute & mask))
                    {
                        for (i = len; 0 <= i; i--)
                        {
                            mat = mats[i];
                            if (ma != (mat.WordFormMorphology.MorphoAttribute & mask))
                            {
                                mats.RemoveAt(i);
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        public static byte get_PronounType(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Interrogative) == MorphoAttributeEnum.Interrogative)
            {
                return((byte)'I');
            }
            if ((ma & MorphoAttributeEnum.InterrogativeRelative) == MorphoAttributeEnum.InterrogativeRelative)
            {
                return((byte)'R');
            }
            if ((ma & MorphoAttributeEnum.Negative) == MorphoAttributeEnum.Negative)
            {
                return((byte)'N');
            }
            if ((ma & MorphoAttributeEnum.Reflexive) == MorphoAttributeEnum.Reflexive)
            {
                return((byte)'F');
            }
            if ((ma & MorphoAttributeEnum.Indefinitive1) == MorphoAttributeEnum.Indefinitive1)
            {
                return((byte)'A');
            }
            if ((ma & MorphoAttributeEnum.Indefinitive2) == MorphoAttributeEnum.Indefinitive2)
            {
                return((byte)'B');
            }
            if ((ma & MorphoAttributeEnum.Possessive) == MorphoAttributeEnum.Possessive)
            {
                return((byte)'P');
            }

            return(U_BYTE);
        }
コード例 #4
0
 public WordFormMorphology(IBaseMorphoForm baseMorphoForm, MorphoAttributeEnum morphoAttribute)
     : this()
 {
     _NormalForm     = baseMorphoForm.NormalForm;
     PartOfSpeech    = baseMorphoForm.PartOfSpeech;
     MorphoAttribute = morphoAttribute;
 }
コード例 #5
0
 public WordFormMorphology_t(IBaseMorphoFormNative baseMorphoForm, MorphoAttributeEnum morphoAttribute) : this()
 {
     _Base           = baseMorphoForm.Base;
     _Ending         = baseMorphoForm.MorphoFormEndings[0];
     PartOfSpeech    = baseMorphoForm.PartOfSpeech;
     MorphoAttribute = morphoAttribute;
 }
コード例 #6
0
        /// чтение файла со словами
        /// path - полный путь к файлу
        /// nounType - тип существительного
        private void ReadWords(string filename, MorphoAttributeEnum nounType)
        {
            var lines = ReadFile(filename);

            foreach (var line in lines)
            {
                #region commented
                //try
                //{
                #endregion
                var array = line.Split(WORDS_DICTIONARY_SEPARATOR, StringSplitOptions.RemoveEmptyEntries);
                if (array.Length != 3)
                {
                    _ModelLoadingErrorCallback("Wrong line format", line);   //throw (new MorphoFormatException());
                    continue;
                }

                MorphoType morphoType = GetMorphoTypeByName(array[1]);
                if (morphoType == null)
                {
                    _ModelLoadingErrorCallback("Unknown morpho-type", line);   //throw new UnknownMorphoTypeException();
                }
                else
                if (array[2] != _PartOfSpeechStringDictionary[morphoType.PartOfSpeech])
                {
                    _ModelLoadingErrorCallback("Wrong part-of-speech", line);   //throw new WrongPartOfSpeechException();
                }
                else
                {
                    var word = array[0];

                    /*
                     * if ( word == "коем" )
                     *  System.Diagnostics.Debugger.Break();
                     * //*/

                    var _nounType = default(MorphoAttributePair?);
                    if ((morphoType.MorphoAttributeGroup & MorphoAttributeGroupEnum.NounType) == MorphoAttributeGroupEnum.NounType)
                    {
                        _nounType = _MorphoAttributeList.GetMorphoAttributePair(MorphoAttributeGroupEnum.NounType, nounType);
                    }
                    _TreeDictionary.AddWord(word, morphoType, _nounType);
                }
                #region commented
                //}
                //catch (UnknownMorphoTypeException)
                //{
                //    CMorphoModel::Logging("Unknown MorphoType", str);
                //    m_isInitialized = false;
                //}
                //catch (WrongPartOfSpeechException)
                //{
                //    CMorphoModel::Logging("Wrong PartOfSpeech", str);
                //    m_isInitialized = false;
                //}
                #endregion
            }
        }
コード例 #7
0
        public static byte get_Form(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Short) == MorphoAttributeEnum.Short)
            {
                return((byte)'S');
            }

            return(U_BYTE);
        }
コード例 #8
0
        public MorphoAttributePair?TryGetMorphoAttributePair(
            MorphoAttributeGroupEnum morphoAttributeGroup,
            MorphoAttributeEnum morphoAttribute)
        {
            if (_Set.TryGetValue(morphoAttributeGroup, morphoAttribute, ref _Pair))
            {
                return(_Pair);
            }

            return(null);
        }
コード例 #9
0
        /// создание морфоатрибута из строки
        /// attribute - строка со значением атрибута
        /// attributeType - тип атрибута
        public MorphoAttributePair GetMorphoAttributePair(
            MorphoAttributeGroupEnum morphoAttributeGroup,
            MorphoAttributeEnum morphoAttribute)
        {
            if (_Set.TryGetValue(morphoAttributeGroup, morphoAttribute, ref _Pair))
            {
                return(_Pair);
            }

            throw new MorphoFormatException();
        }
コード例 #10
0
        public static byte get_NounType(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Proper) == MorphoAttributeEnum.Proper)
            {
                return((byte)'P');
            }
            if ((ma & MorphoAttributeEnum.Common) == MorphoAttributeEnum.Common)
            {
                return((byte)'C');
            }

            return(U_BYTE);
        }
コード例 #11
0
        public static byte get_ConjunctionType(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Coordinating) == MorphoAttributeEnum.Coordinating)
            {
                return((byte)'C');
            }
            if ((ma & MorphoAttributeEnum.Subordinating) == MorphoAttributeEnum.Subordinating)
            {
                return((byte)'S');
            }

            return(U_BYTE);
        }
コード例 #12
0
        public static byte get_VerbTransitivity(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Transitive) == MorphoAttributeEnum.Transitive)
            {
                return((byte)'T');
            }
            if ((ma & MorphoAttributeEnum.Intransitive) == MorphoAttributeEnum.Intransitive)
            {
                return((byte)'I');
            }

            return(U_BYTE);
        }
コード例 #13
0
        public static byte get_Voice(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Active) == MorphoAttributeEnum.Active)
            {
                return((byte)'A');
            }
            if ((ma & MorphoAttributeEnum.Passive) == MorphoAttributeEnum.Passive)
            {
                return((byte)'P');
            }

            return(U_BYTE);
        }
コード例 #14
0
        public static byte get_Number(MorphoAttributeEnum ma)
        {
            if ((ma & MorphoAttributeEnum.Singular) == MorphoAttributeEnum.Singular)
            {
                return((byte)'S');
            }
            if ((ma & MorphoAttributeEnum.Plural) == MorphoAttributeEnum.Plural)
            {
                return((byte)'P');
            }

            return(U_BYTE);
        }
コード例 #15
0
        public MorphoAttributePair GetMorphoAttributePair_2(
            MorphoAttributeGroupEnum morphoAttributeGroup,
            MorphoAttributeEnum morphoAttribute)
        {
            var pair = default(MorphoAttributePair);

            if (_Set.TryGetValue(morphoAttributeGroup, morphoAttribute, ref pair))
            {
                return(pair);
            }

            throw new MorphoFormatException();
        }
コード例 #16
0
            public bool Contains(MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
            {
                int hash = InternalGetHashCode(morphoAttributeGroup, morphoAttribute);

                for (int i = _Buckets[hash % _Buckets.Length] - 1; 0 <= i;)
                {
                    var slot = _Slots[i];
                    if ((slot.hashCode == hash) && IsEquals(ref slot.value, morphoAttributeGroup, morphoAttribute))
                    {
                        return(true);
                    }
                    i = slot.next;
                }

                return(false);
            }
コード例 #17
0
        public MorphoAttributePair?TryGetMorphoAttributePair(
            MorphoAttributeGroupEnum morphoAttributeGroup,
            MorphoAttributeEnum morphoAttribute)
        {
            for (int i = _morphoAttributePairsLength_Minus1; 0 <= i; i--)
            {
                var morphoAttributePair = (_morphoAttributePairsBasePtr + i);
                if ((morphoAttributeGroup & morphoAttributePair->MorphoAttributeGroup) == morphoAttributeGroup &&
                    (morphoAttribute & morphoAttributePair->MorphoAttribute) == morphoAttribute)
                {
                    return(*morphoAttributePair);
                }
            }

            return(null);
        }
コード例 #18
0
        /// создание морфоатрибута из строки
        /// attribute - строка со значением атрибута
        /// attributeType - тип атрибута
        public MorphoAttributePair GetMorphoAttributePair(
            MorphoAttributeGroupEnum morphoAttributeGroup,
            MorphoAttributeEnum morphoAttribute)
        {
            {
                for (int i = _morphoAttributePairsLength_Minus1; 0 <= i; i--)
                {
                    var morphoAttributePair = (_morphoAttributePairsBasePtr + i);
                    if ((morphoAttributeGroup & morphoAttributePair->MorphoAttributeGroup) == morphoAttributeGroup &&
                        (morphoAttribute & morphoAttributePair->MorphoAttribute) == morphoAttribute)
                    {
                        return(*morphoAttributePair);
                    }
                }
            }

            throw new MorphoFormatException();
        }
コード例 #19
0
        unsafe public static MorphoAttributeEnum GetMorphoAttribute(
            MorphoTypeNative morphoType,
            MorphoAttributeEnum morphoAttribute,
            ref MorphoAttributePair?nounType)
        {
            if (nounType.HasValue)
            {
                var morphoAttributeGroup = morphoType.MorphoAttributeGroup;
                var morphoAttributePair  = nounType.Value;
                if ((morphoAttributeGroup & morphoAttributePair.MorphoAttributeGroup) == morphoAttributePair.MorphoAttributeGroup)
                {
                    morphoAttribute |= morphoAttributePair.MorphoAttribute;
                }
                else
                {
                    throw (new WrongAttributeException());
                }
            }

            return(morphoAttribute);
        }
コード例 #20
0
        public static byte get_Case(MorphoAttributeEnum ma)
        {
            //var ma = word.morphology.MorphoAttribute;
            if ((ma & MorphoAttributeEnum.Nominative) == MorphoAttributeEnum.Nominative)
            {
                return((byte)'N');
            }
            if ((ma & MorphoAttributeEnum.Genitive) == MorphoAttributeEnum.Genitive)
            {
                return((byte)'G');
            }
            if ((ma & MorphoAttributeEnum.Dative) == MorphoAttributeEnum.Dative)
            {
                return((byte)'D');
            }
            if ((ma & MorphoAttributeEnum.Accusative) == MorphoAttributeEnum.Accusative)
            {
                return((byte)'A');
            }
            if ((ma & MorphoAttributeEnum.Instrumental) == MorphoAttributeEnum.Instrumental)
            {
                return((byte)'I');
            }
            if ((ma & MorphoAttributeEnum.Prepositional) == MorphoAttributeEnum.Prepositional)
            {
                return((byte)'P');
            }
            if ((ma & MorphoAttributeEnum.Locative) == MorphoAttributeEnum.Locative)
            {
                return((byte)'L');
            }
            if ((ma & MorphoAttributeEnum.Anycase) == MorphoAttributeEnum.Anycase)
            {
                return((byte)'H');
            }

            return(U_BYTE);
        }
コード例 #21
0
ファイル: MorphoModel.cs プロジェクト: lavrenkova/sw-auto
        /// чтение файла со словами
        /// 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);
                }
            }
        }
コード例 #22
0
 private static bool IsGenderGeneral(MorphoAttributeEnum morphoAttribute) => ((morphoAttribute & MorphoAttributeEnum.General) == MorphoAttributeEnum.General);
コード例 #23
0
 public MorphoFormEndingUpperAndMorphoAttribute(IntPtr endingUpper, LinkedList <MorphoAttributeEnum> morphoAttributes)
 {
     EndingUpper      = endingUpper;
     MorphoAttributes = new MorphoAttributeEnum[morphoAttributes.Count];
     morphoAttributes.CopyTo(MorphoAttributes, 0);
 }
コード例 #24
0
            /// чтение файла со словами
            /// 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);
                        }
                    }
                }
            }
コード例 #25
0
 private static bool IsCaseAnycase(MorphoAttributeEnum morphoAttribute) => ((morphoAttribute & MorphoAttributeEnum.Anycase) == MorphoAttributeEnum.Anycase);
コード例 #26
0
 public pair_t(BaseMorphoForm baseMorphoForm, MorphoAttributeEnum morphoAttribute)
 {
     BaseMorphoForm  = baseMorphoForm;
     MorphoAttribute = morphoAttribute;
 }
コード例 #27
0
 public Pair(BaseMorphoFormNative baseMorphoForm, MorphoAttributeEnum morphoAttribute)
 {
     BaseMorphoForm  = baseMorphoForm;
     MorphoAttribute = morphoAttribute;
 }
コード例 #28
0
 private static bool IsEquals(ref MorphoAttributePair v1, MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
 {
     return((v1.MorphoAttributeGroup & morphoAttributeGroup) == morphoAttributeGroup &&
            (v1.MorphoAttribute & morphoAttribute) == morphoAttribute);
 }
コード例 #29
0
 public MorphoAttributePair(MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
 {
     _MorphoAttributeGroup = morphoAttributeGroup;
     _MorphoAttribute      = morphoAttribute;
 }
コード例 #30
0
 private static int InternalGetHashCode(MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
 {
     return((morphoAttributeGroup.GetHashCode() ^ morphoAttribute.GetHashCode()) & 0x7fffffff);
 }