[topbraid-users] INSERT INTO <graph> question

61 views
Skip to first unread message

Arthur Keen

unread,
Apr 19, 2010, 12:47:54 PM4/19/10
to topbrai...@googlegroups.com
The SPARQL form: INSERT INTO <graph> does not allow a variable for the graph so something like INSERT INTO ?graph{...} WHERE GRAPH ?graph{...} is not valid SPARQL.
I tried to get around this constraint by parametrizing the query in a spin template so that I could create valid queries from the template by passing in a parameter sp:arg1 for the graph into the template, e.g., INSERT INTO ?arg1{...} WHERE..., but the syntax checker on the SPIN Template will not let it through. Is this the way to do this or is there some other way?

Arthur



--
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
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

Holger Knublauch

unread,
Apr 19, 2010, 4:43:55 PM4/19/10
to topbrai...@googlegroups.com
Hi Arthur,

I guess the underlying issue is that SPARQL has no formal notion of pre-bound variables. In SPIN templates (and many other real-world applications), those pre-bound variables are very convenient and powerful, but without this concept, having a variable as graph URI does not make sense, because the SPARQL queries would not be self-contained.

I have no plans to move SPIN beyond what ARQ (Jena's SPARQL engine) is able to parse as this would have a lot of undesired implications. Maybe a future SPARQL version adds a proper concept for pre-bound variables. I will try to follow up on this topic elsewhere, but in the meantime I am not aware of work-arounds for your use case.

Thanks,
Holger

Arthur Keen

unread,
Apr 21, 2010, 6:44:37 PM4/21/10
to topbrai...@googlegroups.com
Holger,

I was inspired to look at named graphs by a paper by Jeremy Carol's on using named graphs (instead of statement reification) for provenance (published around 2003), in which he shows how one could insert the statements resulting from a particular decision into a named graph and assert the rationale (provenance) for the decision as statements about the named graph, so that the provenance for a series of decisions (statements and rationale) could be captured in a series of named graphs.

When I tried to do this in SPARQL, I found that I could not construct an INSERT INTO for an arbitrary graph, which would be created at the decision point. So I thought I could leverage SPIN Template functionality to create graph-specific SPARQL INSERT INTO <graph> queries, but from your email, I understand that that won't work either. These kinds of things are probably easy to do inside Jena.

Arthur

Holger Knublauch

unread,
Apr 21, 2010, 6:49:10 PM4/21/10
to topbrai...@googlegroups.com
Yes with Jena this is possible. Basically you would need to create the SPARQL query string dynamically, and insert the URI of the target graph before compiling it into a Query object.

But since the ARQ parser won't allow variables as named graphs, we do not support this in SPIN yet.

Holger

Arthur Keen

unread,
Apr 21, 2010, 6:55:19 PM4/21/10
to topbrai...@googlegroups.com
Could I use the "Convert string to RDF" to construct the query in SPARQLMotion to achieve the same outcome as your jena suggestion?

Holger Knublauch

unread,
Apr 21, 2010, 6:59:35 PM4/21/10
to topbrai...@googlegroups.com
I would not recommend going down this route. Theoretically it might be enough to insert the missing triple into the SPIN expression tree, but I don't think this would be a clean and maintainable solution. It goes too far into the area of metaprogramming, even for my taste.

Holger

Arthur Keen

unread,
Apr 21, 2010, 7:05:30 PM4/21/10
to topbrai...@googlegroups.com
Holger,

Thanks very much for clarifying this.

Arthur

Scott Henninger

unread,
Apr 26, 2010, 12:08:46 PM4/26/10
to TopBraid Suite Users
Arthur; You can pass a string bound to ?updateQuery to a
PerformUpdate module. Of course, you will need to make sure that the
query is correct syntactically, including any bindings at run-time.

-- Scott
> For more options, visit this group athttp://groups.google.com/group/topbraid-users?hl=en

Arthur Keen

unread,
Apr 26, 2010, 12:42:46 PM4/26/10
to topbrai...@googlegroups.com
Thanks Scott. I will try that out.

Arthur Keen

unread,
May 3, 2010, 6:38:59 PM5/3/10
to topbrai...@googlegroups.com
Scott,

That works!  I tried this out, by coupling a "Bind By Select" to a "Perform Update" but have a question on how "PerformUpdate" figures out it can use ?updateQuery instead of the sml:updateQuery property?  When I first tried this, I tried to bind {?updateQuery} to sml:updateQuery, but that did not work, and on re-reading your email, I realized that you had simply told me to pass a string query bound to ?updateQuery to "Perform Update".  Does this only work for "perform update" or are there other modules where you can bind to a value to a variable that is named the same as a property on a downstream module?

Regards 
Arthur

FYI: I used the "Bind by select" SMS module to bind the query:

SELECT ?updateQuery
WHERE {
    LET (?updateQuery := "INSERT  INTO <http://tb-session> { :Aron rdf:type owl:Thing } WHERE {}") .
}

Then connected it to a "Perform Update" SMS module

Run the script


Arthur


On Apr 26, 2010, at 11:08 AM, Scott Henninger wrote:

Holger Knublauch

unread,
May 3, 2010, 6:46:00 PM5/3/10
to topbrai...@googlegroups.com
> Does this only work for "perform update" or are there other modules where you can bind to a value to a variable that is named the same as a property on a downstream module?

This works everywhere in SPARQLMotion.

Holger

Holger Knublauch

unread,
May 4, 2010, 10:55:09 PM5/4/10
to topbrai...@googlegroups.com
Arthur,

I have meanwhile found a solution to the problem of how to dynamically change named graphs. For 3.3.2 onwards, I have extended sml:PerformUpdate so that it can access graph URIs through bound variables. Since I cannot change the SPARQL syntax to allow variables as graph URIs (e.g. INSERT INTO ?graph is syntactically not valid), I have introduced a name mapping mechanism using patterns of the form

<urn:var:VAR_NAME>

where VAR_NAME is the name of a bound SM variable. Example:

INSERT INTO <urn:var:targetGraph>

will look up the variable ?targetGraph from previous steps, and then insert its URI.

This will also work inside of GRAPH clauses to access arbitrary named graphs in the WHERE clause.

If this turns out to be useful, I can extend this feature to other SPARQLMotion modules. Feedback appreciated.

Regards,
Holger

Arthur Keen

unread,
May 5, 2010, 12:24:03 PM5/5/10
to topbrai...@googlegroups.com
Holger,

Thanks.  I like that the variable binding is explicit, it will make the code much easier to maintain.  I look forward to using it.  WIll we be able to use it for prefixes as well? For example: 

PREFIX wellmodel: <urn:var:wellmodel>
INSERT INTO <urn:var:wellmodel> {
wellmodel:mygaswell a well:Well.
wellmodel:mygaswell geo:lat ?lat
wellmodel:mygaswell geo:long ?long
    ...}
WHERE {
 ...
 ... ?lat .
 ... ?long .
 ...
}

Regards

Arthur

Scott Henninger

unread,
May 5, 2010, 12:38:13 PM5/5/10
to TopBraid Suite Users
Arthur; In terms of prefixes, try using smf:buildURI(). E.g.

INSERT INTO <urn:var:wellmodel> {
?gaswell a well:Well.
?gaswell geo:lat ?lat
?gaswell geo:long ?long
...}
WHERE {
...
LET (?gaswell := smf:buildURI("{?wellmodel}#mygaswell"))
... ?lat .
... ?long .
...

}

-- Scott
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages