Hi Michael,

thanks for the background. This sounds like Event-Condition-Action rules to me. I guess SHACL could be used to describe the pattern in the data for which the rules need to trigger, and the updates that need to happen. In SHACL Advanced you could use a custom target for that, to determine which focus nodes a rule needs to fire on. For example, assume that you want to update the status of ex:Customer to ex:GoldStatus once she has made more than $1000 in purchases:

ex:GoldStatusRuleShape
    a sh:NodeShape ;
    sh:target [
        a sh:SPARQLTarget ;
        sh:select """
            SELECT ?this
            WHERE {
                ?this a ex:Customer .
                ?this ex:purchasedValue ?value .
                FILTER (?value >= 1000) .
                FILTER NOT EXISTS { ?this ex:status ?any } .
            } """ ;
    sh:rule [
        a sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate ex:status ;
        sh:object ex:GoldStatus ;
    ] .

Alternatively, maybe you could use sh:condition...

ex:GoldStatusRuleShape
    a sh:NodeShape ;
    sh:targetClass ex:Customer ;   # Check for all customer instances
    sh:rule [
        a sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate ex:status ;
        sh:object ex:GoldStatus ;
        sh:condition [
            sh:property [   # Customer has no ex:status yet
                sh:path ex:status ;
                sh:maxCount 0 ;
            ] ;
            sh:property [   # and has purchased for more than $1000
                sh:path ex:purchasedValue ;
                sh:minInclusive 1000 ;
            ] ;
    ] .

There would need to be some outside "trigger" mechanism that monitors the data for changes and goes through all these rule shapes. I assume this is a feature that a platform such as TopBraid could provide.

Note that the conditions are worded in such a way so that they can only trigger once.

Does this look similar to what you are trying to do, or what else would be missing for your use case?

(And if you're interested, maybe we could make a pre-alpha release of 5.4 available so that you don't need to wait for half a year...)

Thanks,
Holger


On 18/05/2017 0:56, Michael Johnson wrote:
Hey Holger,
We are receiving reports from a variety of domains. All of these are ingested into the triple store. We are looking for conditions/patterns that indicate an “event.” Once we identify that the conditions for a particular class of event have occurred, we want to create an instance of that class. Now that we have an instance of a particular type of event we will then determine what action needs to be taken.
We have created several domain ontologies for this effort.

We currently have SHACL statements that accurately find the data of concern. We are using the sh:sparql as most of the queries tend to get fairly complex. With the exception of the violation report in TBC it really isn’t much more than a SPARQL query. What we need to do is construct triples to be added to the graph. I have tried a variety of methods with little success. I have started to incorporate SPIN as a method to create the triples, but seems that I should be able to do this with SHACL or at least call the SPIN rule and pass the data to create the triples.

It seems as if the advanced features address what is needed. My understanding is that the Advanced Features will not be present until TBC 5.4.

We are very pleased with the work you have done in SHACL and excited about the path forward.

Thanks,
Michael

On Tuesday, May 16, 2017 at 6:51:11 PM UTC-4, Holger Knublauch wrote:

    Hi Michael,

    if you are referring to SHACL rules, they are part of the Advanced
    Features WG note. I worked on its implementation over the last
    month. Support for SPARQL CONSTRUCT queries is definitely there
    and will remain important. We did however also add a more
    declarative way of representing rules, for simpler and more
    predictable use cases. Full support of these features will be part
    of TopBraid 5.4, while the open source API has intermediate
    snapshots for those who are willing to use the lower levels.

    On your specific scenario, I would be interested to hear what you
    are trying to do - please provide details.

    Regards,
    Holger


    On 17/05/2017 0:09, Michael Johnson wrote:
    Holger,
    I have been reading the updated draft for SHACL (16 May 2017).
    It seems as if SHACL is migrating away from the use of CONSTRUCT.

    My use case for CONSTRUCT is this:
    1. It is revealed thru a SPARQL query that a number of conditions
    point to a particular type of event
    2. An instance of class:event is created with the conditions of
    the SPARQL query as evidence (properties of)
    3. The presence of the event then creates another instance of
    class:recommendation

    We have "parts" of this working.  We have SHACL that identifies
    the conditions.
    We have SPIN that creates some instances.  However, we are trying
    to link the two together.

    I have attempted to use spin:constructor within SHACL (a bit of a
    shot in the dark...) with no success.

    1.  Do you have any recommendations how this would be done?
    2.  Is it possible that the triples are "automagically" inserted
    after inference?

    Thank you.
    Michael



    On Friday, March 3, 2017 at 2:37:35 AM UTC-5, Holger Knublauch
    wrote:

        That looks more like a use case for SPIN rules to me. It is
        not yet decided whether SHACL will have something similar.

        Holger


        Sent from my iPad

        On 3 Mar 2017, at 01:18, Michael Johnson
        <[email protected]> wrote:

        Hey Holger.
        Thanks for pointing me in the right direction.
        It seems as if the only suggestion that can be applied is to
        delete the offending triple, whereas I wish to add a triple.
         Do you have any suggestions?

        For example:
        :JohnDoe_1
          rdf:type :Person_1 ;
          :ssn "qweqeqweqweq" ;
        .

        This is a violation of the sh:MaxLengthConstraintComponent

        What if I want to insert a new triple:
        :Violations_1
          rdf:type :Violation ;
          :ssn "qweqeqweqweq" ;
        .

        Thanks so much for your time.

        Michael

        On Monday, February 20, 2017 at 5:46:53 PM UTC-5, Holger
        Knublauch wrote:

            Hi Michael,

            sh:update is by default not doing anything in SHACL. It
            is a property that can be used by extensions. One such
            extension is the DASH suggestions framework supported by
            TopBraid:

            http://datashapes.org/suggestions.html
            <http://datashapes.org/suggestions.html>

            Please take a look and let me know if this would help.
            It is currently limited to constraint components, i.e.
            it is not yet possible to define suggestions that would
            be for a specific constraint instance only.

            Holger


            On 21/02/2017 5:12, Michael Johnson wrote:
            I am attempting to insert a triple when a particular
            SHACL violation occurs.  It seems as if I would use the
            sh:update, but I can't seem to get it right.
            I have a Person class that has a property Comment.  I
            can easily update the Person by
            INSERT {
            ?s ex:Comment "inserted Comments" .
            }
            WHERE {
            ?s rdf:type ex:Person .

            I have tried to add the sh:update as a property constraint:

            ex:Person
              rdf:type rdfs:Class ;
              rdf:type sh:Shape ;
              rdfs:label "Person" ;
              rdfs:subClassOf rdfs:Resource ;
              sh:property [
                  sh:predicate ex:Comment ;
                  sh:datatype xsd:string ;
                  sh:minCount 1 ;
            *    sh:update """PREFIX ex: <http://example.com#>
            <http://example.com#>*
            *INSERT {*
            *?s ex:Comment \"inserted Comments\" .*
            *}*
            *WHERE {*
            *?s rdf:type ex:Person . }""" ;*
                ] ;
              sh:property [
                  sh:predicate ex:firstName ;
                  sh:datatype xsd:string ;
                  sh:minCount 1 ;
                  sh:name "first name" ;
                ] ;
              sh:property [
                  sh:predicate ex:gender ;
                  sh:class ex:Gender ;
                  sh:description "A Person's gender" ;
                  sh:maxCount 1 ;
                  sh:minCount 1 ;
                  sh:name "gender" ;
                ] ;
              sh:property [
                  sh:predicate ex:lastName ;
                  sh:datatype xsd:string ;
                  sh:description "last name" ;
                  sh:maxCount 1 ;
                  sh:minCount 1 ;
                  sh:name "last name" ;
                ] ;
              sh:property [
                  sh:predicate ex:mother ;
                  sh:class ex:Person ;
                  sh:description "A Person's mother";
                  sh:maxCount 1 ;
                  sh:name "mother" ;
                  sh:nodeKind sh:IRI ;
                  sh:shape ex:FemaleShape ;
                ] ;
              sh:update """INSERT {
            ?s ex:Comment \"inserted Comments\" .
            }
            WHERE {
            ?s rdf:type ex:Person . }""" ;
            .



            ex:Person
              rdf:type rdfs:Class ;
              rdf:type sh:Shape ;
              rdfs:label "Person" ;
              rdfs:subClassOf rdfs:Resource ;
              sh:property [
                  sh:predicate ex:Comment ;
                  sh:datatype xsd:string ;
                  sh:minCount 1 ;
                  sh:update """INSERT {
            ?s ex:Comment \"inserted Comments\" .
            }
            WHERE {
            ?s rdf:type ex:Person . }""" ;
                ] ;
              sh:property [
                  sh:predicate ex:firstName ;
                  sh:datatype xsd:string ;
                  sh:minCount 1 ;
                  sh:name "first name" ;
                ] ;
              sh:property [
                  sh:predicate ex:gender ;
                  sh:class ex:Gender ;
                  sh:description "A Person's gender" ;
                  sh:maxCount 1 ;
                  sh:minCount 1 ;
                  sh:name "gender" ;
                ] ;
              sh:property [
                  sh:predicate ex:lastName ;
                  sh:datatype xsd:string ;
                  sh:description "last name" ;
                  sh:maxCount 1 ;
                  sh:minCount 1 ;
                  sh:name "last name" ;
                ] ;
              sh:property [
                  sh:predicate ex:mother ;
                  sh:class ex:Person ;
                  sh:description "A Person's mother" ;
                  sh:maxCount 1 ;
                  sh:name "mother" ;
                  sh:nodeKind sh:IRI ;
                  sh:shape ex:FemaleShape ;
                ] ;
            .


-- 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]
    <javascript:>
    ---
    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] <javascript:>.
    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.

Reply via email to