On Wed, Jan 29, 2014 at 9:07 PM, Paolo Ciccarese
<paolo.ciccar...@gmail.com> wrote:
> I am trying to check for the existence of a graph and if I execute this
> query in the Conductor
> ASK { GRAPH <http://example.org/tests/graph/001> { ?s ?p ?o . } }
> returns 'false' when the graph is not there.
>
> However, if I run the same query with Jena and the Virtuoso Jena Provider I
> always get back 'true':
>
> VirtGraph set = new VirtGraph ("jdbc:virtuoso://localhost:1111", "dba",
> "dba");
> String query = "ASK { GRAPH <http://example.org/tests/graph/001> { ?s ?p ?o
> . } }";
> Query sparql = QueryFactory.create(query);
> VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql,
> set);
> boolean result =  vqe.execAsk();
>
> Any advice that can help me out?

Hi Paolo,
try this:

boolean graphExists = false;

VirtGraph kb = new VirtGraph(
  graphName,
  graphAddress,
  graphUser,
  graphPassword
  );

Query query4graph = QueryFactory.create(
  Namespace.SPARQL_NS_DECLARATIONS + // include all namespaces
  "ASK { GRAPH <" + graphName + "> { $s $p $o . } }"
  );
VirtuosoQueryExecution vqe =
VirtuosoQueryExecutionFactory.create(query4graph, kb);
Boolean qresult = vqe.execAsk();
graphExists = qresult;
vqe.close();

if(graphExists) {
  System.err.println("Graph " + graphName + " exists");
} else {
  System.err.println("Graph " + graphName + " does NOT exist");
}

I used this code 2 days ago, I tested it and it works (which means
answers are consistent between jena and Virtuoso's conductor's SPARQL
query execution) with this setup:

$ virtuoso-t -?
Virtuoso Open Source Edition (multi threaded)
Version 6.1.4.3127-pthreads as of Feb  2 2013
Compiled for Linux (x86_64-pc-linux-gnu)

$ java -jar /usr/local/lib/virtuoso_jena_provider/virt_jena.jar
OpenLink Virtuoso(TM) Provider for Jena(TM) Version 2.6.2 [Build 1.5]

$ java -jar /usr/local/lib/virtuoso_jena_provider/virtjdbc3.jar
OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.62]


HTH
  Andrea

-- 
Andrea Bagnacani - altlabel
web: bagnacan.web.cs.unibo.it

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to