//private IEnumerable<WordPartOfSpeechVertex> PartsOfSpeechSpannedBy(ParentElementBuilder parentElement) //{ // IEnumerable<PartOfSpeechBuilder> partsOfSpeechInSubtree = parentElement.GetElementsOfTypeInSubtree<PartOfSpeechBuilder>(); // return PartsOfSpeech.Where(partOfSpeechVertex => partsOfSpeechInSubtree.Contains(partOfSpeechVertex.Model)); //} private void RealignPartsOfSpeechWithTokens() { IDictionary <ElementVertex, Rect> newRectangles = new Dictionary <ElementVertex, Rect>(); foreach (ElementVertex eachElementVertex in Rectangles.Keys) { newRectangles.Add(eachElementVertex, Rectangles[eachElementVertex]); } foreach (WordContentVertex eachContentVertex in WordContents) { Rect tokenRectangle = Rectangles[eachContentVertex]; WordPartOfSpeechVertex correspondingPartOfSpeech = PartOfSpeechCorrespondingTo(eachContentVertex); Rect oldPartOfSpeechRectangle = Rectangles[correspondingPartOfSpeech]; double newPartOfSpeechX = tokenRectangle.X + ((tokenRectangle.Width - oldPartOfSpeechRectangle.Width) / 2); newRectangles[correspondingPartOfSpeech] = new Rect(new Point(newPartOfSpeechX, oldPartOfSpeechRectangle.Y), oldPartOfSpeechRectangle.Size); } Rectangles = newRectangles; }
internal static ElementBuilderGraph Of(IElementBuilder model) { ElementBuilderGraph graph = new ElementBuilderGraph(); AddSubtreeIncludingRoot(model); //AddSyntacticRelationEdges(); return(graph); ElementBuilderVertex AddSubtreeIncludingRoot(IElementBuilder builder, ElementBuilderVertex parentVertex = null) { switch (builder) { case ParentElementBuilder peb: return(AddSubtree(peb)); case WordElementBuilder web: return(AddLeafVertexFor(web)); default: throw new InvalidOperationException("ElementGraphBuilder doesn't handle this ElementBuilder type"); } ParentElementVertex AddSubtree(ParentElementBuilder parentElementBuilder) { ParentElementVertex parentElementVertex = new ParentElementVertex(parentElementBuilder); graph.AddVertex(parentElementVertex); foreach (ElementBuilder eachChild in parentElementBuilder.Children) { ElementBuilderVertex eachChildVertex = AddSubtreeIncludingRoot(eachChild, parentElementVertex); graph.AddEdge(new ParentElementToChildEdge(parentElementVertex, eachChildVertex, parentElementBuilder.RoleFor(eachChild))); } return(parentElementVertex); } WordPartOfSpeechVertex AddLeafVertexFor(WordElementBuilder wordElementBuilder) { WordPartOfSpeechVertex partOfSpeechVertex = new WordPartOfSpeechVertex(wordElementBuilder); graph.AddVertex(partOfSpeechVertex); // The token node is the one actually containing the word WordContentVertex contentVertex = new WordContentVertex(wordElementBuilder); graph.AddVertex(contentVertex); PartOfSpeechToContentEdge contentEdge = new PartOfSpeechToContentEdge(partOfSpeechVertex, contentVertex); graph.AddEdge(contentEdge); return(partOfSpeechVertex); } } //void AddSyntacticRelationEdges() //{ // foreach (PartOfSpeechVertex eachPartOfSpeechVertex in graph.PartsOfSpeech) // { // PartOfSpeechBuilder eachPartOfSpeechBuilder = eachPartOfSpeechVertex.Model; // foreach (SyntacticRelation eachDependency in eachPartOfSpeechBuilder.IncomingSyntacticRelations) // { // graph.AddEdge(new DependencyEdge(graph.TokenVertexFor(eachDependency.Governor), graph.TokenVertexFor(eachDependency.Dependent), eachDependency.Relation)); // } // } //} }
/// <summary>Return the vertex representing the word contents that correspond to <paramref name="partOfSpeech"/></summary> internal WordContentVertex WordContentsCorrespondingTo(WordPartOfSpeechVertex partOfSpeech) => WordContents.Single(vertex => vertex.Model == partOfSpeech.Model);