コード例 #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(Verb verb, ISentenceGraph graph)
        {
            // Skip copula
            if (this.DependencyTypeHelper.IsCopula(verb.DependencyType))
            {
                return(this);
            }

            IProcessable processElement = this;

            // Process all depending drawables of the verb
            if (verb.DependingDrawables.Count != 0)
            {
                verb.DependingDrawables.ForEach(dd => processElement = processElement.Process(dd, graph));
                verb.DependingDrawables.Clear();
            }

            // Process all related actions
            verb.RelatedActions.ForEach(ra => processElement.Process(ra, graph));
            verb.RelatedActions.Clear();

            // Process non used adposition
            if (verb.DrawableAdposition != null)
            {
                processElement.Process(verb.DrawableAdposition, graph);
                verb.DrawableAdposition = null;
            }

            // Replace verb object in the graph
            if (verb.Object != null)
            {
                if (verb.Object is NounSet)
                {
                    ((NounSet)verb.Object).Nouns.ForEach(n =>
                    {
                        if (graph.Vertices.Contains(n))
                        {
                            graph.ReplaceVertex((IDrawable)processElement, n);
                        }
                    });
                }

                if (graph.Vertices.Contains((IDrawable)verb.Object))
                {
                    graph.ReplaceVertex((IDrawable)processElement, (IDrawable)verb.Object);
                }
            }

            // Process only non negated verbs
            if (!verb.IsNegated && processElement == this)
            {
                foreach (var noun in this.Nouns)
                {
                    noun.Process(verb, graph);
                }
            }

            return(processElement);
        }
コード例 #3
0
        private IProcessable ProcessElement(Verb verb, ISentenceGraph graph)
        {
            // skip copula
            if (this.DependencyHelper.IsCopula(verb.DependencyType))
            {
                return(this);
            }

            IProcessable processElement = this;

            // Don't process negated verb
            if (!verb.IsNegated)
            {
                this.Actions.Add(verb);
            }

            // Process all depending drawables
            if (verb.DependingDrawables.Count != 0)
            {
                verb.DependingDrawables.ForEach(dd => processElement = processElement.Process(dd, graph));
                verb.DependingDrawables.Clear();
            }

            // Process all related actions
            verb.RelatedActions.ForEach(ra => processElement.Process(ra, graph));
            verb.RelatedActions.Clear();

            // Process unprocessed adposition
            if (verb.DrawableAdposition != null)
            {
                processElement.Process(verb.DrawableAdposition, graph);
            }

            // Replace verb object in the graph
            if (verb.Object != null)
            {
                if (verb.Object is NounSet ns)
                {
                    ns.Nouns.ForEach(n =>
                    {
                        if (graph.Vertices.Contains(n))
                        {
                            graph.ReplaceVertex((IDrawable)processElement, n);
                        }
                    });
                }

                if (graph.Vertices.Contains((IDrawable)verb.Object))
                {
                    graph.ReplaceVertex((IDrawable)processElement, (IDrawable)verb.Object);
                }
            }

            return(processElement);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }