Catrina, thinking about this further, since ASK will terminate with
"true" once a match is found to the query, the following will let you
know whether or not a graph exists:

ASK
WHERE {
   GRAPH ?GRAPH_VAR {?s ?p ?o}
}

...where ?GRAPH_VAR is pre-bound to the graph you are looking for.  If
a match is found, ASK returns a "true", after finding the first triple
in the graph.  If the graph does not exist (in a TBS workspace), ASK
returns a "false".

-- Scott

On Oct 12, 12:00 pm, Scott Henninger <[email protected]>
wrote:
> Catrina; What is the use case here?  For finding whether there is any
> data in a graph, either of these examples will work.  These are pretty
> core to Jena, so I'm not entirely sure how that would improve on
> either of these (?).
>
> -- Scott
>
> On Oct 12, 11:48 am, Catrina <[email protected]>
> wrote:
>
> > Yes, I thought of that too and I agree it would be more efficient.
> > But, I wondered about the cases where the Ontology might not be
> > defined.  As you said in most cases it is defined.  That's where I
> > thought my first query example could be handy.  Maybe I'll look at
> > creating another custom sparqlmotion module and handle this in java
> > with jena.
>
> > Thanks
>
> > On Oct 12, 11:31 am, Scott Henninger <[email protected]>
> > wrote:
>
> > > Catrina; The second query, using smf:buildURI() to create a resource,
> > > should work.  A NPE will occur when executing tops:definesStatements
> > > if the resource defined for ?baseURI does not exist in the model the
> > > query is applied to.
>
> > > Also, I note that your query is returning all triples for the graph,
> > > but you are only interested in whether or not a triple is defined for
> > > the graph.  In that case, it will be more efficient to use a triple
> > > pattern.  For example, in most cases the owl:Ontology is defined for a
> > > graph.  So you could use:
>
> > > ASK
> > > WHERE
> > > {  LET (?baseURI := smf:buildURI("http://someGraphUri";)) .
> > >    ?baseURI a owl:Ontology .
>
> > > }
>
> > > …and only one triple will need to be found to for ASK to be true.
>
> > > -- Scott
>
> > > On Oct 12, 8:23 am, Catrina <[email protected]>
> > > wrote:
>
> > > > Is it possible to use <urn:var:GRAPH_VAR> in an ASK query?  For
> > > > example, I want to dynamically determine if a graph exists with
> > > > something like the following where I previously set GRAPH_VAR.
> > > > ASK WHERE {
> > > >     GRAPH <urn:var:GRAPH_VAR> {
> > > >     } .
>
> > > > }
>
> > > > I tried something like the following, but I get a NullPointerException
> > > > if the graph does not exists.
> > > > ASK WHERE {
> > > >         LET (?baseURI := smf:buildURI("http://someGraphUri";)) .
> > > >     ?baseURI tops:definesStatements (?subject ?predicate ?object) .
>
> > > > }
>
> > > > Thanks,
> > > > Catrina- Hide quoted text -
>
> > > - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

Reply via email to