1 2 3 4 5 6 7 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?url FROM <bloggers.rdf> WHERE { ?contributor foaf:name "Jon Foobar" . ?contributor foaf:weblog ?url . } |
1 2 3 4 5 | $ export ARQROOT=~/ARQ-0.9.5 $ chmod +rx $ARQROOT/bin/* $ export PATH=$PATHARQROOT/bin $ sparql Usage: [--data URL] [exprString | --query file] |
1 2 3 4 5 6 | $ sparql --query jon-url.rq ---------------------------- | url | ============================ | <http://foobar.xx/blog> | ---------------------------- |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // Open the bloggers RDF graph from the filesystem InputStream in = new FileInputStream(new File("bloggers.rdf")); // Create an empty in-memory model and populate it from the graph Model model = ModelFactory.createMemModelMaker().createModel(); model.read(in,null); // null base URI, since model URIs are absolute in.close(); // Create a new query String queryString = "REFIX foaf: <http://xmlns.com/foaf/0.1/> " + "SELECT ?url " + "WHERE {" + " ?contributor foaf:name \"Jon Foobar\" . " + " ?contributor foaf:weblog ?url . " + " }"; Query query = QueryFactory.create(queryString); // Execute the query and obtain results QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSet results = qe.execSelect(); // Output query results ResultSetFormatter.out(System.out, results, query); // Important - free up resources used running the query qe.close(); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |