Not logged in : Login

About: VirtJenaSPARQLExample12     Goto   Sponge   NotDistinct   Permalink

An Entity of Type : atom:Entry, within Data Space : www.openlinksw.com associated with source document(s)
QRcode icon
http://www.openlinksw.com/describe/?url=http%3A%2F%2Fwww.openlinksw.com%2Fdataspace%2Fdav%2Fwiki%2FMain%2FVirtJenaSPARQLExample12

AttributesValues
has container
Date Created
maker
topic
described by
seeAlso
Date Modified
link
id
  • b6bd920306e6297e70bcd2da525dde63
content
  • %VOSWARNING% %META:TOPICPARENT{name="VirtJenaProvider"}% ---+ Virtuoso Jena Provider - SPARQL Example 12 <verbatim> import com.hp.hpl.jena.query.*; import com.hp.hpl.jena.graph.Triple; import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.rdf.model.*; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.vocabulary.DC; import java.util.Iterator; import virtuoso.jena.driver.*; public class VirtuosoSPARQLExample12 { /** * Executes a SPARQL query against a virtuoso url and prints results. */ public static void main(String[] args) { String url; if(args.length == 0) url = "jdbc:virtuoso://localhost:1111"; else url = args[0]; Model m = VirtModel.openDatabaseModel("my:test", url, "dba", "dba"); m.removeAll(); Resource r1 = m.createResource("http://example.org/book#1") ; Resource r2 = m.createResource("http://example.org/book#2") ; r1.addProperty(DC.title, "SPARQL - the book") .addProperty(DC.description, "A book about SPARQL") ; r2.addProperty(DC.title, "Advanced techniques for SPARQL") ; String prolog = "PREFIX dc: <"+DC.getURI()+"> \n" ; // Query string. String queryString = prolog + "SELECT ?title WHERE {?x dc:title ?title}" ; System.out.println("Execute query=\n"+queryString) ; System.out.println() ; Query query = QueryFactory.create(queryString) ; System.out.println("\n==CASE 1 ==Parse ARQ Execute ARQ GraphStore Virtuoso"); //NOTE: query is parsed & executed by ARQ, so it works slow // and you can't use Virtuoso SPARQL features QueryExecution qexec = QueryExecutionFactory.create(query, m) ; // Or QueryExecutionFactory.create(queryString, model) ; System.out.println("Titles: ") ; try { ResultSet rs = qexec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; RDFNode x = rb.get("title") ; if ( x.isLiteral() ) { Literal titleStr = (Literal)x ; System.out.println(" "+titleStr) ; } else System.out.println("Strange - not a literal: "+x) ; } } finally { qexec.close() ; } System.out.println("\n==CASE 2a ==Parse ARQ Execute Virtuoso GraphStore Virtuoso"); //NOTE: query is parsed by ARQ, so you can't use Virtuoso SPARQL features // execution speed fast VirtuosoQueryEngine.register(); qexec = QueryExecutionFactory.create(query, m) ; // Or QueryExecutionFactory.create(queryString, model) ; System.out.println("Titles: ") ; try { ResultSet rs = qexec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; RDFNode x = rb.get("title") ; if ( x.isLiteral() ) { Literal titleStr = (Literal)x ; System.out.println(" "+titleStr) ; } else System.out.println("Strange - not a literal: "+x) ; } } finally { qexec.close() ; } VirtuosoQueryEngine.unregister(); System.out.println("\n==CASE 2b ==Parse ARQ Execute Virtuoso GraphStore Virtuoso"); //NOTE: query is parsed by ARQ, so you can't use Virtuoso SPARQL features // execution speed fast qexec = VirtuosoQueryExecutionFactory.create(query, m) ; System.out.println("Titles: ") ; try { ResultSet rs = qexec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; RDFNode x = rb.get("title") ; if ( x.isLiteral() ) { Literal titleStr = (Literal)x ; System.out.println(" "+titleStr) ; } else System.out.println("Strange - not a literal: "+x) ; } } finally { qexec.close() ; } System.out.println("\n==CASE 3 ==Parse & Execute Virtuoso GraphStore Virtuoso"); //NOTE: query is parsed & executed by Virtuoso, so you can use all Virtuoso SPARQL features // execution speed fast qexec = VirtuosoQueryExecutionFactory.create(queryString, m) ; System.out.println("Titles: ") ; try { ResultSet rs = qexec.execSelect() ; for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; RDFNode x = rb.get("title") ; if ( x.isLiteral() ) { Literal titleStr = (Literal)x ; System.out.println(" "+titleStr) ; } else System.out.println("Strange - not a literal: "+x) ; } } finally { qexec.close() ; } } } </verbatim>
Title
  • VirtJenaSPARQLExample12
has creator
is described using
atom:source
atom:updated
  • 2014-04-29T00:54:24Z
atom:title
  • VirtJenaSPARQLExample12
atom:author
label
  • VirtJenaSPARQLExample12
topic
atom:published
  • 2011-08-18T11:21:49Z
type
is topic of
is interest of
Faceted Search & Find service v1.17_git63 as of Apr 23 2021


Alternative Linked Data Documents: iSPARQL | ODE     Content Formats:       RDF       ODATA       Microdata      About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 08.03.3322 as of Jun 3 2021, on Linux (x86_64-generic-linux-glibc25), Single-Server Edition (30 GB total memory)
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2021 OpenLink Software