예제 #1
0
        /// добавление части слова
        /// 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))
예제 #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;
            }
        }
예제 #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);
            }
예제 #4
0
 private static int InternalGetHashCode(ref MorphoAttributePair value)
 {
     return((value.MorphoAttributeGroup.GetHashCode() ^ value.MorphoAttribute.GetHashCode()) & 0x7fffffff);
 }
예제 #5
0
 private static bool IsEquals(ref MorphoAttributePair v1, MorphoAttributeGroupEnum morphoAttributeGroup, MorphoAttributeEnum morphoAttribute)
 {
     return((v1.MorphoAttributeGroup & morphoAttributeGroup) == morphoAttributeGroup &&
            (v1.MorphoAttribute & morphoAttribute) == morphoAttribute);
 }
예제 #6
0
 private static bool IsEquals(ref MorphoAttributePair v1, ref MorphoAttributePair v2)
 {
     return((v1.MorphoAttributeGroup & v2.MorphoAttributeGroup) == v2.MorphoAttributeGroup &&
            (v1.MorphoAttribute & v2.MorphoAttribute) == v2.MorphoAttribute);
 }
예제 #7
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);
            }
예제 #8
0
 public bool Add(MorphoAttributePair value)
 {
     return(Add(ref value));
 }
예제 #9
0
        /// поиск слова в слоте
        /// 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();
                    }
                    }
                }
            }
        }