Esempio n. 1
0
        unsafe public static MorphoAttributeEnum GetMorphoAttribute(
            MorphoTypeNative morphoType,
            MorphoFormNative morphoForm)
        {
            var result = default(MorphoAttributeEnum);

            var len = morphoForm.MorphoAttributePairs.Length;

            if (0 < len)
            {
                var morphoAttributeGroup = morphoType.MorphoAttributeGroup;
                fixed(MorphoAttributePair *map_ptr = morphoForm.MorphoAttributePairs)
                {
                    for (len--; 0 <= len; len--)
                    {
                        var morphoAttributePair = (map_ptr + len);
                        if ((morphoAttributeGroup & morphoAttributePair->MorphoAttributeGroup) == morphoAttributePair->MorphoAttributeGroup)
                        {
                            result |= morphoAttributePair->MorphoAttribute;
                        }
                        else
                        {
                            throw (new WrongAttributeException());
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
            /// <summary>
            /// создание морфоформы из строки
            /// </summary>
            private MorphoFormNative?CreateMorphoForm(MorphoTypeNative morphoType, char *lineBase)
            {
                #region find index-of-COLON & check on length
                var index = IndexOf(lineBase, COLON);
                if ((index == -1) || (ENDING_BUFFER_SIZE <= index))
                {
                    _ModelLoadingErrorCallback("Index of COLON is undefined or length the line is too long", StringsHelper.ToString(lineBase));
                    return(null);
                }
                #endregion

                #region fill '_ENDING_LOWER_BUFFER'
                var i = 0;
                for (char *ptr = lineBase; i < index; ptr++, i++)
                {
                    var ch = *ptr;
                    if ((_CHARTYPE_MAP[ch] & CharType.IsWhiteSpace) == CharType.IsWhiteSpace)
                    {
                        break;
                    }
                    _ENDING_LOWER_BUFFER[i] = _LOWER_INVARIANT_MAP[ch];
                }
                _ENDING_LOWER_BUFFER[i] = '\0';
                #endregion

                #region fill '_MorphoAttributePairs_Buffer'
                _MorphoAttributePairs_Buffer.Clear();
                for (char *ptr = lineBase + index + 1; ; ptr++)
                {
                    var ch = *ptr;
                    if (ch == '\0')
                    {
                        break;
                    }

                    if ((_CHARTYPE_MAP[ch] & CharType.IsLetter) != CharType.IsLetter)
                    {
                        continue;
                    }

                    var len = 0;
                    for (; ; ptr++)
                    {
                        ch = *ptr;
                        if (ch == '\0')
                        {
                            break;
                        }
                        var ct = _CHARTYPE_MAP[ch];
                        if ((ct & CharType.IsLetter) != CharType.IsLetter &&
                            (ct & CharType.IsDigit) != CharType.IsDigit)
                        {
                            break;
                        }
                        len++;
                    }
                    if (len != 0)
                    {
                        var morphoAttribute = default(MorphoAttributeEnum);
                        if (_EnumParserMorphoAttribute.TryParse(ptr - len, len, ref morphoAttribute))
                        {
                            var map = _MorphoAttributeList.TryGetMorphoAttributePair(morphoType.MorphoAttributeGroup, morphoAttribute);
                            if (map.HasValue)
                            {
                                _MorphoAttributePairs_Buffer.Add(map.Value);
                            }
#if DEBUG
                            //*
                            //TOO MANY ERRORS AFTER last (2016.12.28) getting morpho-dcitionaries from 'LangAnalyzerStd-[ilook]'
                            else
                            {
                                var attr = new string( ptr - len, 0, len );
                                _ModelLoadingErrorCallback("Error in morpho-attribute: '" + attr + '\'', StringsHelper.ToString(lineBase));
                            }
                            //*/
#endif
                        }
                        else
                        {
                            var attr = new string(ptr - len, 0, len);
                            _ModelLoadingErrorCallback("Unknown morpho-attribute: '" + attr + '\'', StringsHelper.ToString(lineBase));
                        }
                    }

                    if (ch == '\0')
                    {
                        break;
                    }
                }
                #endregion

                #region Allocate native-memory for endingOfWord
                //*
                IntPtr endingPtr;
                IntPtr endingUpperPtr;
                if ((i == 1) && (_ENDING_LOWER_BUFFER[0] == UNDERLINE))
                {
                    endingPtr      = _EMPTY_STRING;
                    endingUpperPtr = _EMPTY_STRING;
                }
                else
                {
                    #region ending-in-original-case
                    endingPtr = new IntPtr(_ENDING_LOWER_BUFFER);

                    if (_EndingDictionary.TryGetValue(endingPtr, out IntPtr existsPtr))
                    {
                        endingPtr = existsPtr;
                    }
                    else
                    {
                        AllocHGlobalAndCopy(_ENDING_LOWER_BUFFER, index, out endingPtr);
                        _EndingDictionary.Add(endingPtr, endingPtr);
                    }
                    #endregion

                    #region ending-in-upper-case
                    StringsHelper.ToUpperInvariant(_ENDING_LOWER_BUFFER, _ENDING_UPPER_BUFFER);

                    endingUpperPtr = new IntPtr(_ENDING_UPPER_BUFFER);

                    if (_EndingDictionary.TryGetValue(endingUpperPtr, out existsPtr))
                    {
                        endingUpperPtr = existsPtr;
                    }
                    else
                    {
                        AllocHGlobalAndCopy(_ENDING_UPPER_BUFFER, index, out endingUpperPtr);
                        _EndingDictionary.Add(endingUpperPtr, endingUpperPtr);
                    }
                    #endregion
                }
                #endregion

                var morphoForm = new MorphoFormNative((char *)endingPtr, (char *)endingUpperPtr, _MorphoAttributePairs_Buffer);
                return(morphoForm);
            }