/** * Given a set of edges that form a rooted and connected graph, returns a Semgrex pattern * corresponding to it. * @throws Exception */ public static String semgrexFromGraph(Iterable<SemanticGraphEdge> edges, boolean matchTag, boolean matchWord, Map<IndexedWord, String> nodeNameMap) throws Exception { SemanticGraph sg = SemanticGraphFactory.makeFromEdges(edges); return semgrexFromGraph(sg, matchTag, matchWord, nodeNameMap); }
/** * Returns the set of incoming edges for the given node that have the given * relation. * * Because certain edges may remain in string form (prepcs), check for both * string and object form of relations. */ public static List<SemanticGraphEdge> incomingEdgesWithReln(IndexedWord node, SemanticGraph sg, GrammaticalRelation reln) { return edgesWithReln(sg.incomingEdgeIterable(node), reln); }
private static void addPassiveAgentToReln(SemanticGraph sg, IndexedWord gov, IndexedWord mod, IndexedWord caseMarker) { SemanticGraphEdge edge = sg.getEdge(gov, mod); GrammaticalRelation reln = UniversalEnglishGrammaticalRelations.AGENT; edge.setRelation(reln); }
/** * This creates a new graph based off the given, but uses the existing nodes objects. */ public static SemanticGraph duplicateKeepNodes(SemanticGraph sg) { SemanticGraph retSg = new SemanticGraph(); for (IndexedWord node : sg.vertexSet()) { retSg.addVertex(node); } retSg.setRoots(sg.getRoots()); for (SemanticGraphEdge edge : sg.edgeIterable()) { retSg.addEdge(edge.getGovernor(), edge.getDependent(), edge.getRelation(), edge.getWeight(), edge.isExtra()); } return retSg; }
public boolean containsEdge(SemanticGraphEdge edge) { return containsEdge(edge.getSource(), edge.getTarget()); }
public static void getSubTreeEdgesHelper(IndexedWord vertice, SemanticGraph sg, Set<SemanticGraphEdge> tabuEdges) { for (SemanticGraphEdge edge : sg.outgoingEdgeIterable(vertice)) { if (!tabuEdges.contains(edge)) { IndexedWord dep = edge.getDependent(); tabuEdges.add(edge); getSubTreeEdgesHelper(dep, sg, tabuEdges); } } }
public boolean attachedNegatedVerb(IndexedWord vertex) { for (IndexedWord parent : getParents(vertex)) { if (isNegatedVerb(parent)) { return true; } } return false; }
/** * Produces an Uncollapsed (basic) SemanticGraph. */ public static SemanticGraph generateUncollapsedDependencies(GrammaticalStructure gs) { return makeFromTree(gs, Mode.BASIC, GrammaticalStructure.Extras.NONE, null); }
/** * Checks for outgoing edges of the node, in the given graph, which contain * the given relation. Relations are matched on if they are GrammaticalRelation * objects or strings. */ public static List<SemanticGraphEdge> outgoingEdgesWithReln(IndexedWord node, SemanticGraph sg, GrammaticalRelation reln) { return edgesWithReln(sg.outgoingEdgeIterable(node), reln); }
public static String printVertices(SemanticGraph sg) { return printVertices(sg, new PrintVerticeParams()); }
/** * Returns a {@code String} representation of this semantic graph, * formatted by the supplied semantic graph formatter. */ public String toFormattedString(SemanticGraphFormatter formatter) { return formatter.formatSemanticGraph(this); }
/** * Returns an unnamed dot format digraph. * Nodes will be labeled with the word and edges will be labeled * with the dependency. */ public String toDotFormat() { return toDotFormat(""); }
/** * Used to make a mapping that lets you create "anonymous" versions of shared nodes between two * graphs (given in the arg) using the shared prefix. */ public static Map<IndexedWord, IndexedWord> makeGenericVertices(Iterable<IndexedWord> verts) { return anonymyizeNodes(verts, SHARED_NODE_ANON_PREFIX); }
/** * Given a SemanticGraph, creates a SemgrexPattern string based off of this graph. * NOTE: the word() value of the vertice is the name to reference * NOTE: currently presumes there is only one root in this graph. * TODO: see if Semgrex can allow multiroot patterns * @param sg SemanticGraph to base this pattern on. */ public static String semgrexFromGraph(SemanticGraph sg, boolean matchTag, boolean matchWord, Map<IndexedWord, String> nodeNameMap) throws Exception { return semgrexFromGraph(sg, null, matchTag, matchWord, nodeNameMap); }
/** * * Produces an enhanced++ dependencies SemanticGraph. */ public static SemanticGraph generateEnhancedPlusPlusDependencies(Tree tree){ return makeFromTree(tree, Mode.ENHANCED_PLUS_PLUS, GrammaticalStructure.Extras.NONE); }
/** * Returns a {@code String} representation of this semantic graph, * formatted by the default semantic graph formatter. */ public String toFormattedString() { return formatter.formatSemanticGraph(this); }
/** * Returns a dot format digraph with the given name. * Nodes will be labeled with the word and edges will be labeled * with the dependency. */ public String toDotFormat(String graphname) { return toDotFormat(graphname, CoreLabel.OutputFormat.VALUE_TAG_INDEX); }
/** * @see #makeFromTree(Tree, Mode, GrammaticalStructure.Extras, Predicate */ public static SemanticGraph makeFromTree(Tree tree, Mode mode, GrammaticalStructure.Extras includeExtras, Predicate<TypedDependency> filter) { return makeFromTree(tree, mode, includeExtras, filter, false); }
/** * Produces an Uncollapsed (basic) SemanticGraph. */ public static SemanticGraph generateUncollapsedDependencies(Tree tree) { return makeFromTree(tree, Mode.BASIC, GrammaticalStructure.Extras.NONE); }
/** * @see #makeFromTree(Tree, Mode, GrammaticalStructure.Extras, Predicate */ public static SemanticGraph makeFromTree(Tree tree, Mode mode, GrammaticalStructure.Extras includeExtras, Predicate<TypedDependency> filter, boolean originalDependencies) { return makeFromTree(tree, mode, includeExtras, filter, originalDependencies, INCLUDE_PUNCTUATION_DEPENDENCIES); }