Skip to content

Instantly share code, notes, and snippets.

@rafaelportela
Created July 8, 2014 01:11
Show Gist options
  • Save rafaelportela/451f868807df8c72b771 to your computer and use it in GitHub Desktop.
Save rafaelportela/451f868807df8c72b771 to your computer and use it in GitHub Desktop.
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.VCARD;
import static com.hp.hpl.jena.query.QueryExecutionFactory.*;
public class Main {
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
Resource portela = model
.createResource("http://portela/me")
.addProperty(VCARD.FN, "Rafael Portela");
Resource marcos = model
.createResource("http://marcos/him")
.addProperty(VCARD.FN, "Markone");
Property likes = model.createProperty("http://tw.com/verbs#", "likes");
Property java = model.createProperty("http://tw.com/langs#", "java");
Property ruby = model.createProperty("http://tw.com/langs#", "ruby");
portela.addProperty(likes, java);
portela.addProperty(likes, ruby);
marcos.addProperty(likes, java);
marcos.addProperty(likes, ruby);
String query = "SELECT ?s WHERE {?s <"+ likes +"> <"+ ruby +"> }";
ResultSet resultSet = create(query, model).execSelect();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.nextSolution();
// ?s = <http://marcos/him>
// ?s = <http://portela/me>
System.out.println(solution);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment