Exemplo n.º 1
0
        /// создание морфотипа из строки
        private MorphoTypePair?CreateMorphoTypePair(string line)
        {
            var m = MORPHOTYPE_PREFIX_REGEXP.Match(line);

            if (m == null || m.Groups.Count < 3)
            {
                return(null);
            }

            string prefix = m.Groups[1].Value;
            string pos    = m.Groups[2].Value;
            string name   = line.Substring(prefix.Length);

            var partOfSpeech = default(PartOfSpeechEnum);

            if (Enum.TryParse(pos, true, out partOfSpeech))
            {
                var morphoType     = new MorphoType(_PartOfSpeechList.GetPartOfSpeech(partOfSpeech));
                var morphoTypePair = new MorphoTypePair()
                {
                    Name       = name,
                    MorphoType = morphoType,
                };
                return(morphoTypePair);
            }
            else
            {
                _ModelLoadingErrorCallback("Unknown part-of-speech: '" + pos + '\'', line);
            }
            return(null);
        }
Exemplo n.º 2
0
            /// <summary>
            /// создание морфотипа из строки
            /// </summary>
            private MorphoTypeNative_pair_t?CreateMorphoTypePair(char *lineBase, int lineLength)
            {
                var index1 = IndexOf(lineBase, COMMA);

                if (index1 == -1)
                {
                    return(null);
                }
                var index2 = IndexAfter_MORPHO_TYPE(lineBase + index1 + 1);

                if (index2 == -1)
                {
                    return(null);
                }

                var partOfSpeech = default(PartOfSpeechEnum);

                if (_EnumParserPartOfSpeech.TryParse(lineBase, index1, ref partOfSpeech))
                {
                    var    startIndex = index1 + 1 + index2 + 1;
                    IntPtr namePtr;
                    AllocHGlobalAndCopy(lineBase + startIndex, lineLength - startIndex, out namePtr);

                    var morphoType     = new MorphoTypeNative(_PartOfSpeechList.GetPartOfSpeech(partOfSpeech));
                    var morphoTypePair = new MorphoTypeNative_pair_t()
                    {
                        Name       = namePtr,
                        MorphoType = morphoType,
                    };
                    return(morphoTypePair);
                }
                else
                {
                    var pos = StringsHelper.ToString(lineBase, index1);
                    _ModelLoadingErrorCallback("Unknown part-of-speech: '" + pos + '\'', StringsHelper.ToString(lineBase));
                }
                return(null);
            }