/** * 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); }
/** * Given a collection of nodes from srcGraph, generates a new * SemanticGraph based off the subset represented by those nodes. * This uses the same vertices as in the original graph, which * allows for equality and comparisons between the two graphs. */ public static SemanticGraph makeGraphFromNodes(Collection<IndexedWord> nodes, SemanticGraph srcGraph) { if (nodes.size() == 1) { SemanticGraph retSg = new SemanticGraph(); for (IndexedWord node :nodes) retSg.addVertex(node); return retSg; } if (nodes.isEmpty()) { return null; } // TODO: if any nodes are not connected to edges in the original // graph, this will leave them out List<SemanticGraphEdge> edges = new ArrayList<>(); for (IndexedWord nodeG : nodes) { for (IndexedWord nodeD: nodes) { Collection<SemanticGraphEdge> existingEdges = srcGraph.getAllEdges(nodeG, nodeD); if (existingEdges != null) { edges.addAll(existingEdges); } } } return SemanticGraphFactory.makeFromEdges(edges); }
/** * 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); }
/** * 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); }
/** * Given a collection of nodes from srcGraph, generates a new * SemanticGraph based off the subset represented by those nodes. * This uses the same vertices as in the original graph, which * allows for equality and comparisons between the two graphs. */ public static SemanticGraph makeGraphFromNodes(Collection<IndexedWord> nodes, SemanticGraph srcGraph) { if (nodes.size() == 1) { SemanticGraph retSg = new SemanticGraph(); for (IndexedWord node :nodes) retSg.addVertex(node); return retSg; } if (nodes.isEmpty()) { return null; } // TODO: if any nodes are not connected to edges in the original // graph, this will leave them out List<SemanticGraphEdge> edges = new ArrayList<>(); for (IndexedWord nodeG : nodes) { for (IndexedWord nodeD: nodes) { Collection<SemanticGraphEdge> existingEdges = srcGraph.getAllEdges(nodeG, nodeD); if (existingEdges != null) { edges.addAll(existingEdges); } } } return SemanticGraphFactory.makeFromEdges(edges); }
/** * Given a collection of nodes from srcGraph, generates a new * SemanticGraph based off the subset represented by those nodes. * This uses the same vertices as in the original graph, which * allows for equality and comparisons between the two graphs. */ public static SemanticGraph makeGraphFromNodes(Collection<IndexedWord> nodes, SemanticGraph srcGraph) { if (nodes.size() == 1) { SemanticGraph retSg = new SemanticGraph(); for (IndexedWord node :nodes) retSg.addVertex(node); return retSg; } if (nodes.isEmpty()) { return null; } // TODO: if any nodes are not connected to edges in the original // graph, this will leave them out List<SemanticGraphEdge> edges = new ArrayList<>(); for (IndexedWord nodeG : nodes) { for (IndexedWord nodeD: nodes) { Collection<SemanticGraphEdge> existingEdges = srcGraph.getAllEdges(nodeG, nodeD); if (existingEdges != null) { edges.addAll(existingEdges); } } } return SemanticGraphFactory.makeFromEdges(edges); }