示例#1
0
        private IProcessable ProcessElement(NounSet nounSet, ISentenceGraph graph)
        {
            // If noun set is in coordination relation
            if (this.DependencyTypeHelper.IsConjuction(nounSet.DependencyType) &&
                this.CoordinationTypeHelper.IsMergingCoordination(this.CoordinationType))
            {
                // Try create edge between elements
                IPositionateEdge newEdge = this.EdgeFactory.Create(
                    this,
                    nounSet,
                    new List <string>(),
                    nounSet.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList(),
                    this.DependencyTypeHelper.IsSubject(nounSet.DependencyType)
                    );

                if (newEdge != null)
                {
                    nounSet.Adpositions.Clear();
                    graph.AddEdge(newEdge);
                    nounSet.FinalizeProcessing(graph);
                    return(this);
                }

                // If no edge exists merge them
                this.GetAllNouns();
                this.Nouns.AddRange(nounSet.GetAllNouns());
                nounSet.Nouns.Clear();
                graph.ReplaceVertex(this, nounSet);
                return(this);
            }

            // Part of this noun
            if (this.DependencyTypeHelper.IsCompound(nounSet.DependencyType) || this.DependencyTypeHelper.IsNounPhrase(nounSet.DependencyType) || this.DependencyTypeHelper.IsName(nounSet.DependencyType))
            {
                this.Nouns.ForEach(n => n.Process(nounSet, graph));
                graph.ReplaceVertex(this, nounSet);

                return(this);
            }

            // Return noun set if this is negated
            if (this.IsNegated && this.DependencyTypeHelper.IsObject(this.DependencyType))
            {
                return(nounSet);
            }

            // Processing relationship between noun set and this
            this.DrawableHelper.ProcessEdge(graph, this.EdgeFactory, this, nounSet, this.Adpositions, nounSet.Adpositions, this.DependencyTypeHelper.IsSubject(nounSet.DependencyType), () =>
            {
                // Add to extensions
                nounSet.DependencyType = "compound";
                this.Nouns.ForEach(n => n.Process(nounSet, graph));
            });

            // Finalize processed noun
            nounSet.FinalizeProcessing(graph);

            return(this);
        }
示例#2
0
        private IProcessable ProcessElement(Noun noun, ISentenceGraph graph)
        {
            // Process merging coordination type
            if (this.DependencyHelper.IsConjuction(noun.DependencyType) && this.CoordinationTypeHelper.IsMergingCoordination(this.CoordinationType))
            {
                // Try to create edge between elements
                IPositionateEdge newEdge = this.EdgeFactory.Create(
                    this,
                    noun,
                    new List <string>(),
                    noun.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList(),
                    this.DependencyHelper.IsSubject(noun.DependencyType)
                    );

                if (newEdge != null)
                {
                    noun.Adpositions.Clear();
                    graph.AddEdge(newEdge);
                    noun.FinalizeProcessing(graph);
                    return(this);
                }

                // If no edge was found create new noun set
                return(this.ElementFactory.Create(this, noun, graph));
            }

            // Part of noun phrase
            if (this.DependencyHelper.IsCompound(noun.DependencyType) || this.DependencyHelper.IsNounPhrase(noun.DependencyType) || this.DependencyHelper.IsName(noun.DependencyType))
            {
                this.Extensions.Add(noun);
                graph.ReplaceVertex(this, noun);

                return(this);
            }

            // Skip possessive relation
            if (this.DependencyHelper.IsPossesive(noun.DependencyType))
            {
                return(this);
            }

            // Return depending drawable if this is negated
            if (this.IsNegated && this.DependencyHelper.IsObject(this.DependencyType))
            {
                return(noun);
            }

            // Processing relationship between noun set and this
            this.DrawableHelper.ProcessEdge(graph, this.EdgeFactory, this, noun, this.Adpositions, noun.Adpositions, this.DependencyHelper.IsSubject(noun.DependencyType), () =>
            {
                // Add to extensions
                this.Extensions.Add(noun);
            });

            // Finalize processed noun
            noun.FinalizeProcessing(graph);

            return(this);
        }
 private void AssertRelativeEdge(IPositionateEdge edge, Type type)
 {
     Assert.IsNotNull(edge);
     Assert.IsInstanceOfType(edge, typeof(Edge));
     Assert.IsInstanceOfType(edge, type);
     Assert.IsNotNull(edge.Left);
     Assert.IsNotNull(edge.Right);
     Assert.AreEqual(edge.Left, this.Left);
     Assert.AreEqual(edge.Right, this.Right);
 }
示例#4
0
        private void AssertEdgeBasic(IPositionateEdge edge, Vector2 leftPosition, Vector2 rightPosition)
        {
            edge.Positionate(WIDTH, HEIGHT);

            Assert.IsNotNull(edge.Right.Position);
            Assert.IsNotNull(edge.Left.Position);
            Assert.IsTrue(edge.Right.IsPositioned);
            Assert.IsTrue(edge.Left.IsPositioned);
            Assert.AreEqual(edge.Left.Position, leftPosition);
            Assert.AreEqual(edge.Right.Position, rightPosition);
        }
示例#5
0
        private void AssertEdgeInside(IPositionateEdge edge, int divideFactor = 2)
        {
            edge.Positionate(WIDTH, HEIGHT);

            Assert.IsNotNull(edge.Right.Position);
            Assert.IsNotNull(edge.Left.Position);
            Assert.IsTrue(edge.Right.IsPositioned);
            Assert.IsTrue(edge.Left.IsPositioned);
            Assert.IsTrue(edge.Left.ZIndex > edge.Right.ZIndex);
            Assert.IsTrue(edge.Left.Width <= edge.Right.Width / divideFactor);
            Assert.IsTrue(edge.Left.Height <= edge.Right.Height / divideFactor);
        }
        private void AssertCornerEdge(IPositionateEdge edge, HorizontalPlace horizontal)
        {
            HorizontalPlace edgeHorizontal;

            if (edge is InCornerEdge cornerEdge)
            {
                edgeHorizontal = cornerEdge.Horizontal;
            }
            else
            {
                OnCornerEdge onCornerEdge = (OnCornerEdge)edge;
                edgeHorizontal = onCornerEdge.Horizontal;
            }

            Assert.AreEqual(edgeHorizontal, horizontal);
        }
        private void AssertCornerEdge(IPositionateEdge edge, VerticalPlace vertical)
        {
            VerticalPlace edgeVertical;

            if (edge is InCornerEdge cornerEdge)
            {
                edgeVertical = cornerEdge.Vertical;
            }
            else
            {
                OnCornerEdge onCornerEdge = (OnCornerEdge)edge;
                edgeVertical = onCornerEdge.Vertical;
            }

            Assert.AreEqual(edgeVertical, vertical);
        }
示例#8
0
        /// <summary>
        /// Adds new edge into a graph
        /// </summary>
        /// <param name="edge">Edge to add</param>
        public void AddEdge(IPositionateEdge edge)
        {
            if (!this.Graph.ContainsKey(edge.Left))
            {
                this.Graph.Add(edge.Left, new List <IPositionateEdge>());
            }

            if (edge.Right != null && !this.Graph.ContainsKey(edge.Right))
            {
                this.Graph.Add(edge.Right, new List <IPositionateEdge>());
            }

            if (edge is IAbsolutePositionateEdge && edge.Right == null)
            {
                edge = AddAbsoluteEdge((IAbsolutePositionateEdge)edge);
            }

            this.Graph[edge.Left].Add(edge);
        }
示例#9
0
        /// <summary>
        /// Processes two drawable elements.
        /// Tries to create edge between them.
        /// Also checks other options.
        /// </summary>
        /// <param name="graph">Sentence graph</param>
        /// <param name="left">left vertex</param>
        /// <param name="right">right vertex</param>
        /// <param name="leftAdpositions">left adpositions</param>
        /// <param name="rightAdpositions">right adpositions</param>
        /// <param name="finalAction">Actual to do if "of" is found</param>
        /// <param name="isRightSubject">Flag if right vertex is subject</param>
        /// <returns>New edge or null</returns>
        public bool ProcessEdge(ISentenceGraph graph, IEdgeFactory edgeFactory, IDrawable left, IDrawable right, List <Adposition> leftAdpositions, List <Adposition> rightAdpositions, bool isRightSubject, Action finalAction)
        {
            // Get adpositions from adpositions combinations
            List <string>    leftAdp  = leftAdpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList();
            List <string>    rightAdp = rightAdpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList();
            IPositionateEdge edge     = edgeFactory.Create(left, right, leftAdp, rightAdp, isRightSubject);

            // Clear used adpositions
            if (leftAdp.Count == 0)
            {
                leftAdpositions.Clear();
            }
            if (rightAdp.Count == 0)
            {
                rightAdpositions.Clear();
            }

            // Add only not null edge
            if (edge != null)
            {
                graph.AddEdge(edge);
            }
            else
            {
                // Check if drawable contains "of" -> then it is an extension of this
                if (rightAdpositions.Count == 1 && rightAdpositions[0].ToString() == "of")
                {
                    // Replace vertex in graph
                    graph.ReplaceVertex(left, right);

                    // Run final action
                    finalAction();
                }
                else
                {
                    graph.AddVertex(right);
                }
            }

            return(edge != null);
        }
示例#10
0
        public IProcessable FinalizeProcessing(ISentenceGraph graph)
        {
            // Don't create image if already is created
            if (this._image != null)
            {
                return(this);
            }

            // Finalize all nouns
            this.GetAllNouns().ForEach(noun => noun.FinalizeProcessing(graph));

            // Try to create new absolute edge
            IPositionateEdge newEdge = this.EdgeFactory.Create(this, this.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList());

            if (newEdge != null)
            {
                this.Adpositions.Clear();
                graph.AddEdge(newEdge);
            }

            return(this);
        }
示例#11
0
 public void AddEdge(IPositionateEdge edge)
 {
 }
示例#12
0
 private void AssertEdgeVerticesEqualDimensions(IPositionateEdge edge)
 {
     Assert.AreEqual(edge.Right.Width, edge.Left.Width);
     Assert.AreEqual(edge.Right.Height, edge.Left.Height);
 }
示例#13
0
        private IProcessable ProcessElement(Noun noun, ISentenceGraph graph)
        {
            // If noun is in coordination relation
            if (this.DependencyTypeHelper.IsConjuction(noun.DependencyType) &&
                this.CoordinationTypeHelper.IsMergingCoordination(this.CoordinationType))
            {
                // Try to create new edge between elements
                IPositionateEdge newEdge = this.EdgeFactory.Create(
                    this,
                    noun,
                    new List <string>(),
                    noun.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList(),
                    this.DependencyTypeHelper.IsSubject(noun.DependencyType)
                    );

                if (newEdge != null)
                {
                    noun.Adpositions.Clear();
                    graph.AddEdge(newEdge);
                    noun.FinalizeProcessing(graph);
                }
                // If no exists add noun into this set
                else
                {
                    this.GetAllNouns();
                    this.Nouns.Add(noun);
                }

                return(this);
            }

            // If this element is possessive return depending element
            if (this.DependencyTypeHelper.IsPossesive(noun.DependencyType))
            {
                return(this);
            }

            // Let each noun process noun phrase
            if (this.DependencyTypeHelper.IsNounPhrase(noun.DependencyType) || this.DependencyTypeHelper.IsCompound(noun.DependencyType) || this.DependencyTypeHelper.IsName(noun.DependencyType))
            {
                this.Nouns.ForEach(n => n.Process(noun, graph));
                graph.ReplaceVertex(this, noun);

                return(this);
            }

            // If this is negated return depending element
            if (this.IsNegated && this.DependencyTypeHelper.IsObject(this.DependencyType))
            {
                return(noun);
            }

            // Processing relationship between noun and this
            this.DrawableHelper.ProcessEdge(graph, this.EdgeFactory, this, noun, this.Adpositions, noun.Adpositions, this.DependencyTypeHelper.IsSubject(noun.DependencyType), () =>
            {
                // Add to extensions
                noun.DependencyType = "compound";
                this.Nouns.ForEach(n => n.Process(noun, graph));
            });

            // Finalize processed noun
            noun.FinalizeProcessing(graph);

            return(this);
        }