Example #1
0
        /// <summary>
        /// Parse word pos pair.
        /// </summary>
        /// <param name="wordPosPair">Word.</param>
        /// <param name="attributeSchema">AttributeSchema.</param>
        /// <returns>ErrorSet.</returns>
        public ErrorSet Parse(string wordPosPair, LexicalAttributeSchema attributeSchema)
        {
            ErrorSet errorSet = new ErrorSet();
            int slashIndex = wordPosPair.LastIndexOf(WordPosDelimeter);

            if (slashIndex < 0 || slashIndex > wordPosPair.Length - 1)
            {
                errorSet.Add(PosCorpusError.InvalidFormat, wordPosPair);
            }
            else if (slashIndex == 0)
            {
                errorSet.Add(PosCorpusError.EmptyWord, wordPosPair);
            }
            else if (slashIndex == wordPosPair.Length - 1)
            {
                errorSet.Add(PosCorpusError.EmptyPos, wordPosPair);
            }
            else
            {
                WordText = wordPosPair.Substring(0, slashIndex);
                string originalPos = wordPosPair.Substring(slashIndex + 1);
                if (attributeSchema != null)
                {
                    string posTaggingPos = attributeSchema.GetPosTaggingPos(originalPos);
                    if (string.IsNullOrEmpty(posTaggingPos))
                    {
                        errorSet.Add(PosCorpusError.NoPosTaggingPos, originalPos);
                    }
                    else
                    {
                        Pos = posTaggingPos;
                    }
                }
                else
                {
                    Pos = originalPos;
                }
            }

            return errorSet;
        }