Created
May 7, 2010 15:35
-
-
Save kendall/393596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
aQuery.setHint(RdfQuery.HINT_ENTITY_CLASS, Book.class); | |
// set the parameter in the query to the value for the min price | |
// parameters are prefixed with ?? -- this differs slightly from JPQL | |
aQuery.setParameter("min", 30); | |
// now execute the query to get the list of all books which are $30 USD | |
List aResults = aQuery.getResultList(); | |
// 233 results | |
System.err.println("Num Results: " + aResults.size()); | |
// print the titles of the first five results | |
for (int i = 0; i < 5; i++) { | |
Book aBookResult = (Book) aResults.get(i); | |
System.err.println(aBookResult.getTitle()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment