Example #1
0
        /// <summary>
        /// Validate attribute set for the word.
        /// </summary>
        /// <param name="property">Lexicon item property.</param>
        /// <param name="attributeSchema">Lexical Attribute Schema.</param>
        /// <returns>Error set.</returns>
        private static ErrorSet ValidateAttributeSet(LexiconItemProperty property,
            LexicalAttributeSchema attributeSchema)
        {
            Debug.Assert(attributeSchema != null);
            ErrorSet attributeErrorSet = new ErrorSet();

            foreach (KeyValuePair<string, List<AttributeItem>> pair in property.AttributeSet)
            {
                foreach (AttributeItem attribute in pair.Value)
                {
                    AttributeCategory category = attributeSchema.GetRootCategory(pair.Key);
                    if (category == null)
                    {
                        attributeErrorSet.Add(LexicalAttributeError.InvalidCategory, pair.Key);
                    }
                    else if (category.Name.Equals(LexicalAttributeSchema.PosCategoryName, StringComparison.Ordinal))
                    {
                        attributeErrorSet.Add(LexicalAttributeError.InvalidDefinitionForPos, attribute.Value);
                    }
                    else
                    {
                        bool found = false;
                        foreach (AttributeValue value in category.Values)
                        {
                            if (value.Name.Equals(attribute.Value, StringComparison.Ordinal))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            attributeErrorSet.Add(LexicalAttributeError.InvalidValue, attribute.Value, pair.Key);
                        }
                    }
                }
            }

            return attributeErrorSet;
        }