Java Code Examples for com.hp.hpl.jena.graph.Node#equals()

The following examples show how to use com.hp.hpl.jena.graph.Node#equals() . 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: NeoGraph.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
	}
}