Example #1
0
        /// <summary>
        /// Returns the complete gram case declaration
        /// </summary>
        /// <param name="parts">The parts.</param>
        /// <returns></returns>
        public string GetAll(gramFlagDeclarationParts parts = gramFlagDeclarationParts.all)
        {
            StringBuilder sb = new StringBuilder();

            if (parts.HasFlag(gramFlagDeclarationParts.posType))
            {
                sb.Append(posConverter.getString(type));
            }

            if (parts.HasFlag(gramFlagDeclarationParts.posMarkers))
            {
                foreach (string marker in markers)
                {
                    sb.Append("+");
                    sb.Append(marker.Trim('+'));
                }

                sb.Append(":");
            }
            if (parts.HasFlag(gramFlagDeclarationParts.posGramFlags))
            {
                foreach (Type t in posConverter.posTypeVsPattern[type])
                {
                    checkItemsForType(t);
                    sb.Append(posConverter.getString(items[t] as Enum));
                }
            }

            stringForm = sb.ToString();

            return(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// Sets: <see cref="pos_type"/>, and other pos flags contained in the specified declaration
        /// </summary>
        /// <param name="declaration">The declaration in Unitex format -- the part of DELAF entry without word and lemma, after dot: N:mp2q</param>
        /// <param name="parts">The parts.</param>
        /// <exception cref="aceGeneralException">
        /// POS type definition not found in the input declaration [" + declaration + "] - null - POS Type failed in SetAll()
        /// or
        /// POS type set to none by the input declaration [" + declaration + "] - null - POS Type failed in SetAll()
        /// or
        /// POS gram flags not found in the input declaration [" + declaration + "] - null - POS gram flags failed in SetAll()
        /// </exception>
        public void SetAll(string declaration, gramFlagDeclarationParts parts = gramFlagDeclarationParts.all)
        {
            declaration = declaration.Trim();
            if (declaration == ":")
            {
                return;
            }

            MatchCollection mcl = null; // posConverter.REGEX_UNITEX_Declaration.Matches(declaration);

            if (parts.HasFlag(gramFlagDeclarationParts.posType))
            {
                Match mc = posConverter.REGEX_UNITEX_DecPosType.Match(declaration);

                if (mc.Success)
                {
                    string g_dec = mc.Value;

                    type = (pos_type)posConverter.getFlag(typeof(pos_type), g_dec);
                }
                else
                {
                    throw new aceGeneralException("POS type definition not found in the input declaration [" + declaration + "]", null, this, "POS Type failed in SetAll()");
                }

                if (type == pos_type.none)
                {
                    throw new aceGeneralException("POS type set to none by the input declaration [" + declaration + "]", null, this, "POS Type failed in SetAll()");
                }
            }


            if (parts.HasFlag(gramFlagDeclarationParts.posMarkers))
            {
                if (posConverter.REGEX_UNITEX_MarkersSelection.IsMatch(declaration))
                {
                    string        m_dec = posConverter.REGEX_UNITEX_MarkersSelection.Match(declaration).Value;
                    List <string> marks = m_dec.SplitSmart("+");
                    markers.AddRangeUnique(marks);
                }
            }


            if (parts.HasFlag(gramFlagDeclarationParts.posGramFlags))
            {
                var ts = posConverter.posTypeVsPattern[type];


                Match mc = posConverter.REGEX_UNITEX_DecGrams.Match(declaration);

                if (mc.Success)
                {
                    string g_dec = mc.Value;
                    //var ts = posConverter.posTypeVsPattern[type];
                    var fls = posConverter.posTypeVsString.GetEnums(ts, g_dec);

                    if (!fls.Any())
                    {
                        if (ts.Count > 0)
                        {
                            throw new aceGeneralException("POS gram flags interpretation failed, no flags found in the input declaration [" + declaration + "]", null, this, "POS gram flags failed in SetAll()");
                        }
                    }

                    foreach (var fl in fls)
                    {
                        Set(fl as Enum);
                    }
                }
                else
                {
                    throw new aceGeneralException("POS gram flags not found in the input declaration [" + declaration + "]", null, this, "POS gram flags failed in SetAll()");
                }
            }

            stringForm = declaration;
        }