/// <summary> /// Returns a new /// <c>SemanticGraph</c> /// constructed from a given /// <see cref="Edu.Stanford.Nlp.Trees.Tree"/> /// with given options. /// This factory method is intended to replace a profusion of highly similar /// factory methods, such as /// <c>typedDependencies()</c> /// , /// <c>typedDependenciesCollapsed()</c> /// , /// <c>allTypedDependencies()</c> /// , /// <c>allTypedDependenciesCollapsed()</c> /// , etc. /// For a fuller explanation of the meaning of the boolean arguments, see /// <see cref="Edu.Stanford.Nlp.Trees.GrammaticalStructure"/> /// . /// </summary> /// <param name="tree">A tree representing a phrase structure parse</param> /// <param name="includeExtras"> /// Whether to include extra dependencies, which may /// result in a non-tree /// </param> /// <param name="filter">A filter to exclude certain dependencies; ignored if null</param> /// <param name="originalDependencies"> /// generate original Stanford dependencies instead of new /// Universal Dependencies /// </param> /// <returns>A SemanticGraph</returns> public static SemanticGraph MakeFromTree(Tree tree, SemanticGraphFactory.Mode mode, GrammaticalStructure.Extras includeExtras, IPredicate <TypedDependency> filter, bool originalDependencies, bool includePunctuationDependencies) { GrammaticalStructure gs; if (originalDependencies) { IPredicate <string> wordFilt; if (includePunctuationDependencies) { wordFilt = Filters.AcceptFilter(); } else { wordFilt = new PennTreebankLanguagePack().PunctuationWordRejectFilter(); } gs = new EnglishGrammaticalStructure(tree, wordFilt, new SemanticHeadFinder(true)); } else { IPredicate <string> tagFilt; if (includePunctuationDependencies) { tagFilt = Filters.AcceptFilter(); } else { tagFilt = new PennTreebankLanguagePack().PunctuationTagRejectFilter(); } gs = new UniversalEnglishGrammaticalStructure(tree, tagFilt, new UniversalSemanticHeadFinder(true)); } return(MakeFromTree(gs, mode, includeExtras, filter)); }
// static main private static GrammaticalStructure SemanticGraphToGrammaticalStructure(SemanticGraph sg) { /* sg.typedDependency() generates an ArrayList */ IList <TypedDependency> deps = (IList <TypedDependency>)sg.TypedDependencies(); IndexedWord root = deps[0].Gov(); TreeGraphNode rootNode = new TreeGraphNode(root); GrammaticalStructure gs = new UniversalEnglishGrammaticalStructure(deps, rootNode); return(gs); }