org.neo4j.cypher.javacompat.ExecutionEngine Java Examples
The following examples show how to use
org.neo4j.cypher.javacompat.ExecutionEngine.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Neo4JDb.java From knowledge-extraction with Apache License 2.0 | 6 votes |
private Node getNode(Label label, String key, Object value) { Node node = null; try (Transaction tx = graphDb.beginTx()) { ResourceIterator<Node> nodes = null; if (label != null){ nodes = graphDb.findNodesByLabelAndProperty( label, key, value).iterator(); } else { String validValue = StringEscapeUtils.escapeJavaScript((String) value); ExecutionEngine engine = new ExecutionEngine(graphDb); nodes = engine.execute( "START n=node(*)" + " WHERE n." + key + "=\"" + validValue + "\"" + " RETURN n").columnAs("n"); } if (nodes.hasNext()) { node = nodes.next(); } nodes.close(); } return node; }
Example #2
Source File: Neo4JDb.java From knowledge-extraction with Apache License 2.0 | 5 votes |
public void writeOutContent(String filename) { GlobalGraphOperations ops = GlobalGraphOperations.at(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); try (FileWriter writer = new FileWriter(filename); Transaction tx = graphDb.beginTx()) { for (Node n : ops.getAllNodes()) { writer.write("[" + n.getId() + "," + n.getProperty(PROP_NAME) + ",["); Iterator<Node> connected = engine.execute( "START s=node(" + n.getId() + ") MATCH s-[r]->n RETURN n").columnAs("n"); for (Node e : IteratorUtil.asIterable(connected)) { Iterator<String> rel = engine.execute( "START s=node(" + n.getId() + "), e=node(" + e.getId() + ") MATCH s-[r]->e RETURN r.value") .columnAs("r.value"); String relVal = rel.hasNext()? rel.next() : ""; writer.write("[" + e.getId() + "," + relVal + "],"); } writer.write("]]\n"); } tx.success(); } catch (IOException e1) { e1.printStackTrace(); } }
Example #3
Source File: NeoGraph.java From neo4jena with Apache License 2.0 | 4 votes |
/** * Find the given triple(s) from the graph. */ @Override public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) { //System.out.println("NeoGraph#find"); try(Transaction tx = graphdb.beginTx()) { StringBuffer query = new StringBuffer("MATCH triple="); query.append("(subject"); if(subject.equals(Node.ANY)) { query.append(":"+ LABEL_URI); //System.out.println("NeoGraph#find#Any:"+subject); } else if(subject.isURI()){ query.append(":"+LABEL_URI+" {uri:'"); query.append(subject.getURI()); query.append("'}"); //System.out.println("NeoGraph#find#URI:"+subject+subject.getURI()); } else { query.append(":" + LABEL_BNODE); //System.out.println("NeoGraph#find#"+subject); } query.append(")-[predicate]->(object"); //query.append("]->(object"); if(object.equals(Node.ANY)) { //query.append(" "); } else if(object.isURI()){ query.append(":"+LABEL_URI+" {uri:'"); query.append(object.getURI()); query.append("'}"); } else { query.append(":"+LABEL_LITERAL+" {value:'"); query.append(object.getLiteralValue()); query.append("'}"); } query.append(")"); //System.out.println("Predicate in query: " +getPrefixMapping().shortForm(predicate.getURI())); if(predicate.isURI()) { query.append("WHERE type(predicate)='"); query.append(getPrefixMapping().shortForm(predicate.getURI())); query.append("'"); } query.append("\nRETURN subject, type(predicate), object"); //System.out.println(query.toString()); ExecutionEngine engine = new ExecutionEngine(graphdb); ExecutionResult results = engine.execute(query.toString()); //System.out.println(results.dumpToString()); //System.out.println("NeoGraph#find#"+predicate); //System.out.println("NeoGraph#find#"+object); //System.out.println("NeoGraph#find#DONE"); return new ExecutionResultIterator(results, graphdb); } }
Example #4
Source File: Neo4jSingleInsertion.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
public Neo4jSingleInsertion(GraphDatabaseService neo4jGraph, File resultsPath) { super(GraphDatabaseType.NEO4J, resultsPath); this.neo4jGraph = neo4jGraph; engine = new ExecutionEngine(this.neo4jGraph); }