1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package itsudparis.application;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import java.io.IOException;
import java.io.OutputStream;
/**
*
* @author driss
*/
public class Testquery {
public static void main(String[] args) {
String service ="http://dbpedia.org/sparql";
String queryString = "PREFIX dbpprop: <http://dbpedia.org/property/> "+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> "+
" SELECT DISTINCT ?book ?titre ?labelGenre ?pages ?lang ?nom_auteur ?nationalite"+
" WHERE {"+
"?book a <http://dbpedia.org/ontology/Book>."+
"?book dbpprop:titleOrig ?titre."+
"?book dbpprop:pages ?pages."+
"?book dbpprop:language ?langage."+
"?langage rdfs:label ?lang ."+
"?book dbpedia-owl:author ?author."+
"?author dbpprop:birthName ?nom_auteur."+
"?book dbpprop:genre ?genre."+
"?genre rdfs:label ?labelGenre."+
"?author dbpprop:birthName ?nom_auteur."+
"{?author dbpprop:nationality ?nationalite . FILTER regex(?nationalite, \"^French\")}"+
"UNION"+
"{?author dbpprop:nationality ?nationalite . FILTER regex(?nationalite, \"^American\")}"+
"UNION"+
"{?author dbpprop:nationality ?nationalite . FILTER regex(?nationalite, \"^Italian\")}"+
"UNION"+
"{?author dbpprop:nationality ?nationalite . FILTER regex(?nationalite, \"^Russian\")}"+
"Filter langMatches(lang(?lang),'fr')."+
"Filter langMatches(lang(?titre),'en')."+
"Filter langMatches(lang(?labelGenre),'fr')."+
"} LIMIT 40";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.sparqlService(service, query);
try {
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
} finally { qe.close() ; }
}
} |
Partager