TBCME: Cannot write to a graph from an SWP

30 views
Skip to first unread message

Tim Smith

unread,
Aug 17, 2020, 3:34:31 PM8/17/20
to topbrai...@googlegroups.com
Hi,

I cannot write to an existing graph in the workspace from an SWP.  This is a problem that has plagued me since TBC 5.1.4 so perhaps I'm doing something wrong.  I've attached a minimal example as a project.

The file, swp_write_to_graph.ui.ttlx contains a subclass of ui:Services called w2g:w2graph.  In the ui:prototype, I populate a temp graph (ui:tempGraphFinalOutput) with a single triple.  ui:prototype shown below.

Next, I dump the temp graph to a temporary file using ui:dumpGraph to ensure ui:tempGraphFinalOutput contains the triple.  This works as expected.  Then I try to insert the contents into an RDF file that exists in the workspace.  This file contains nothing but the triples TBC creates when a new RDF file is created.

The SWP call completes successfully but the single triple is not inserted into the existing graph.

The SWP is called using:


What am I missing such that I cannot insert triples into existing graphs from an SWP?

Note that my ultimate goal is to pass the name of the output graph into the SWP so you will see a constraint setup for that purpose but it is not used in this example.

Any help would be appreciated.  I need to create a number of SWPs and being able to manipulate graphs at will is a skill I need.

Tim



<ui:group let:outputFileGraph="{= IRI(?outputGraph) }">
    <h3>The output graph is {= ?outputGraph }  Graph: {= ?outputFileGraph }</h3>{= smf:trace("Populating the temp graph... ") }<ui:update ui:updateQuery="{!
            INSERT {
                GRAPH ui:tempGraphFinalOutput {
                    ?uri rdfs:label &quot;I am a Thing&quot; .
                } .
            }
            WHERE {
                BIND (spif:buildURI(&quot;&lt;http://example.com/{?1}&gt;&quot;, &quot;i_am_a_thing&quot;) AS ?uri) .
            } }"/>{= smf:trace("Finished!") }

{= smf:trace("Dumping to the debug graph...") }<ui:dumpGraph ui:filePath="/SWP_Example/swp_write_to_graph_debug_output.ttl" ui:graph="ui:tempGraphFinalOutput"/>
    <!-- Try to insert into the output graph -->{= smf:trace("Writing output graph... ") }<ui:setContext ui:queryGraph="ui:tempGraphFinalOutput">
        <ui:update ui:updateQuery="{!
                INSERT {
                    GRAPH &lt;http://example.com/swp_write_to_graph_output&gt; {
                        ?s ?p ?o .
                    } .
                }
                WHERE {
                    ?s ?p ?o .
                } }"/>
    </ui:setContext>
</ui:group>
SWP_Example.zip

Holger Knublauch

unread,
Aug 17, 2020, 7:11:12 PM8/17/20
to topbrai...@googlegroups.com

Hi Tim,

you were almost there. The missing info is that ui:update will only write to the context graph when done, not any graph mentioned in the INSERT. So change it to

<ui:setContext ui:queryGraph="&lt;http://example.com/swp_write_to_graph_output&gt;">


        <ui:update ui:updateQuery="{!
                INSERT {

                    ?s ?p ?o .
                }
                WHERE {
                    GRAPH ui:tempGraphFinalOutput {


                        ?s ?p ?o .
                    } .

                } }"/>
    </ui:setContext>

which makes the target graph the active context graph while the source graph is moved into the WHERE clause.

You may also want to wrap the ui:update with a ui:transaction if you want to bundle multiple updates into a single save step. It will otherwise auto-create a transaction for each nested ui:update.

HTH and thanks for taking the time to prepare the bundled example.

Holger

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/CAF0Wbn%2BG7FQ8vk8nsLP8FPt%3DoLy86mOs9PuBudBcQP4FTTyO3g%40mail.gmail.com.

Tim Smith

unread,
Aug 17, 2020, 11:41:56 PM8/17/20
to topbrai...@googlegroups.com
Hi Holger, 

I was thinking it worked like SPARQL syntax.  Thanks for clearing that up!  Now my SWPs will be much more effective.  :)

Tim

Holger Knublauch

unread,
Aug 17, 2020, 11:49:31 PM8/17/20
to topbrai...@googlegroups.com


On 18/08/2020 13:41, Tim Smith wrote:
Hi Holger, 

I was thinking it worked like SPARQL syntax. 

It does work like SPARQL, but the ui:update/ui:transaction elements need to decide when to physically write the triples to the file, and that is easier to do if only the context graph is modified. I am sure this could be improved but that's how it works at the moment.

Holger



Tim Smith

unread,
Aug 17, 2020, 11:54:27 PM8/17/20
to topbrai...@googlegroups.com
That works for me.  It was something I missed in the documentation - although it's clearly written.  I'm just glad to be able to successfully manipulate graphs and move my project forward.  Thanks again!

Tim

Reply all
Reply to author
Forward
0 new messages