示例#1
0
        /// <summary>
        /// Load LexiconItemProperty from XmlNode.
        /// </summary>
        /// <param name="parentLexPron">LexiconPronunciation.</param>
        /// <param name="propertyNode">XmlNode.</param>
        /// <param name="nsmgr">XmlNamespaceManager.</param>
        /// <param name="contentController">Object.</param>
        /// <param name="errorSet">ErrorSet.</param>
        /// <returns>LexiconItemProperty.</returns>
        internal static LexiconItemProperty Load(LexiconPronunciation parentLexPron, XmlNode propertyNode, XmlNamespaceManager nsmgr, Lexicon.ContentControler contentController, ErrorSet errorSet)
        {
            Debug.Assert(parentLexPron != null && parentLexPron.Parent != null && propertyNode != null &&
                nsmgr != null && contentController != null && errorSet != null);

            LexiconItemProperty property = new LexiconItemProperty();
            property.Parent = parentLexPron;

            XmlElement propertyElem = propertyNode as XmlElement;
            string stateValue = propertyElem.GetAttribute("s");
            if (!string.IsNullOrEmpty(stateValue))
            {
                property.Status = (Lexicon.LexiconStatus)Enum.Parse(typeof(Lexicon.LexiconStatus), stateValue, true);
            }

            if (!contentController.IsHistoryCheckingMode && property.Status == Lexicon.LexiconStatus.Deleted)
            {
                property = null;
            }
            else
            {
                PosItem posItem = PosItem.Load(propertyNode, nsmgr);
                if (posItem != null)
                {
                    property.PartOfSpeech = posItem;
                }

                GenderItem genderItem = GenderItem.Load(propertyNode, nsmgr);
                if (genderItem != null)
                {
                    property.Gender = genderItem;
                }

                CaseItem caseItem = CaseItem.Load(propertyNode, nsmgr);
                if (caseItem != null)
                {
                    property.Case = caseItem;
                }

                NumberItem numberItem = NumberItem.Load(propertyNode, nsmgr);
                if (numberItem != null)
                {
                    property.Number = numberItem;
                }

                foreach (XmlNode domainNode in propertyNode.SelectNodes("tts:domain", nsmgr))
                {
                    DomainItem domainItem = DomainItem.Load(property, domainNode, nsmgr, contentController, errorSet);
                    if (domainItem != null)
                    {
                        if (!property.Domains.ContainsKey(domainItem.Value))
                        {
                            property.Domains.Add(domainItem.Value, domainItem);
                        }
                        else
                        {
                            Error error = new Error(DomainError.DuplicateDomain, domainItem.Value);
                            errorSet.Add(LexiconError.DomainError,
                                error, parentLexPron.Parent.Text, parentLexPron.Symbolic);
                        }
                    }
                }

                string lexLevelDomain = (parentLexPron.Parent.Parent as Lexicon).DomainTag;
                if (property.Domains.Count == 0)
                {
                    if (string.IsNullOrEmpty(lexLevelDomain))
                    {
                        property.ChangeDomain(new DomainItem());
                    }
                    else
                    {
                        property.ChangeDomain(new DomainItem(lexLevelDomain));
                    }
                }
                else if (!string.IsNullOrEmpty(lexLevelDomain))
                {
                    Error error = new Error(DomainError.InvalidDomainTags);
                    errorSet.Add(LexiconError.DomainError,
                        error, parentLexPron.Parent.Text, parentLexPron.Symbolic);
                }

                foreach (XmlNode attributeNode in propertyNode.SelectNodes("tts:attr", nsmgr))
                {
                    AttributeItem attributeItem = AttributeItem.Load(property, attributeNode, nsmgr, contentController, errorSet);
                    if (attributeItem != null)
                    {
                        property.AddAttribute(attributeItem);
                    }
                }
            }

            return property;
        }
示例#2
0
        /// <summary>
        /// Clone current property .
        /// </summary>
        /// <returns>Cloned LexiconItemProperty.</returns>
        public LexiconItemProperty Clone()
        {
            LexiconItemProperty clonedProperty = new LexiconItemProperty();
            clonedProperty.Valid = _valid;
            clonedProperty.Status = Status;

            if (_pos != null)
            {
                clonedProperty.PartOfSpeech = _pos.Clone();
            }

            if (_gender != null)
            {
                clonedProperty.Gender = _gender.Clone();
            }

            if (_case != null)
            {
                clonedProperty.Case = _case.Clone();
            }

            if (_number != null)
            {
                clonedProperty.Number = _number.Clone();
            }

            foreach (string domainName in _domains.Keys)
            {
                clonedProperty.Domains.Add(domainName, _domains[domainName].Clone());
            }

            foreach (string attributeName in _attributes.Keys)
            {
                foreach (AttributeItem attr in _attributes[attributeName])
                {
                    clonedProperty.AddAttribute(attr.Clone());
                }
            }

            return clonedProperty;
        }