Hi Russell,

it looks like your expectation is that if you add a triple such as

                        INSERT {
                            ?person a kennedys:Person .
                            ?person kennedys:birthYear 2015 .
                        }
                        WHERE {
                            BIND (?newPerson AS ?person) .
                        }

inside of sml:ApplyTopSPIN then the inferences will happen automatically. However, sml:ApplyTopSPIN is a batch operation and will only infer the triples that it gets from the context graph. So the INSERT above will not lead to a new triple.

To avoid the problem that the SPIN file gets overwritten, make sure that the graph is not the context graph when you run the sml:ApplyTopSPIN. One way of doing that is to create a copy into ui:tempGraph and then operate on that "sandbox".

Finally, you had used kennedys:age where it should have been kspin:age.

I have put all these pieces together as attached. Maybe we can use that as a starting point to get closer to what you originally requested.

(Note that kspin:age is a magic property so if you query it as in the SELECT it will in fact create the value dynamically regardless of whether it's already "inferred" as a triple. That's often a good way of avoiding inferencing altogether - just compute the values that you need on the fly).

HTH
Holger



On 9/03/2017 5:18, Russell Morrisey wrote:
I found that not only does this script fail to produce inferences; but, it also causes the kennedysSPIN file in my workspace to be modified when run locally, which is exactly what I don't want. =(

On Wednesday, March 8, 2017 at 12:06:01 PM UTC-5, Russell Morrisey wrote:

    Here is an example of what I am trying to do, using only
    kennedysSPIN. I have removed everything that's specific to my
    application.

    In this example, I create a new kennedys:Person using a ui:update
    statement. I want to compute the *age* of the person that I have
    just created.

    When I run the code sample given below, I see the person data, but
    the inferred triple for the age is missing.

    |
    <ui:group>
        <ui:setPrefix
    ui:namespace="http://www.w3.org/2000/01/rdf-schema#
    <http://www.w3.org/2000/01/rdf-schema#>" ui:prefix="rdfs"/>
        <ui:setPrefix
    ui:namespace="http://topbraid.org/examples/kennedys#
    <http://topbraid.org/examples/kennedys#>" ui:prefix="kennedys"/>
        <ui:setPrefix
    ui:namespace="http://topbraid.org/examples/kennedysSPIN#
    <http://topbraid.org/examples/kennedysSPIN#>" ui:prefix="kspin"/>
        <ui:setContext ui:queryGraph="{=
    ui:graphWithImports(&lt;http://topbraid.org/examples/kennedysSPIN&gt
    <http://topbraid.org/examples/kennedysSPIN&gt>;) }">
            <sml:ApplyTopSPIN let:newPerson="{=
    spif:buildUniqueURI(&quot;kennedys:BobTestman&quot;) }">
                <ui:update ui:updateQuery="{!
                        INSERT {
                            ?person a kennedys:Person .
                            ?person kennedys:birthYear 2015 .
                        }
                        WHERE {
                            BIND (?newPerson AS ?person) .
                        } }"/>
                <swon:Object>
                    <swon:Value arg:name="request" arg:value="{=
    ?newPerson }"/>
                    <swon:Value arg:name="inferredResponse">
                        <swon:Array>
                            <ui:forEach ui:resultSet="{#
                                    SELECT ?birthYear ?age
                                    WHERE {
    ?newPerson a kennedys:Person .
    ?newPerson kennedys:birthYear ?birthYear .
    OPTIONAL {
    ?newPerson kennedys:age ?age .
                                        } .
                                    }
                                    LIMIT 10 }" ui:separator=",">
    <swon:Object>
    <swon:Value arg:name="birthYear" arg:value="{= ?birthYear }"/>
    <swon:Value arg:name="inferredAge" arg:value="{= ?age }"/>
    </swon:Object>
                            </ui:forEach>
                        </swon:Array>
                    </swon:Value>
                </swon:Object>
            </sml:ApplyTopSPIN>
        </ui:setContext>
    </ui:group>
    |






    On Tuesday, March 7, 2017 at 10:33:19 PM UTC-5, Holger Knublauch
    wrote:

        Hi Russell,

        I believe the issue is that the SWP below uses a ui:setContext
        which basically makes the inferred triples invisible to the
        downstream processes. The correct order is illustrated in the
        attached example, which runs inferences over kennedysSPIN and
        prints JSON in the format that you have proposed. (Note that I
        also took out the ?s in the GRAPH ui:tempGraph because it was
        not finding any matches in the kennedys example.) But the big
        picture is that sml:ApplyTopSPIN will run inferences on the
        current query graph (the surrounding context) and the children
        of it are the inferred triples.

        HTH
        Holger


        On 8/03/2017 8:45, Russell Morrisey wrote:
        Holger,

        We are proceeding with TBL, using federated query to solve
        the volume issue.

        I reviewed your SM script. In my use case, I really don't
        want the inferred triples to be saved off to a file. What I
        think I want to do is invoke the *sml:ApplyTopSPIN* function
        in a SWP endpoint.

        I tried this approach, but could not get it to work. Can you
        help me figure out what I'm doing wrong?

        Here is my prototype SWP endpoint.
        Currently, the query is returning no results. If I move the
        query's "?s ?p ?o" inside the GRAPH block, I can see the
        inserted triples, but no inferred triples are showing up.

        |
        <ui:group>
            <sml:ApplyTopSPIN sml:replace="true">
                <ui:setPrefix
        ui:namespace="http://www.w3.org/2000/01/rdf-schema#";
        <http://www.w3.org/2000/01/rdf-schema#> ui:prefix="rdfs"/>
                <ui:setPrefix
        
ui:namespace="http://knowledge.cscglobal.com/question-answer/1.0/api/schema/";
        <http://knowledge.cscglobal.com/question-answer/1.0/api/schema/>
        ui:prefix="qnaApi"/>
                <ui:setPrefix
        
ui:namespace="http://knowledge.cscglobal.com/question-answer/1.0/api/data/";
        <http://knowledge.cscglobal.com/question-answer/1.0/api/data/>
        ui:prefix="qnaData"/>
                <ui:setContext ui:queryGraph="{=
        
ui:graphWithImports(&lt;http://knowledge.cscglobal.com/question-answer/1.0/api/rules&gt
        <http://knowledge.cscglobal.com/question-answer/1.0/api/rules&gt>;)
        }" ui:silentTransactions="true">
                    <ui:update ui:updateQuery="{!
                            INSERT {
                                GRAPH ui:tempGraph {
        ?qnaRequest a qnaApi:QuestionKnowledgeRequest .
        ?qnaRequest qnaApi:orderTypeCode &quot;TCC&quot; .
        ?qnaRequest qnaApi:stateName &quot;Delaware&quot; .
                                } .
                            }
                            WHERE {
                                BIND
        (spif:buildUniqueURI(&quot;qnaData:{?1}&quot;,
        spif:generateUUID()) AS ?qnaRequest) .
                            } }"/>
                    <swon:Object>
                        <swon:Value arg:name="order">
        <swon:Object>
        <swon:Value arg:name="foo" arg:value="bar"/>
        <swon:Value arg:name="services">
        <swon:Array>
        <ui:forEach ui:resultSet="{#
          SELECT ?s ?p ?o
          WHERE {
              GRAPH ui:tempGraph {
                  ?s a qnaApi:QuestionKnowledgeRequest .
              } .
              ?s ?p ?o .
          }
          LIMIT 10 }" ui:separator=",">
        <ui:br/>
        <swon:Object>
          <swon:Value arg:name="s" arg:value="{= ?s }"/>
          <swon:Value arg:name="p" arg:value="{= ?p }"/>
          <swon:Value arg:name="o" arg:value="{= ?o }"/>
        </swon:Object>
        </ui:forEach>
        </swon:Array>
        </swon:Value>
        </swon:Object>
                        </swon:Value>
                    </swon:Object>
                </ui:setContext>
            </sml:ApplyTopSPIN>
        </ui:group>
        |

        Thanks!


        On Sunday, February 19, 2017 at 5:46:26 PM UTC-5, Holger
        Knublauch wrote:

            Ok, if there is a TBL server in the mix then we can rely
            on SPARQLMotion (or SWP) to perform inferencing. This
            could theoretically happen on the fly for each request,
            e.g. by calling a SPARQLMotion script with parameters.
            But this would have the server re-apply the inferences
            for each individual request, and may not be performant.
            So one possible work flow would be to have a small SM
            script that applies inferences and produces a new named
            graph (e.g. TTL file or TDB), and then query that new
            named graph with the usual SPARQL end point. You would
            call this script before you want to query or periodically
            if the data changes.

            I have attached an SM file that you can put into your TBL
            workspace (e.g. via project upload). An example call
            using TBC-ME would be

            
http://localhost:8083/tbl/sparqlmotion?id=createInfGraph:CreateInfGraph&graphName=http://topbraid.org/examples/kennedysSPIN
            
<http://localhost:8083/tbl/sparqlmotion?id=createInfGraph:CreateInfGraph&graphName=http://topbraid.org/examples/kennedysSPIN>

            The script looks like:



            The produces a stand-alone graph with all inferences
            which you can then query using the SPARQL end point, e.g.

            SELECT *
            WHERE {
                GRAPH
            <http://topbraid.org/examples/kennedysSPIN-withSPIN>
            <http://topbraid.org/examples/kennedysSPIN-withSPIN> {
                    ?subject a
            <http://topbraid.org/examples/kennedys#Person>
            <http://topbraid.org/examples/kennedys#Person> .
                }
            } ORDER BY ?subject

            HTH
            Holger


            On 18/02/2017 6:05, Russell Morrisey wrote:
            Holger,

            Thanks for your reply.

            The current (prototype) version of the app calls out to
            the SPARQL REST endpoint in TopBraid Live:
            http://localhost:8083/tbl/sparql
            <http://localhost:8083/tbl/sparql>

            If there is a better way I should do this, please point
            me to the right approach.

            I don't know how to tell the sparql endpoint that it
            should execute SPIN rules. The SPIN rule declaration is
            stored in the ontology as part of the Class definition.
            Here is the Class definition, including the rule
            declaration:

            |
            spinTest:SpinTest
              rdf:type owl:Class ;
              spin:rule [
                  rdf:type sp:Construct ;
                  sp:templates (
                      [
                        sp:object "spin:rule OK" ;
                        sp:predicate spinTest:testResult ;
                        sp:subject [
                            sp:varName "test" ;
                          ] ;
                      ]
                    ) ;
                  sp:where (
                      [
                        sp:object spinTest:SpinTest ;
                        sp:predicate rdf:type ;
                        sp:subject [
                            sp:varName "test" ;
                          ] ;
                      ]
                    ) ;
                ] ;
              rdfs:label "Spin test" ;
              rdfs:subClassOf owl:Thing ;
            .
            |

            I have tested out this rule using "Run Inferences" in
            Composer, but I don't understand how to apply it on the
            server.

            Thanks


            On Thursday, February 16, 2017 at 11:40:58 PM UTC-5,
            Holger Knublauch wrote:

                Hi Russell,

                in your question you indicate that you have a Java
                app, so I assume this code runs outside of the TBL
                server. Assuming you want to perform the inferences
                in your code using the SPIN API, I guess there is no
                difference between TBL or any 3rd party triple store
                - you can for example use the SPARQL end point to
                retrieve the original triples. Everything else is
                under full control of your application.

                Is this the scenario you are describing?

                Thanks,
                Holger


                On 17/02/2017 8:59, Russell Morrisey wrote:
                I have an ontology with a *spin:rule* that I've
                built and tested in TopBraid Composer.

                I'd like to build an app that has the following flow:

                 1. Load some graph data from a triple store
                 2. Assert some triples from the client into a
                    temporary graph (preferably a session-scoped graph)
                 3. Run my spin:rules and store the new triples in
                    the temporary graph
                 4. Query the temporary graph and send the results
                    back to the caller.

                My app is a Java app which does not use SWP.

                How can I apply spin:rules this way when my
                ontology is deployed in TopBraid Live?
                How can I apply spin:rules this way when my
                ontology is in a 3rd-party triple store?
                Which 3rd-party triple stores support this?

                I am working on figuring out the answers to these
                questions. Any help would be appreciated.

-- You received this message because you are
                subscribed to the Google Group "TopBraid Suite
                Users", the topics of which include the TopBraid
                Suite family of products and its base technologies
                such as SPARQLMotion, SPARQL Web Pages and SPIN.
                To post to this group, send email to
                [email protected]
                ---
                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
                [email protected].
                For more options, visit
                https://groups.google.com/d/optout
                <https://groups.google.com/d/optout>.

-- You received this message because you are subscribed to
            the Google Group "TopBraid Suite Users", the topics of
            which include the TopBraid Suite family of products and
            its base technologies such as SPARQLMotion, SPARQL Web
            Pages and SPIN.
            To post to this group, send email to
            [email protected]
            ---
            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 [email protected].
            For more options, visit
            https://groups.google.com/d/optout
            <https://groups.google.com/d/optout>.

-- You received this message because you are subscribed to the
        Google Group "TopBraid Suite Users", the topics of which
        include the TopBraid Suite family of products and its base
        technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
        To post to this group, send email to [email protected]
        ---
        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 [email protected].
        For more options, visit https://groups.google.com/d/optout
        <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
---
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 [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Group "TopBraid 
Suite Users", the topics of which include the TopBraid Suite family of products and 
its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
--- 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 [email protected].
For more options, visit https://groups.google.com/d/optout.
# baseURI: http://example.org/swpRules
# imports: http://topbraid.org/examples/kennedysSPIN
# imports: http://topbraid.org/swa
# prefix: swpRules

@prefix afn: <http://jena.hpl.hp.com/ARQ/function#> .
@prefix arg: <http://spinrdf.org/arg#> .
@prefix composite: <http://www.topbraid.org/2007/05/composite.owl#> .
@prefix css: <http://uispin.org/css#> .
@prefix daml: <http://www.daml.org/2001/03/daml+oil#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix default: <http://uispin.org/default#> .
@prefix email: <http://topbraid.org/email#> .
@prefix fn: <http://www.w3.org/2005/xpath-functions#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix html: <http://uispin.org/html#> .
@prefix kennedys: <http://topbraid.org/examples/kennedys#> .
@prefix kspin: <http://topbraid.org/examples/kennedysSPIN#> .
@prefix let: <http://uispin.org/let#> .
@prefix letrs: <http://uispin.org/letrs#> .
@prefix list: <http://jena.hpl.hp.com/ARQ/list#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix qnaAPI: <http://example.org/file1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix search: <http://topbraid.org/search#> .
@prefix search.spin: <http://topbraid.org/search.spin#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix sm: <http://topbraid.org/sparqlmotion#> .
@prefix smf: <http://topbraid.org/sparqlmotionfunctions#> .
@prefix sml: <http://topbraid.org/sparqlmotionlib#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix sparqlmotionlib-swp: <http://topbraid.org/sparqlmotionlib-swp#> .
@prefix spif: <http://spinrdf.org/spif#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix spl-dynamic-ranges: <http://spinrdf.org/spl-dynamic-ranges#> .
@prefix spr: <http://spinrdf.org/spr#> .
@prefix spra: <http://spinrdf.org/spra#> .
@prefix style: <http://uispin.org/style#> .
@prefix svg: <http://uispin.org/svg#> .
@prefix swa: <http://topbraid.org/swa#> .
@prefix swauml: <http://topbraid.org/swauml#> .
@prefix swon: <http://uispin.org/swon#> .
@prefix swpRules: <http://example.org/swpRules#> .
@prefix sxml: <http://topbraid.org/sxml#> .
@prefix tosh: <http://topbraid.org/tosh#> .
@prefix ui: <http://uispin.org/ui#> .
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
@prefix xlink: <http://www.w3.org/1999/xlink#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/swpRules>
  rdf:type owl:Ontology ;
  owl:imports <http://topbraid.org/examples/kennedysSPIN> ;
  owl:imports <http://topbraid.org/swa> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
swpRules:TestService
  rdf:type ui:Service ;
  ui:prototype """
<ui:group let:newPerson=\"{= kennedys:BobTestman }\">
    <ui:setPrefix ui:namespace=\"http://www.w3.org/2000/01/rdf-schema#\"; 
ui:prefix=\"rdfs\"/>
    <ui:setPrefix ui:namespace=\"http://topbraid.org/examples/kennedys#\"; 
ui:prefix=\"kennedys\"/>
    <ui:setPrefix ui:namespace=\"http://topbraid.org/examples/kennedysSPIN#\"; 
ui:prefix=\"kspin\"/>
    <ui:setContext ui:queryGraph=\"{= 
ui:graphWithImports(&lt;http://topbraid.org/examples/kennedysSPIN&gt;) }\">
        <ui:update ui:updateQuery=\"{!
                INSERT {
                    GRAPH ui:tempGraph {
                        ?s ?p ?o .
                    } .
                }
                WHERE {
                    ?s ?p ?o .
                } }\"/>
        <ui:update ui:updateQuery=\"{!
                INSERT {
                    GRAPH ui:tempGraph {
                        ?newPerson a kennedys:Person .
                        ?newPerson kennedys:birthYear 2015 .
                    } .
                }
                WHERE {
                } }\"/>
        <ui:setContext ui:queryGraph=\"{= ui:tempGraph }\">
            <sml:ApplyTopSPIN>
                <swon:Object>
                    <swon:Value arg:name=\"request\" arg:value=\"{= ?newPerson 
}\"/>
                    <swon:Value arg:name=\"inferredResponse\">
                        <swon:Array>
                            <ui:forEach ui:resultSet=\"{#
                                    SELECT ?birthYear ?age
                                    WHERE {
                                        ?newPerson a kennedys:Person .
                                        ?newPerson kennedys:birthYear 
?birthYear .
                                        OPTIONAL {
                                            ?newPerson kspin:age ?age .
                                        } .
                                    }
                                    LIMIT 10 }\" ui:separator=\",\">
                                <swon:Object>
                                    <swon:Value arg:name=\"birthYear\" 
arg:value=\"{= ?birthYear }\"/>
                                    <swon:Value arg:name=\"inferredAge\" 
arg:value=\"{= ?age }\"/>
                                </swon:Object>
                            </ui:forEach>
                        </swon:Array>
                    </swon:Value>
                </swon:Object>
            </sml:ApplyTopSPIN>
        </ui:setContext>
    </ui:setContext>
</ui:group>
"""^^ui:Literal ;
  rdfs:label "Test service" ;
  rdfs:subClassOf ui:JSONServices ;
.

Reply via email to