/// добавление части слова
        /// wordPart - оставшася часть слова
        /// pBase - базовая форма
        unsafe private void AddWordPart(char *wordPart, BaseMorphoForm baseMorphoForm)
        {
            var first_char = *wordPart;

            if (first_char == '\0')
            /// сохранение характеристик
            {
                var tuples = from morphoForm in baseMorphoForm.MorphoForms
                             select new
                {
                    ending = morphoForm.EndingUpper,
                    baseMorphoForm,
                    morphoForm,
                };
                var dict = new Dictionary <string, LinkedList <Pair> >();
                foreach (var t in tuples)
                {
                    if (!dict.TryGetValue(t.ending, out LinkedList <Pair> pairs))
                    {
                        pairs = new LinkedList <Pair>();
                        dict.Add(t.ending, pairs);
                    }
                    pairs.AddLast(new Pair(t.baseMorphoForm, MorphoAttributePair.GetMorphoAttribute(t.baseMorphoForm, t.morphoForm)));
                }

                if (_EndingDictionary == null)
                {
                    _EndingDictionary = new Dictionary <string, Pair[]>();
                }
                foreach (var p in dict)
                {
                    if (!_EndingDictionary.TryGetValue(p.Key, out Pair[] pairs))
Esempio n. 2
0
        internal void SetMorphoForms(List <MorphoFormNative> morphoForms)
        {
            if (morphoForms.Count != 0)
            {
                LinkedList <MorphoAttributeEnum> morphoAttributes = null;
                for (int i = 0, len = morphoForms.Count; i < len; i++)
                {
                    var morphoForm = morphoForms[i];

                    tempBufferHS.Add((IntPtr)morphoForm.Ending);

                    var endingUpperPtr = (IntPtr)morphoForm.EndingUpper;
                    if (!tempBufferDict.TryGetValue(endingUpperPtr, ref morphoAttributes))
                    {
                        morphoAttributes = PopLinkedList();
                        tempBufferDict.Add(endingUpperPtr, morphoAttributes);
                    }
                    var morphoAttribute = MorphoAttributePair.GetMorphoAttribute(this, morphoForm);
                    morphoAttributes.AddLast(morphoAttribute);
                }

                _morphoFormEndings = new char *[tempBufferHS.Count];
                fixed(char **morphoFormEndingsBase = _morphoFormEndings)
                {
                    var it = tempBufferHS.GetEnumerator();

                    for (var i = 0; it.MoveNext(); i++)
                    {
                        *(morphoFormEndingsBase + i) = (char *)it.Current;
                    }
                }

                tempBufferHS.Clear();

                _morphoFormEndingUpperAndMorphoAttributes = new MorphoFormEndingUpperAndMorphoAttribute[tempBufferDict.Count];

                var it2 = tempBufferDict.GetEnumerator();
                for (var i = 0; it2.MoveNext(); i++)
                {
                    _morphoFormEndingUpperAndMorphoAttributes[i] =
                        new MorphoFormEndingUpperAndMorphoAttribute(it2.Current_IntPtr, it2.Current_Value);
                    PushLinkedList(it2.Current_Value);
                }

                tempBufferDict.Clear();
            }
            else
            {
                _morphoFormEndings = EMPTY_ENDINGS;
                _morphoFormEndingUpperAndMorphoAttributes = EMPTY_MFUEMA;
            }
        }
Esempio n. 3
0
            public bool Add(ref MorphoAttributePair value)
            {
                int hash = InternalGetHashCode(ref value);

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

                {
                    int n1;
                    if (0 <= _FreeList)
                    {
                        n1        = _FreeList;
                        _FreeList = _Slots[n1].next;
                    }
                    else
                    {
                        if (_Count == _Slots.Length)
                        {
                            Resize();
                        }
                        n1 = _Count;
                        _Count++;
                    }
                    int n2 = hash % _Buckets.Length;
                    _Slots[n1] = new Slot()
                    {
                        hashCode = hash,
                        value    = value,
                        next     = _Buckets[n2] - 1,
                    };
                    _Buckets[n2] = n1 + 1;
                }

                return(true);
            }
Esempio n. 4
0
        /// добавление слова и всех его форм в словарь
        /// wordBase   - marshaled-слово
        /// morphoType - морфотип
        /// nounType   - тип сущетсвительного
        public void AddWord(char *wordBase, MorphoTypeNative morphoType, ref MorphoAttributePair?nounType)
        {
            var baseMorphoForm = new BaseMorphoFormNative(wordBase, morphoType);

            for (TreeDictionaryNative _this = this, _this_next; ;)
            {
                var first_char = _UPPER_INVARIANT_MAP[*wordBase];

                #region [.сохранение характеристик if end-of-word.]
                if (first_char == '\0')
                {
                    var len = morphoType.MorphoFormEndingUpperAndMorphoAttributes.Length;
                    SortedListIntPtrKey <Pair[]> .Tuple[] tuples;
                    int tuplesOffset;
                    if (!_this.HasEndings())
                    {
                        tuplesOffset = 0;
                        tuples       = new SortedListIntPtrKey <Pair[]> .Tuple[len];
                    }
                    else
                    {
                        tuplesOffset = _this._endings.Count;
                        tuples       = new SortedListIntPtrKey <Pair[]> .Tuple[len + tuplesOffset];

                        for (int i = 0; i < tuplesOffset; i++)
                        {
                            tuples[i] = _this._endings.Array[i];
                        }
                    }

                    for (int i = 0; i < len; i++)
                    {
                        var p = morphoType.MorphoFormEndingUpperAndMorphoAttributes[i];
                        var pairs_current_len = p.MorphoAttributes.Length;
                        var pairs_current     = new Pair[pairs_current_len];
                        for (int j = 0; j < pairs_current_len; j++)
                        {
                            var ma = MorphoAttributePair.GetMorphoAttribute(morphoType, p.MorphoAttributes[j], ref nounType);
                            pairs_current[j] = new Pair(baseMorphoForm, ma);
                        }
                        tuples[i + tuplesOffset] = new SortedListIntPtrKey <Pair[]> .Tuple()
                        {
                            Key = p.EndingUpper, Value = pairs_current
                        };
                    }

                    ShellSortAscending(tuples);
                    MergeSorted(ref tuples);
                    _this._endings.SetArray(tuples);
                    return;
                }
                #endregion

                if (!_this._slots.TryGetValue(first_char, out _this_next))
                {
                    /// добавление новой буквы
                    _this_next = new TreeDictionaryNative();
                    _this._slots.Add(first_char, _this_next);
                }
                _this = _this_next;
                wordBase++;
            }
        }
        /// поиск слова в слоте
        /// wordPart - оставшаяся часть слова
        /// pSlot - слот
        /// letterIndex - индекс буквы
        unsafe private void FillWordFormMorphologies_Core(char *wordPart, int wordPartLength, int fullWordLength,
                                                          List <WordFormMorphology> result, WordFormMorphologyModeEnum wordFormMorphologyMode)
        {
            if (_BaseMorphoForms == null)
            {
                return;
            }

            foreach (var baseMorphoForm in _BaseMorphoForms)
            {
                int baseLength = baseMorphoForm.Base.Length;
                if ((fullWordLength < baseLength) ||
                    (baseLength + baseMorphoForm.MorphoType.MaxEndingLength < fullWordLength)
                    )
                {
                    continue;
                }

                foreach (var morphoForm in baseMorphoForm.MorphoType.MorphoForms)
                {
                    var endingLength = morphoForm.EndingUpper.Length;
                    if (baseLength + endingLength != fullWordLength)
                    {
                        continue;
                    }

                    if (endingLength != wordPartLength)
                    {
                        continue;
                    }
                    if (wordPartLength == 0)
                    {
                        ;
                    }
                    else
                    if (!StringsHelper.IsEqual(morphoForm.EndingUpper, wordPart, wordPartLength))
                    {
                        continue;
                    }

                    switch (wordFormMorphologyMode)
                    {
                    case WordFormMorphologyModeEnum.Default:
                    {
                        var wfmi = new WordFormMorphology(baseMorphoForm, MorphoAttributePair.GetMorphoAttribute(baseMorphoForm, morphoForm));
                        result.Add(wfmi);
                    }
                    break;

                    case WordFormMorphologyModeEnum.StartsWithLowerLetter:
                    {
                        fixed(char *normalForm_ptr = baseMorphoForm.NormalForm)
                        {
                            var first_char = *normalForm_ptr;

                            if ((first_char != '\0') && *(XlatUnsafe.Inst._UPPER_INVARIANT_MAP + first_char) == first_char)
                            {
                                continue;
                            }
                        }

                        var wfmi = new WordFormMorphology(baseMorphoForm, MorphoAttributePair.GetMorphoAttribute(baseMorphoForm, morphoForm));
                        result.Add(wfmi);
                    }
                    break;

                    case WordFormMorphologyModeEnum.StartsWithUpperLetter:
                    {
                        fixed(char *normalForm_ptr = baseMorphoForm.NormalForm)
                        {
                            var first_char = *normalForm_ptr;

                            if ((first_char != '\0') && *(XlatUnsafe.Inst._UPPER_INVARIANT_MAP + first_char) != first_char)
                            {
                                continue;
                            }
                        }

                        var wfmi = new WordFormMorphology(baseMorphoForm, MorphoAttributePair.GetMorphoAttribute(baseMorphoForm, morphoForm));
                        result.Add(wfmi);
                    }
                    break;

                    case WordFormMorphologyModeEnum.FirstStartsWithUpperAfterLowerLetter:
                    case WordFormMorphologyModeEnum.FirstStartsWithLowerAfterUpperLetter:
                    {
                        throw new NotImplementedException();
                    }
                    }
                }
            }
        }
Esempio n. 6
0
 private static int InternalGetHashCode(ref MorphoAttributePair value)
 {
     return((value.MorphoAttributeGroup.GetHashCode() ^ value.MorphoAttribute.GetHashCode()) & 0x7fffffff);
 }
Esempio n. 7
0
 private static bool IsEquals(ref MorphoAttributePair v1, MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
 {
     return((v1.MorphoAttributeGroup & morphoAttributeGroup) == morphoAttributeGroup &&
            (v1.MorphoAttribute & morphoAttribute) == morphoAttribute);
 }
Esempio n. 8
0
 private static bool IsEquals(ref MorphoAttributePair v1, ref MorphoAttributePair v2)
 {
     return((v1.MorphoAttributeGroup & v2.MorphoAttributeGroup) == v2.MorphoAttributeGroup &&
            (v1.MorphoAttribute & v2.MorphoAttribute) == v2.MorphoAttribute);
 }
Esempio n. 9
0
            public bool TryGetValue(MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute, ref MorphoAttributePair value)
            {
                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))
                    {
                        value = slot.value;
                        return(true);
                    }
                    i = slot.next;
                }

                return(false);
            }
Esempio n. 10
0
 public bool Add(MorphoAttributePair value)
 {
     return(Add(ref value));
 }