public SemanticInfo Copy() { var result = new SemanticInfo(); result.CommonClass = SemanticInfoCommonClass.ReadFromString(CommonClass.Value); result.LexicalClass = SemanticInfoLexicalClass.ReadFromString(LexicalClass.Value); return result; }
private void _createFromAPIFormat(XElement elementXML, bool useNamespaces) { // смотрим что обрабатываем - слово или знак препинания var elementNode = elementXML.Element(XName.Get(Consts.NodeWord, Namespaces.NamespaceLinguistic)); if (elementNode != null) ElementType = SentenceElementType.ReadFromString(elementNode.Name.LocalName); else { elementNode = elementXML.Element(XName.Get(Consts.NodePunctuator, useNamespaces ? Namespaces.NamespaceLinguistic : "")); if (elementNode != null) ElementType = SentenceElementType.ReadFromString(elementNode.Element(XName.Get(Consts.NodePunctuatorType, useNamespaces ? Namespaces.NamespaceLinguistic : "")).Attribute(XName.Get(Consts.AttResourse, useNamespaces ? Namespaces.NamespaceRDF : "")).Value); } Debug.Assert(elementNode != null); GUID = elementNode.Attribute(XName.Get(Consts.AttElementNodeId, useNamespaces ? Namespaces.NamespaceRDF : "")).Value; // проваливаемся на 1 уровень ниже - на нем располагаются все свойства elementXML = elementNode; var nodeIdName = XName.Get(Consts.AttElementNodeId, useNamespaces ? Namespaces.NamespaceRDF : ""); // вершиной дерева всегда будет ID слова SyntacticChain.AddChild(GUID); // Order var orderNodeName = XName.Get(Consts.NodeWordOrder, useNamespaces ? Namespaces.NamespaceLinguistic : ""); Debug.Assert(elementXML.Element(orderNodeName) != null); Order = int.Parse(elementXML.Element(orderNodeName).Value); // Text var textNodeName = XName.Get(Consts.NodeWordText, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(textNodeName) != null) Text = elementXML.Element(textNodeName).Value; else Text = ""; // Lemma var lemmaNodeName = XName.Get(Consts.NodeLemmaName, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(lemmaNodeName) != null) Lemma = elementXML.Element(lemmaNodeName).Value; else Lemma = ""; // Syntactic Role var syntacticRoleNodeName = XName.Get(Consts.NodeSyntacticRole, useNamespaces ? Namespaces.NamespaceLinguistic : ""); var syntacticRoleAttName = XName.Get(Consts.AttResourse, useNamespaces ? Namespaces.NamespaceRDF : ""); if (elementXML.Element(syntacticRoleNodeName) != null) SyntacticRole = SyntacticRole.ReadFromString(elementXML.Element(syntacticRoleNodeName).Attribute(syntacticRoleAttName).Value); else SyntacticRole = SyntacticRole.Undefined; // Surface slot var surfaceSlotNodeName = XName.Get(Consts.NodeSurfaceSlot, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(surfaceSlotNodeName) != null) SurfaceSlot = elementXML.Element(surfaceSlotNodeName).Value; else SurfaceSlot = Consts.SurfaceSlotUndefined; // grammar info var grammarInfoNodeName = XName.Get(Consts.NodeGrammarInfo, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(grammarInfoNodeName) != null) GrammarInfo = new GrammarInfo(elementXML.Element(grammarInfoNodeName), useNamespaces); else GrammarInfo = new GrammarInfo(); // prepositionUsed var prepositionUsedNodeName = XName.Get(Consts.NodeGrammarPrepositionUsed, useNamespaces ? Namespaces.NamespaceLinguistic : ""); var resourceName = XName.Get(Consts.AttResourse, useNamespaces ? Namespaces.NamespaceRDF : ""); if (elementXML.Element(prepositionUsedNodeName) != null) PrepositionUsed = PrepositionUsed.ReadFromString(elementXML.Element(prepositionUsedNodeName).Attribute(resourceName).Value); else PrepositionUsed = PrepositionUsed.Undefined; // is restored var isRestoredNodeName = XName.Get(Consts.NodeIsRestored, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(isRestoredNodeName) != null) IsRestored = (elementXML.Element(isRestoredNodeName).Value == Consts.ValueTrue); else IsRestored = false; //is word IsWord = SentenceElementType.IsWord(ElementType); // syntactic parent guid var syntacticParentNodeName = XName.Get(Consts.NodeSyntacticParent, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(syntacticParentNodeName) != null) SyntacticParentWordGUID = elementXML.Element(syntacticParentNodeName).Attribute(nodeIdName).Value; else SyntacticParentWordGUID = ""; // controller nodes var controllerNodeName = XName.Get(Consts.NodeHasController, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(controllerNodeName) != null) { var singleControllerNodeName = XName.Get(Consts.NodeController, useNamespaces ? Namespaces.NamespaceLinguistic : ""); foreach (var controllerItemXML in elementXML.Element(controllerNodeName).Elements(singleControllerNodeName)) ControllerNodes.Add(new Controller(controllerItemXML, useNamespaces)); } // conjucted with guid var conjuctedWithNodeName = XName.Get(Consts.NodeConjuctedWith, useNamespaces ? Namespaces.NamespaceLinguistic : ""); if (elementXML.Element(conjuctedWithNodeName) != null) ConjunctedWithGUID = elementXML.Element(conjuctedWithNodeName).Attribute(nodeIdName).Value; else ConjunctedWithGUID = ""; // semantic info --> lexical class predefined var semanticInfoNodeName = XName.Get(Consts.NodeSemanticInfo, useNamespaces ? Namespaces.NamespaceLinguistic : ""); SemanticInfo = new SemanticInfo(elementXML.Element(semanticInfoNodeName), useNamespaces); //Equivalents var equivalentGUIDNodeName = XName.Get(Consts.NodeEquivalent, useNamespaces ? Namespaces.NamespaceLinguistic : ""); EquivalentGUIDs.AddRange(elementXML.Elements(equivalentGUIDNodeName).Select(x => x.Attribute(nodeIdName).Value).ToList()); // при добавлении свойств зарегистрировать их в методе глубукого копирования }