Parameterized Query for ex:Person (not full URI)

0 views
Skip to first unread message

justforthe...@gmail.com

unread,
Mar 17, 2016, 1:58:46 PM3/17/16
to Stardog
I would like to run a parameterized query (http://docs.stardog.com/java/snarl/com/complexible/stardog/api/Query.html). All the examples I can find use full URI addresses such as: IRI PERSON = Values.iri("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Person"); aQuery.parameter("type", PERSON);


However, I would like to use "ex:Person". But when I do:

 aQuery.parameter( "type", Values.iri("ex:Person") );
 
It gets translated into the query to:

PREFIX ......
# Overrides by the API: 
# PARAMETERS ( ?type ) {
# <ex:Person>
# }

Like a full URI, so the query returns no values. How can I achieve this? I have seen the following example that seems to work, but I cannot figure it out in my case. The Javadocs don't seem to contain any useful hint.

Model aGraph = Models2.newModel(Values.statement(Values.iri("urn:subj"),
Values.iri("urn:pred"), Values.iri("urn:obj"))); Thanks.

Michael Grove

unread,
Mar 17, 2016, 2:21:54 PM3/17/16
to stardog
On Thu, Mar 17, 2016 at 1:58 PM, <justforthe...@gmail.com> wrote:
I would like to run a parameterized query (http://docs.stardog.com/java/snarl/com/complexible/stardog/api/Query.html). All the examples I can find use full URI addresses such as: IRI PERSON = Values.iri("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Person");

If you've defined a namespace for `ex` that corresponds to `http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#`, `ex:Person` and the full IRI are equivalent.

You can pre-associate namespaces with a database so that you can use qnames in a query when writing it stand alone, but to create an IRI object in the API, you *must* provide a complete IRI.  If you want to be able to do the equivalent of `iri("ex:Person")` you'll need to write a utility function to get the namespaces associated with the database, parse the qname, and create the resulting IRI to pass to `Values#iri`.

Cheers,

Mike
 
aQuery.parameter("type", PERSON);


However, I would like to use "ex:Person". But when I do:

 aQuery.parameter( "type", Values.iri("ex:Person") );
 
It gets translated into the query to:

PREFIX ......
# Overrides by the API: 
# PARAMETERS ( ?type ) {
# <ex:Person>
# }

Like a full URI, so the query returns no values. How can I achieve this? I have seen the following example that seems to work, but I cannot figure it out in my case. The Javadocs don't seem to contain any useful hint.

Model aGraph = Models2.newModel(Values.statement(Values.iri("urn:subj"),
Values.iri("urn:pred"), Values.iri("urn:obj"))); Thanks.

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Zachary Whitley

unread,
Mar 17, 2016, 3:15:06 PM3/17/16
to sta...@clarkparsia.com
This is working because urn isn't a prefix here, a urn is a valid type of iri.
I think what's happening with your example of ex:Person is its being interpreted as a iri with a protocol type of ex: hence the <ex:Person>. 

Please don't interpret this as dismissive but why would you want to do that? Uri identifiers are supposed to be stable. The only reason I can think of to do that is if you expect the predefined prefix in the database to be changing. 


--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
---
You received this message because you are subscribed to the Google Groups "Stardog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stardog+u...@clarkparsia.com.

Zachary Whitley

unread,
Mar 17, 2016, 3:40:45 PM3/17/16
to sta...@clarkparsia.com


On Mar 17, 2016, at 1:58 PM, justforthe...@gmail.com wrote:

There is a two argument method for Values.iri that takes a prefix and a local part if that's what you're after. http://docs.stardog.com/java/snarl/com/complexible/common/rdf/model/Values.html#iri-java.lang.String-java.lang.String-

Evren Sirin

unread,
Mar 17, 2016, 3:57:25 PM3/17/16
to Stardog
On Thu, Mar 17, 2016 at 3:40 PM, Zachary Whitley <zachary...@gmail.com> wrote:
There is a two argument method for Values.iri that takes a prefix and a local part if that's what you're after. http://docs.stardog.com/java/snarl/com/complexible/common/rdf/model/Values.html#iri-java.lang.String-java.lang.String-




It is impossible to tell since there is no explanation in the javadocs but the first argument to that function should actually be the full namespace IRI. So Values.iri(ns, localName) is functionally equivalent to Values.iri(ns + localName). One can use the connection to first retrieve stored namespaces, find the namespace that corresponds to the prefix and then pass it to either of the functions to create the IRI. That's roughly what stardog query command does when you pass query parameters using stored namespaces. But for a specific namespace in an application it would make more sense to declare a constant in the code for the namespace and directly use that instead of dealing with non-stable prefixes. 

Best,
Evren


Zachary Whitley

unread,
Mar 17, 2016, 3:59:24 PM3/17/16
to sta...@clarkparsia.com
I was just looking through the javadoc a to see where you could get the namespaces defined in the database. Didn't see where you'd get that. 

Evren Sirin

unread,
Mar 17, 2016, 4:03:18 PM3/17/16
to Stardog

Zachary Whitley

unread,
Mar 17, 2016, 4:11:14 PM3/17/16
to sta...@clarkparsia.com


> On Mar 17, 2016, at 4:02 PM, Evren Sirin <ev...@complexible.com> wrote:
>
> It is the Connection.namespaces function:
>
> http://docs.stardog.com/java/snarl/com/complexible/stardog/api/Connection.html#namespaces--
>

Ah, thought it was just for builtins. Got it. Thanks.

justforthe...@gmail.com

unread,
Mar 21, 2016, 1:31:32 PM3/21/16
to Stardog
Yes, basically what I try to do is to abstract my code from the database as much as possible. I think it is a good practice to separate components (loosely coupled).

My idea is to have ex:whatever in the code, but define the namespace "ex" in the database. This way I do not have to make code changes, digging into classes that might run queries and recompile code, if the namespace changes, for example. 

justforthe...@gmail.com

unread,
Mar 21, 2016, 1:33:59 PM3/21/16
to Stardog
It seems that what I wanted is not possible... BUT This is actually a potential solution to have a loosely coupled code.... Thanks for the hint!
Reply all
Reply to author
Forward
0 new messages