Leonard; Attached is an example SPIN rule that is generalized to address all datarange restrictions - one or two data range values and all four datarange restrictions.  There are some test cases included so you can run inferences and experiment with this.  This is just a draft, so see how it works for you.

The main part of the example is the rule on the :Person class:

CONSTRUCT {
    ?this a ?restriction .
}
WHERE {
    ?datatype owl:onDatatype xsd:integer .
    ?datatype owl:withRestrictions ?restrList .
    ?datatype a rdfs:Datatype .
    ?restriction ?restrType ?datatype .
    ?restriction a owl:Restriction .
    ?restriction owl:onProperty ?datatypeproperty .
    ?this ?datatypeproperty ?val .
    ?restrList rdf:rest ?restrListRest .
    BIND (IF((?restrListRest = rdf:nil), :singleDataRange(?val, ?restrList), :doubleDataRange(?val, ?restrList)) AS ?boolResult) .
    FILTER (?boolResult) .
}

The {
?restrList rdf:rest ?restrListRest .} gets the restriction list.  If ?restrListRest = rdf:nil, then there is only one data range to consider.  Otherwise there are two.  The BIND statement uses this fact to call functions that compute whether the range restriction is met. You can find the definitions for these functions by doing a ctl-click in the spin:rule for :Person. 

The datarange definitions for three classes are included to test this out.  The instances of :Person will be classified by rules (the two values for :Scott are both lies ;-) but it classifies correctly)

:Child owl:equivalentClass "Person and (hasAge only xsd:integer[<= 12])"
:Teenager
owl:equivalentClass "Person and (hasAge only xsd:integer[>= 13 , <= 19])"
:Adult owl:equivalentClass "Person and (hasAge only xsd:integer[> 19])"

-- Scott


On 7/13/11 9:09 AM, Leonard Jacuzzo wrote:
Hello Topquadrant folks.
 
I have been pulling my hair out in an attempt to construct a SPIN rule that is general enough to classify an instance for any datarange restriction using maxInclusive and MinInclusive.
 
Going back to the running example. I have defined teenager as being equivalent to the intersection of (Person, and hasAge only mininclusive 13, and hasAge only maxinclusive 19).
 
I would like to have a person classified as being a teenager...But I would like to have a general rule to do any classification of this nature and attach it to Thing. Below is what I have come up with so far.
TBC rejects it based on syntax. Can anyone spot the problem(s)? I feel like I am chasing my tail.
 
Here is what I have so far.

 

CONSTRUCT {?this a ?P}

WHERE {?this a ?B.

 ?P rdfs:subclassOf ?B.

 ?P owl:equivalentClass ?A.

 ?A owl:intersectionOf ?B, ?restriction, ?restriction2
 ?datatype owl:onDatatype xsd:float .
 ?datatype owl:withRestrictions ?var .
 ?datatype a rdfs:Datatype .
 ?restriction owl:allValuesFrom ?datatype .
 ?restriction a owl:Restriction .
 ?restriction owl:onProperty ?datatypeproperty .
 ?var rdf:first ?var1 .
 ?var1 xsd:minInclusive ?mval .
 ?x2 ?datatypeproperty ?val .
 ?datatype2 owl:onDatatype xsd:float .
 ?datatype2 owl:withRestrictions ?var .
 ?datatype2 a rdfs:Datatype .
 ?restriction2 owl:allValuesFrom ?datatype .
 ?restriction2 a owl:Restriction .
 ?restriction2 owl:onProperty ?datatypeproperty .
 ?var2 rdf:rest ?var3 .
 ?var3 xsd:maxInclusive ?maval .
 ?x2 ?datatypeproperty ?val2 .
FILTER (?val >= ?mval) .
FILTER (?val2 <= ?maval). }
--
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
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

--
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
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
# Saved by TopBraid on Thu Jul 14 12:50:47 CDT 2011
# baseURI: http://support.tq.com/datarangeSPIN_Example
# imports: http://spinrdf.org/spin
# imports: http://spinrdf.org/spl

@prefix :        <http://support.tq.com/datarangeSPIN_Example#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix smf:     <http://topbraid.org/sparqlmotionfunctions#> .
@prefix sp:      <http://spinrdf.org/sp#> .
@prefix spif:    <http://spinrdf.org/spif#> .
@prefix spin:    <http://spinrdf.org/spin#> .
@prefix spl:     <http://spinrdf.org/spl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

sp:dataValue
      rdf:type rdf:Property ;
      rdfs:label "data value"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

sp:operator
      rdf:type rdf:Property ;
      rdfs:label "Operator"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

sp:restrList
      rdf:type rdf:Property ;
      rdfs:label "restr list"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

<http://support.tq.com/datarangeSPIN_Example>
      rdf:type owl:Ontology ;
      spin:imports <http://topbraid.org/spin/owlrl-all> ;
      owl:imports <http://spinrdf.org/spl> , <http://spinrdf.org/spin> ;
      owl:versionInfo "Created with TopBraid Composer"^^xsd:string .

:Adult
      rdf:type owl:Class ;
      rdfs:subClassOf owl:Thing ;
      owl:equivalentClass
              [ rdf:type owl:Class ;
                owl:intersectionOf (:Person [ rdf:type owl:Restriction ;
                            owl:allValuesFrom
                                    [ rdf:type rdfs:Datatype ;
                                      owl:onDatatype xsd:integer ;
                                      owl:withRestrictions
                                              ([ xsd:minExclusive 19
                                                ])
                                    ] ;
                            owl:onProperty :hasAge
                          ])
              ] .

:Adult_Exclusive
      rdf:type owl:Class ;
      rdfs:label "Adult Exclusive"^^xsd:string ;
      rdfs:subClassOf :Adult .

:Child
      rdf:type owl:Class ;
      rdfs:label "Child"^^xsd:string ;
      rdfs:subClassOf owl:Thing ;
      owl:equivalentClass
              [ rdf:type owl:Class ;
                owl:intersectionOf (:Person [ rdf:type owl:Restriction ;
                            owl:allValuesFrom
                                    [ rdf:type rdfs:Datatype ;
                                      owl:onDatatype xsd:integer ;
                                      owl:withRestrictions
                                              ([ xsd:maxInclusive 12
                                                ])
                                    ] ;
                            owl:onProperty :hasAge
                          ])
              ] .

:Person
      rdf:type owl:Class ;
      rdfs:subClassOf owl:Thing ;
      spin:rule
              [ rdf:type sp:Construct ;
                sp:templates ([ sp:object _:b1 ;
                            sp:predicate rdf:type ;
                            sp:subject spin:_this
                          ]) ;
                sp:where ([ sp:object xsd:integer ;
                            sp:predicate owl:onDatatype ;
                            sp:subject _:b2
                          ] [ sp:object _:b3 ;
                            sp:predicate owl:withRestrictions ;
                            sp:subject _:b2
                          ] [ sp:object rdfs:Datatype ;
                            sp:predicate rdf:type ;
                            sp:subject _:b2
                          ] [ sp:object _:b2 ;
                            sp:predicate
                                    [ sp:varName "restrType"^^xsd:string
                                    ] ;
                            sp:subject _:b1
                          ] [ sp:object owl:Restriction ;
                            sp:predicate rdf:type ;
                            sp:subject _:b1
                          ] [ sp:object _:b4 ;
                            sp:predicate owl:onProperty ;
                            sp:subject _:b1
                          ] [ sp:object _:b5 ;
                            sp:predicate _:b4 ;
                            sp:subject spin:_this
                          ] [ sp:object _:b6 ;
                            sp:predicate rdf:rest ;
                            sp:subject _:b3
                          ] [ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type sp:if ;
                                      sp:arg1 [ rdf:type sp:eq ;
                                                sp:arg1 _:b6 ;
                                                sp:arg2 ()
                                              ] ;
                                      sp:arg2 [ rdf:type :singleDataRange ;
                                                sp:dataValue _:b5 ;
                                                sp:restrList _:b3
                                              ] ;
                                      sp:arg3 [ rdf:type :doubleDataRange ;
                                                sp:dataValue _:b5 ;
                                                sp:restrList _:b3
                                              ]
                                    ] ;
                            sp:variable _:b7
                          ] [ rdf:type sp:Filter ;
                            sp:expression _:b7
                          ])
              ] .

:Person_1
      rdf:type :Person ;
      :hasAge 20 .

:Person_2
      rdf:type :Person ;
      :hasAge 19 .

:Person_3
      rdf:type :Person ;
      :hasAge 45 .

:Person_4
      rdf:type :Person ;
      rdfs:label "Person 4"^^xsd:string ;
      :hasAge 4 .

:Scott
      rdf:type :Person ;
      rdfs:label "Scott"^^xsd:string ;
      :hasAge 48 , 19 .

:Teenager
      rdf:type owl:Class ;
      rdfs:label "Teenager"^^xsd:string ;
      rdfs:subClassOf owl:Thing ;
      owl:equivalentClass
              [ rdf:type owl:Class ;
                owl:intersectionOf (:Person [ rdf:type owl:Restriction ;
                            owl:allValuesFrom
                                    [ rdf:type rdfs:Datatype ;
                                      owl:onDatatype xsd:integer ;
                                      owl:withRestrictions
                                              ([ xsd:minInclusive 13
                                                ] [ xsd:maxInclusive 19
                                                ])
                                    ] ;
                            owl:onProperty :hasAge
                          ])
              ] .

:doubleDataRange
      rdf:type spin:Function ;
      rdfs:label "single data range"^^xsd:string ;
      rdfs:subClassOf spin:Functions ;
      spin:body
              [ rdf:type sp:Ask ;
                sp:where ([ sp:object _:b8 ;
                            sp:predicate rdf:first ;
                            sp:subject _:b9
                          ] [ sp:object _:b10 ;
                            sp:predicate _:b11 ;
                            sp:subject _:b8
                          ] [ rdf:type sp:TriplePath ;
                            sp:object _:b12 ;
                            sp:path [ rdf:type sp:SeqPath ;
                                      sp:path1 rdf:rest ;
                                      sp:path2 rdf:first
                                    ] ;
                            sp:subject _:b9
                          ] [ sp:object _:b13 ;
                            sp:predicate _:b14 ;
                            sp:subject _:b12
                          ] [ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type :getOperator ;
                                      sp:operator _:b11
                                    ] ;
                            sp:variable _:b15
                          ] [ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type :getOperator ;
                                      sp:operator _:b14
                                    ] ;
                            sp:variable _:b16
                          ] [ rdf:type sp:Filter ;
                            sp:expression
                                    [ rdf:type sp:and ;
                                      sp:arg1 [ rdf:type spif:invoke ;
                                                sp:arg1 _:b15 ;
                                                sp:arg2 _:b17 ;
                                                sp:arg3 _:b10
                                              ] ;
                                      sp:arg2 [ rdf:type spif:invoke ;
                                                sp:arg1 _:b16 ;
                                                sp:arg2 _:b17 ;
                                                sp:arg3 _:b13
                                              ]
                                    ]
                          ])
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:restrList ;
                spl:valueType rdf:List
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:dataValue ;
                spl:valueType rdfs:Literal
              ] .

:getOperator
      rdf:type spin:Function ;
      rdfs:label "get operator"^^xsd:string ;
      rdfs:subClassOf spin:Functions ;
      spin:body
              [ rdf:type sp:Select ;
                sp:resultVariables (_:b18) ;
                sp:where ([ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type sp:coalesce ;
                                      sp:arg1 [ rdf:type smf:if ;
                                                sp:arg1 [ rdf:type sp:eq ;
                                                          sp:arg1 _:b19 ;
                                                          sp:arg2 
xsd:minInclusive
                                                        ] ;
                                                sp:arg2 sp:ge
                                              ] ;
                                      sp:arg2 [ rdf:type smf:if ;
                                                sp:arg1 [ rdf:type sp:eq ;
                                                          sp:arg1 _:b19 ;
                                                          sp:arg2 
xsd:maxInclusive
                                                        ] ;
                                                sp:arg2 sp:le
                                              ] ;
                                      sp:arg3 [ rdf:type smf:if ;
                                                sp:arg1 [ rdf:type sp:eq ;
                                                          sp:arg1 _:b19 ;
                                                          sp:arg2 
xsd:minExclusive
                                                        ] ;
                                                sp:arg2 sp:gt
                                              ] ;
                                      sp:arg4 [ rdf:type smf:if ;
                                                sp:arg1 [ rdf:type sp:eq ;
                                                          sp:arg1 _:b19 ;
                                                          sp:arg2 
xsd:maxExclusive
                                                        ] ;
                                                sp:arg2 sp:lt
                                              ]
                                    ] ;
                            sp:variable _:b18
                          ])
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:operator ;
                spl:valueType spin:Function
              ] .

:hasAge
      rdf:type owl:DatatypeProperty ;
      rdfs:domain :Person ;
      rdfs:range xsd:integer .

:singleDataRange
      rdf:type spin:Function ;
      rdfs:label "single data range"^^xsd:string ;
      rdfs:subClassOf spin:Functions ;
      spin:body
              [ rdf:type sp:Ask ;
                sp:where ([ sp:object _:b20 ;
                            sp:predicate rdf:first ;
                            sp:subject
                                    [ sp:varName "restrList"^^xsd:string
                                    ]
                          ] [ sp:object _:b21 ;
                            sp:predicate _:b22 ;
                            sp:subject _:b20
                          ] [ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type :getOperator ;
                                      sp:operator _:b22
                                    ] ;
                            sp:variable _:b23
                          ] [ rdf:type sp:Filter ;
                            sp:expression
                                    [ rdf:type spif:invoke ;
                                      sp:arg1 _:b23 ;
                                      sp:arg2 [ sp:varName 
"dataValue"^^xsd:string
                                              ] ;
                                      sp:arg3 _:b21
                                    ]
                          ])
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:dataValue ;
                spl:valueType rdfs:Literal
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:restrList ;
                spl:valueType rdf:List
              ] .

_:b7  sp:varName "boolResult"^^xsd:string .

_:b6  sp:varName "restrListRest"^^xsd:string .

_:b5  sp:varName "val"^^xsd:string .

_:b4  sp:varName "datatypeproperty"^^xsd:string .

_:b1  sp:varName "restriction"^^xsd:string .

_:b3  sp:varName "restrList"^^xsd:string .

_:b2  sp:varName "datatype"^^xsd:string .

_:b23
      sp:varName "op"^^xsd:string .

_:b22
      sp:varName "withRestrType"^^xsd:string .

_:b21
      sp:varName "restrVal"^^xsd:string .

_:b20
      sp:varName "restrBnode"^^xsd:string .

_:b19
      sp:varName "operator"^^xsd:string .

_:b18
      sp:varName "op"^^xsd:string .

_:b17
      sp:varName "dataValue"^^xsd:string .

_:b16
      sp:varName "opRange2"^^xsd:string .

_:b15
      sp:varName "opRange1"^^xsd:string .

_:b14
      sp:varName "restrTypeRange2"^^xsd:string .

_:b13
      sp:varName "range2"^^xsd:string .

_:b12
      sp:varName "range2bnode"^^xsd:string .

_:b11
      sp:varName "restrTypeRange1"^^xsd:string .

_:b10
      sp:varName "range1"^^xsd:string .

_:b9  sp:varName "restrList"^^xsd:string .

_:b8  sp:varName "range1bnode"^^xsd:string .
# Saved by TopBraid on Thu Jul 14 12:50:47 CDT 2011
# baseURI: null

@prefix composite:  <http://www.topbraid.org/2007/05/composite.owl#> .
@prefix forms:   <http://www.topbraid.org/2007/01/forms.owl#> .
@prefix inference:  <http://www.topbraid.org/2007/06/inference.owl#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix visual:  <http://topbraid.org/visual#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

<http://support.tq.com/datarangeSPIN_Example#Person>
      forms:keyProperties (rdfs:label rdfs:comment 
<http://support.tq.com/datarangeSPIN_Example#hasAge>) .

[]    rdf:type inference:Configuration ;
      composite:child
              [ rdf:type <http://spinrdf.org/spin#TopSPIN> ;
                composite:index "0"^^xsd:int
              ] .

Reply via email to