public TaleGenerationInfo(TaleNode tale, double relevanceLevel) { Contract.Requires<ArgumentNullException>(tale != null); Tale = tale; RelevanceLevel = relevanceLevel; ConflictSets = new FunctionConflictSetCollection(); }
public string GenerateText(TaleNode taleNode) { if (taleNode == null) { throw new ArgumentNullException("taleNode"); } return GenerateText(taleNode.Functions); }
internal FunctionNode(TaleNode taleNode, string name, FunctionType functionType) : base((TalesNetwork)taleNode.Network, name) { Network.Edges.Add(this, taleNode, Net.NetworkEdgeType.PartOf); _functionType = functionType; _actionNodes = new FunctionNodeContextNodeCollection(this, NetworkEdgeType.Action); _agentNodes = new FunctionNodeContextNodeCollection(this, NetworkEdgeType.Agent); _recipientNodes = new FunctionNodeContextNodeCollection(this, NetworkEdgeType.Recipient); _locativeNodes = new FunctionNodeContextNodeCollection(this, NetworkEdgeType.Locative); }
private void GetChildContextNode( IDictionary<FunctionNode, TemplateParserResult> parserResults, TaleNode currentTaleNode, FunctionNode baseFunctionNode, NetworkEdgeType edgeType, TemplateParserDictionaryContext newParserContext) { TemplateParserResult baseFunctionNodeParserResult = parserResults[baseFunctionNode]; var currentTaleContextNodes = new List<NetworkNode>(); var baseTaleContextNodes = baseFunctionNode.OutgoingEdges.GetEdges(edgeType).Select(edge => edge.EndNode); bool found = false; foreach (FunctionNode functionNode in currentTaleNode.Functions) { currentTaleContextNodes.AddRange(functionNode.OutgoingEdges.GetEdges(edgeType).Select(edge => edge.EndNode)); } foreach (NetworkNode baseTaleContextNode in baseTaleContextNodes) { if (currentTaleContextNodes.Any(node => node.IsInherit(baseTaleContextNode, false))) { NetworkNode currentNode = null; while (true) { NetworkEdge isAEdge = baseTaleContextNode.OutgoingEdges.GetEdge(NetworkEdgeType.IsA); if (isAEdge != null) { currentNode = isAEdge.StartNode; NetworkNode childNode = currentTaleContextNodes.FirstOrDefault(node => node == currentNode || node.BaseNode == currentNode); if (childNode != null) { found = true; newParserContext.Add(edgeType, childNode); break; } } if (isAEdge == null && currentNode != null) { found = true; newParserContext.Add(edgeType, currentNode); break; } } } } if (!found) { newParserContext.Add(edgeType, baseTaleContextNodes); } }
protected override void LoadFromXElement(XElement xNetwork) { Contract.Requires<ArgumentNullException>(xNetwork != null); XNamespace xNamespace = SerializableObject.XNamespace; XElement xNodesBase = xNetwork.Element(xNamespace + "Nodes"); var xNodes = xNodesBase.Elements(xNamespace + "Node"); foreach (XElement xNode in xNodes) { XAttribute xNodeKindAttribute = xNode.Attribute("nodeKind"); NetworkNode networkNode = null; if (xNodeKindAttribute == null) { //networkNode = Nodes.Add(); throw new SerializationException(); } else { TaleNodeKind nodeKind = (TaleNodeKind)Enum.Parse(typeof(TaleNodeKind), xNodeKindAttribute.Value); switch (nodeKind) { case TaleNodeKind.Tale: networkNode = new TaleNode(this); break; case TaleNodeKind.TaleItem: networkNode = new TaleItemNode(this); break; case TaleNodeKind.Function: networkNode = new FunctionNode(this); break; } } networkNode.LoadFromXml(xNode); // TODO: Необходимо избавиться от этого костыля. if (!Nodes.Where(node => node.Id == networkNode.Id).Any()) { Nodes.Add(networkNode); } } XElement xEdgesBase = xNetwork.Element(xNamespace + "Edges"); var xEdges = xEdgesBase.Elements(xNamespace + "Edge"); foreach (XElement xEdge in xEdges) { NetworkEdge networkEdge = new TaleItemEdge(this); networkEdge.LoadFromXml(xEdge); // TODO: Необходимо избавиться от этого костыля. if (!Edges.Where(edge => edge.Id == networkEdge.Id).Any()) { Edges.Add(networkEdge); } } SetId(); _isDirty = false; _baseActionNode = (TaleItemNode)Nodes[0]; _baseLocativeNode = (TaleItemNode)Nodes[1]; _basePersonNode = (TaleItemNode)Nodes[2]; _baseFunctionNode = Nodes[3]; _baseTaleNode = Nodes[4]; _baseTemplateNode = Nodes[5]; }
internal TaleNode(TalesNetwork taleNetwork, string name, TaleNode baseTaleNode) : base(taleNetwork, name, baseTaleNode) { _functionNodes = new TaleFunctionNodeCollection(this); }