Пример #1
0
        public TalesNetwork()
        {
            _baseActionNode = new TaleItemNode(this, Properties.Resources.BaseActionNodeName);
            Nodes.Add(_baseActionNode);

            _baseLocativeNode = new TaleItemNode(this, Properties.Resources.BaseLocativeNodeName);
            Nodes.Add(_baseLocativeNode);

            _basePersonNode = new TaleItemNode(this, Properties.Resources.BasePersonNodeName);
            Nodes.Add(_basePersonNode);

            _baseFunctionNode = new TaleItemNode(this, Properties.Resources.BaseFunctionNodeName);
            Nodes.Add(_baseFunctionNode);

            _baseTaleNode = new TaleItemNode(this, Properties.Resources.BaseTaleNodeName);
            Nodes.Add(_baseTaleNode);

            _baseTemplateNode = new TaleItemNode(this, Properties.Resources.BaseTemplateNodeName);
            Nodes.Add(_baseTemplateNode);

            _actionNodes = new TaleItemNodeCollection(this, _baseActionNode);
            _locativeNodes = new TaleItemNodeCollection(this, _baseLocativeNode);
            _personNodes = new TaleItemNodeCollection(this, _basePersonNode);
            _taleNodes = new TaleNodeCollection(this);
        }
        public TemplateParserNetworkNodeContext(NetworkNode networkNode)
        {
            if (networkNode == null)
            {
                throw new ArgumentNullException("networkNode");
            }

            _networkNode = networkNode;
        }
Пример #3
0
        /// <summary>
        /// Создает новую вершину сети с заданной базовой вершиной.
        /// </summary>
        /// <param name="network">Сеть, которой должна принадлежать вершина.</param>
        /// <param name="baseNode">Базовая вершина.</param>
        protected internal NetworkNode(Network network, NetworkNode baseNode)
            : base(network)
        {
            if (baseNode == null)
            {
                throw new ArgumentNullException("baseNode");
            }

            BaseNode = baseNode;
        }
Пример #4
0
        /// <summary>
        /// Создает новую вершину сети с заданными именем и базовой вершиной.
        /// </summary>
        /// <param name="network">Сеть, которой должна принадлежать вершина.</param>
        /// <param name="name">Имя новой вершины.</param>
        /// <param name="baseNode">Базовая вершина.</param>
        protected internal NetworkNode(Network network, string name, NetworkNode baseNode)
            : this(network, name)
        {
            if (baseNode == null)
            {
                throw new ArgumentNullException("baseNode");
            }

            BaseNode = baseNode;
        }
Пример #5
0
        /// <summary>
        /// Создает новую дугу сети.
        /// </summary>
        /// <param name="parent">Сеть, которой должна принадлежать дуга.</param>
        /// <param name="startNode">Вершина, из которой должна исходить данная дуга.</param>
        /// <param name="endNode">Вершина, в которую должна входить данная дуга.</param>
        /// <param name="edgeType">Тип дуги.</param>
        protected internal NetworkEdge(Network parent, NetworkNode startNode, NetworkNode endNode, NetworkEdgeType edgeType)
            : base(parent)
        {
            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }
            if (endNode == null)
            {
                throw new ArgumentNullException("endNode");
            }
            if (startNode == null)
            {
                throw new ArgumentNullException("startNode");
            }

            _startNode = startNode;
            _endNode = endNode;
            _edgeType = edgeType;
        }
Пример #6
0
        public bool IsInherit(NetworkNode networkNode, bool useIsInstance)
        {
            if (networkNode == null)
            {
                throw new ArgumentNullException("networkNode");
            }

            bool isInherit = false;

            if (networkNode == this)
            {
                isInherit = true;
            }
            else
            {
                NetworkNode baseNode = BaseNode;

                // TODO: Скорее всего ошибка.
                if (useIsInstance &&
                    baseNode == null)
                {
                    baseNode = InstanceNode;
                }

                while (!isInherit && baseNode != null)
                {
                    if (baseNode == networkNode)
                    {
                        isInherit = true;
                        break;
                    }

                    baseNode = baseNode.BaseNode;
                }
            }

            return isInherit;
        }
Пример #7
0
 public DiagramNodeEx(DiagramNode _node, NetworkNode _netNode)
 {
     DiagramNode = _node;
     NetworkNode = _netNode;
 }
Пример #8
0
        private bool AreHaveCommonAncestor(NetworkNode firstNode, NetworkNode secondNode, params NetworkNode[] stopNodes)
        {
            if (secondNode.IsInherit(firstNode, false))
            {
                return true;
            }

            NetworkNode baseNode = firstNode.BaseNode;

            while (baseNode != null &&
                Array.IndexOf(stopNodes, baseNode) == -1)
            {
                if (secondNode.IsInherit(baseNode, false))
                {
                    return true;
                }

                baseNode = baseNode.BaseNode;
            }

            return false;
        }
Пример #9
0
        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];
        }
Пример #10
0
 private void CreateDescendants(TreeViewItem root, NetworkNode node)
 {
     //Связи
     NetworkEdgeType currentType;
     //TreeViewItem linksRoot = new TreeViewItem();
     //linksRoot.Header = "Связи";
     //root.Items.Add(linksRoot);
     TreeViewItem linksRoot = root;
     //Agent
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Agent);
     //Recipient
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Recipient);
     //Goal
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Goal);
     //Follow
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Follow);
     //Locative
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Locative);
     //Template
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.Template);
     //PartOf
     CreateTypedDescendant(linksRoot, node, NetworkEdgeType.PartOf);
     //Экземплярыэ
     CreateInstances(root, node);
     //Is-a потомки
     CreateDescendantsNodes(root, node);
 }
Пример #11
0
 /// <summary>
 /// Создает новую дугу сети.
 /// </summary>
 /// <param name="parent">Сеть, которой должна принадлежать дуга.</param>
 /// <param name="startNode">Вершина, из которой должна исходить данная дуга.</param>
 /// <param name="endNode">Вершина, в которую должна входить данная дуга.</param>
 protected internal NetworkEdge(Network parent, NetworkNode startNode, NetworkNode endNode)
     : this(parent, startNode, endNode, NetworkEdgeType.IsA)
 {
 }
Пример #12
0
        public override void LoadFromXml(XElement xNetworkEdge)
        {
            if (xNetworkEdge == null)
            {
                throw new ArgumentNullException("xNetworkEdge");
            }

            base.LoadFromXml(xNetworkEdge);

            XAttribute xEdgeTypeAttribute = xNetworkEdge.Attribute("type");
            XAttribute xStartNodeIdAttribute = xNetworkEdge.Attribute("startNodeId");
            XAttribute xEndNodeIdAttribute = xNetworkEdge.Attribute("endNodeId");

            if (xEdgeTypeAttribute == null ||
                xStartNodeIdAttribute == null ||
                xEndNodeIdAttribute == null)
            {
                throw new SerializationException();
            }

            NetworkEdgeType edgeType;
            int startNodeId;
            int endNodeId;

            if (!Enum.TryParse<NetworkEdgeType>(xEdgeTypeAttribute.Value, out edgeType) ||
                !Int32.TryParse(xStartNodeIdAttribute.Value, out startNodeId) ||
                !Int32.TryParse(xEndNodeIdAttribute.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out endNodeId))
            {
                throw new SerializationException();
            }

            _startNode = Network.Nodes.SingleOrDefault(node => node.Id == startNodeId);

            _endNode= Network.Nodes.SingleOrDefault(node => node.Id == endNodeId);
            _edgeType = edgeType;

            if (_startNode == null ||
                _endNode == null)
            {
                throw new SerializationException();
            }
        }
Пример #13
0
        private void CreateTypedDescendant(TreeViewItem root, NetworkNode node, NetworkEdgeType currentType)
        {
            string str = Utils.ConvertToResourcesType(currentType) + "TemplateKey";
            DataTemplate template = Application.Current.TryFindResource(str) as DataTemplate;
            str = Utils.ConvertToResourcesType(currentType) + "ItemTemplateKey";
            DataTemplate itemTemplate = Application.Current.TryFindResource(str) as DataTemplate;

            var edges = node.GetTypedOutGoingEdges(currentType);
            foreach(var edge in edges)
            {
                TreeViewItem linkRoot = new TreeViewItem();
                linkRoot.Header = Utils.ConvertType(edge.Type);
                linkRoot.HeaderTemplate = template;
                linkRoot.ContextMenu = _linkMenu;
                linkRoot.Uid = edge.Id.ToString();

                LoadItemState(edge.Id, node, linkRoot);

                root.Items.Add(linkRoot);

                NetworkNode nodeDesc = edge.EndNode;
                TreeViewItem nodeTreeItem = CreateNodeItem(nodeDesc, itemTemplate);

                LoadItemState(nodeDesc.Id, edge, nodeTreeItem);

                linkRoot.Items.Add(nodeTreeItem);
            }
        }
Пример #14
0
 private TreeViewItem CreateNodeItem(NetworkNode endNode, DataTemplate itemTemplate)
 {
     TreeViewItem nodeRoot = new TreeViewItem();
     Binding nodeBinding = new Binding();
     nodeBinding.Source = endNode;
     nodeBinding.Path = new PropertyPath("Name");
     nodeBinding.Converter = new NodeNameConverter();
     nodeRoot.SetBinding(TreeViewItem.HeaderProperty, nodeBinding);
     nodeRoot.Uid = endNode.Id.ToString(CultureInfo.InvariantCulture);
     nodeRoot.ContextMenu = _nodeMenu;
     nodeRoot.HeaderTemplate = itemTemplate;
     return nodeRoot;
 }
Пример #15
0
        private void CreateInstances(TreeViewItem root, NetworkNode node)
        {
            if (node.HasTypedIncomingEdges(NetworkEdgeType.IsInstance))
            {
                string str = Utils.ConvertToResourcesType(NetworkEdgeType.IsInstance) + "TemplateKey";
                DataTemplate template = Application.Current.TryFindResource(str) as DataTemplate;

                str = Utils.ConvertToResourcesType(NetworkEdgeType.IsInstance) + "ItemTemplateKey";
                DataTemplate itemTemplate = Application.Current.TryFindResource(str) as DataTemplate;

                TreeViewItem instanceRoot = new TreeViewItem();
                instanceRoot.Header = Properties.Resources.InstancesLabel;
                instanceRoot.Focusable = false;
                instanceRoot.HeaderTemplate = template;

                LoadItemState(-1, node, instanceRoot, Properties.Resources.InstancesLabel);

                root.Items.Add(instanceRoot);

                foreach (NetworkEdge edge in node.GetTypedIncomingEdges(NetworkEdgeType.IsInstance))
                {
                    NetworkNode endNode = edge.StartNode;
                    TreeViewItem nodeRoot = CreateNodeItem(endNode, itemTemplate);

                    LoadItemState(endNode.Id, node, nodeRoot);
                    CreateDescendants(nodeRoot, endNode);

                    instanceRoot.Items.Add(nodeRoot);
                }

            }
        }
Пример #16
0
        void OnNetworkNodeTextChanged(NetworkNode netNode)
        {
            if (netNode == null)
                return;

            DiagramNode node = Utils.FindItemByUserData(_diagram, netNode.Id) as DiagramNode;
            if (node == null)
                return;

            node.Label.Text = netNode.Name;
        }
Пример #17
0
        // TODO: Необходимо учитывать, что в actorName может быть несколько слов.
        private TemplateToken ParseActorTemplate(Match match, string actorName, NetworkNode actorNode, NetworkEdgeType edgeType, bool ignoreCase = false)
        {
            Contract.Requires<ArgumentException>(edgeType == NetworkEdgeType.Agent || edgeType == NetworkEdgeType.Recipient);
            Contract.Ensures(Contract.Result<TemplateToken>() != null);
            Contract.Assume(_templateParser != null);

            string lemma = Lemmatize(_templateParser.TextAnalyzer, actorName);
            string resolvedText = null;
            PartOfSentence partOfSentence = PartOfSentence.Subject;

            // 1. Проверим на предмет явного задания граммемы.
            resolvedText = GetTextByGrammem(match, actorName);

            // 2. Выполним поиск сказуемого.
            TemplateToken predicate = _templateParser.CurrentSentence.LastOrDefault(token => token.PartOfSentence == PartOfSentence.Predicate);

            if (predicate == null || edgeType == NetworkEdgeType.Agent)
            {
                partOfSentence = PartOfSentence.Subject;

                if (resolvedText == null)
                {
                    resolvedText = actorName;
                }
            }
            else if (edgeType == NetworkEdgeType.Recipient)
            {
                Grammem objectGrammem = FindObjectGrammem(_templateParser.TextAnalyzer, predicate.Text);

                if (objectGrammem == Grammem.None)
                {
                    objectGrammem = Grammem.Genitiv;
                }

                partOfSentence = PartOfSentence.Object;

                if (resolvedText == null)
                {
                    resolvedText = _templateParser.ReconcileWord(actorName, objectGrammem);
                }
            }

            // 3. Согласуем регистр.
            if (!ignoreCase)
            {
                resolvedText = ReconcileCase(match.Groups[0].Value, resolvedText);
            }

            // 4. Запомним граммему.
            Grammem grammem = Grammem.None;
            TaleNet.IFormattable formattable = actorNode as TaleNet.IFormattable;

            if (formattable != null)
            {
                grammem = formattable.Grammem;
            }

            return
                new TemplateToken(resolvedText, lemma, match.ToString())
                {
                    PartOfSentence = partOfSentence,
                    Grammem = grammem
                };
        }