Exemple #1
0
        public override IProcessable FinalizeProcessing(ISentenceGraph graph)
        {
            if (this.Image != null)
            {
                return(this);
            }

            this.GetImage();

            // If this is plural finalize wih noun set
            IPositionateEdge newEdge;

            if (this.IsPlural)
            {
                var finalizingElement = new NounSet(this.ElementFactory, this.EdgeFactory, this, NumberOfInstances);
                newEdge = this.EdgeFactory.Create(finalizingElement, this.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList());
                return(finalizingElement);
            }

            // Try to create new absolute edge
            newEdge = this.EdgeFactory.Create(this, this.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList());
            if (newEdge != null)
            {
                graph.AddEdge(newEdge);
                this.Adpositions.Clear();
            }

            // Scaling from accumulated scale
            this.Width  = (int)(this.Width * this.Scale);
            this.Height = (int)(this.Height * this.Scale);

            return(this);
        }
Exemple #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 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);
        }
Exemple #4
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);
        }
        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);
        }
        // Constructs regular noun set with given nouns
        public NounSet(ElementFactory elementFactory, IEdgeFactory edgeFactory, ISentenceGraph graph, params Noun[] args) : this(elementFactory, edgeFactory)
        {
            this.Nouns.AddRange(args);
            this.Id             = args[0].Id;
            this.DependencyType = args[0].DependencyType;

            foreach (var noun in args)
            {
                var edge = this.EdgeFactory.Create(this, this.Adpositions.SelectMany(a => a.GetAdpositions()).Select(a => a.ToString()).ToList());
                if (edge != null)
                {
                    graph.AddEdge(edge);
                    this.Adpositions.Clear();
                }
                else
                {
                    this.Adpositions.AddRange(noun.Adpositions);
                }

                noun.Adpositions.Clear();
            }
        }
        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);
        }