Hi Mirko,
But one more question just out of curiosity. I find it very strange
that accent characters ( ` ) are required around the iri()
function, not single or double quotes. I had tried surrounding the
function by single quotes ( ' iri(??)' ) or escaped double quotes
(\"iri(??) \" ) before, which both did not work for me:
PreparedStatement stmt = con.prepareStatement("SELECT ?x FROM
<http://www.mygraph.org> WHERE { ?x <http://purl.org/dc/elements/
1.1/creator 'iri(??)' }");
What's the reason for single quotes not working?
The problem is that SPARQL does not allow expressions in triple
patterns, so using quotes would be either literal string or cause an
error.
So there are two ways to write this:
{ ?s <p> ?some-new-o . filter ( ?some-new-o = iri(??)) }
or the shorthand:
{ ?s <p> `iri(??)` }
So `expn` means:
create a new invisible variable, place it here and add a nearby filter
that will compare this variable with the specified expression
Patrick
I have problems understanding parameters in sparql queries. I read
section 16.2.6 of the docs (http://docs.openlinksw.com/virtuoso/
rdfsparql.html#rdfsparqlinline
), but still don't succeed passing IRIs. I would appreciate an
example. E.g., how can I parametrize the object in the following
query:
SELECT ?x FROM <http://www.mygraph.org> WHERE { ?x <http://
purl.org/dc/elements/1.1/creator
<http://myusers/xyz> }
My attempt (in Java) returns nothing, presumably because the
parameter
is interpreted as a String value:
PreparedStatement stmt = con.prepareStatement("SELECT ?x FROM
<http://www.mygraph.org
WHERE { ?x <http://purl.org/dc/elements/1.1/creator> ?? }");
stmt.setString(1, "http://myusers/xyz");
I suggest you read the following part of the online documentation:
http://docs.openlinksw.com/virtuoso/rdfapiandsql.html
As you indeed thought a parameter like "http://myusers/xyz" is not
the same as the <http://myusers/xyz>. In some constructions
virtuoso is capable of determining the intended use of the
parameter from the context like "graph ??", but in other cases a
parameter will be interpreted as a String.
You can use the following construction (formatted for readability):
PreparedStatement stmt = con.prepareStatement ("
SELECT ?x FROM <http://www.mygraph.org>
WHERE { ?x <http://purl.org/dc/elements/1.1/creator> `iri(??)` }
");
stmt.setString(1, "http://myuser/xyz");
Best regards,
Patrick