Ejemplo n.º 1
0
 unsafe public bool GetWordFormMorphologies(char *wordUpper, List <WordFormMorphology> result, WordFormMorphologyModeEnum wordFormMorphologyMode)
 {
     result.Clear();
     {
         var fullWordLength = StringsHelper.GetLength(wordUpper);
         FillWordFormMorphologies(wordUpper, fullWordLength, fullWordLength, result, wordFormMorphologyMode);
     }
     return(result.Count != 0);
 }
Ejemplo n.º 2
0
        public bool TryGetProbability(ref NativeOffset no, out double probability)
        {
            if (_Set.TryGetValue(ref no, out var existsValue))
            {
#if DEBUG
                var len = StringsHelper.GetLength(existsValue);
                Debug.Assert(len == no.Length);
#endif
                probability = ToProbability(existsValue, no.Length + 1);   //--- len + 1 );
                return(true);
            }
            probability = default(double);
            return(false);
        }
Ejemplo n.º 3
0
        unsafe public bool TryGetProbability(string ngram, out double probability)
        {
            fixed(char *ngramPtr = ngram)
            {
                if (_Set.TryGetValue((IntPtr)ngramPtr, out var existsValue))
                {
#if DEBUG
                    var len = StringsHelper.GetLength(existsValue);
                    Debug.Assert(len == ngram.Length);
#endif
                    probability = ToProbability(existsValue, ngram.Length + 1);
                    return(true);
                }
            }

            probability = default(double);
            return(false);
        }
Ejemplo n.º 4
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);
                        }
                    }
                }
            }