Skip to content

Instantly share code, notes, and snippets.

View kendall's full-sized avatar

Kendall Clark kendall

View GitHub Profile
@RdfProperty("dc:title")
private String title;
@RdfProperty("dc:publisher")
private String publisher;
@RdfProperty("dc:issued")
private Date issued;
@RdfProperty("frbr:embodiment")
Empire.init(new OpenRdfEmpireModule());
EntityManager aManager = Persistence.createEntityManagerFactory("oreilly")
.createEntityManager();
Book aBook = aManager.find(Book.class, URI.create("urn:x-domain:oreilly.com:product:9780596514129.IP"));
// prints: Switching to the Mac: The Missing Manual, Leopard Edition
System.err.println(aBook.getTitle());
// prints: O'Reilly Media / Pogue Press
System.err.println(aBook.getPublisher());
Book aNewBookCopy = aManager.find(Book.class, aNewBook.getRdfId());
// true!
System.err.println(aNewBook.equals(aNewBookCopy));
// let's edit our book...maybe we changed the title and published as a PDF
aNewBook.setTitle("Return of the Empire");
// create a new manifestation
Manifestation aPDFManifestation = new Manifestation();
aPDFManifestation.setIssued(new Date());
// set the dc:type attribute
aPDFManifestation.setType(URI.create("http://purl.oreilly.com/product-types/PDF"));
aNewBook.setEmbodiments(Arrays.asList(aPDFManifestation));
// but can be refreshed...
aManager.refresh(aNewBookCopy);
// and now contains the correct, up-to-date information
System.err.println(aNewBookCopy.getTitle());
System.err.println(aNewBookCopy.getEmbodiments());
// Lastly, we can use the query API to run arbitrary sparql queries
// create a jpql-style partial SPARQL query (JPQL is currently unsupported)
Query aQuery = aManager.createQuery("where { ?result frbr:embodiment ?manifest." +
" ?foo <http://purl.org/goodrelations/v1#typeOfGood> ?manifest . " +
" ?foo <http://purl.org/goodrelations/v1#hasPriceSpecification> ?price. " +
" ?price <http://purl.org/goodrelations/v1#hasCurrencyValue> ?value. " +
" ?price <http://purl.org/goodrelations/v1#hasCurrency> \"USD\"@en." +
" filter(?value > ??min). }");
// this query should return instances of type Book
// now we can delete our new book
aManager.remove(aNewBook);
// false!
System.err.println(aManager.contains(aNewBook));
// but the new manifestation still exists, since we did not specify that deletes should cascade...
// true!
System.err.println(aManager.contains(aPDFManifestation));
{
"service-discovery" : {
"response-mimetype" : [ "text/json", "application/rdf+xml", "application/x-turtle", "application/x-ntriples" ],
"endpoint" : {
"http-methods" : [ "GET" ],
"url" : "http://foo:8080/"
}
},
"knowledge-bases" : [ {
"name" : "wine",