Aziza; Thanks for the follow-on offline.  I thought this would be of general interest to others interested in how to use SPIN Templates and Rules. 

I took the example query given and created the attached model with queries.  A missing part of the description seems to be how you distinguish between the different contract types.  So I took a guess with a class I named FinancialInstrument.

Copy the two files into your workspace, open the .ttl file and run inferences.  This will run the TopSPIN engine against a template rules I have created.  It will infer :InferAsContractTypeA and :ContractTypeA and :InferAsContractTypeB as :ContractTypeB.

The way this works is that I created a SPIN Template named cex:InferContractType (to find this, type "InferCon" into the search box at the bottom of the Classes view and click the search flashlight).  The template is the query you sent and takes the three parameters you mentioned, ?contractName, ?seqNo, and ?f1.

The template is then used to instantiate rules for inferring instances of ContractType{A,B,…}.  Since you wanted to infer over untyped resources, the rules are found in owl:Thing.  Note that I create a rule for each type of contract that appear as:
  Infer cex:ContractTypeA given Financial Instrument=cex:Cash and Sequence Number=1
  Infer cex:ContractTypeB given Financial Instrument=cex:CreditCard and Sequence Number=1


To help understand how this works, you can define the rule for ContractTypeC.  Take the following steps:
 1) Choose "Create from SPIN Template" from the context menu for spin:rule (in the class owl:Thing)
 2) Choose the template I defined, cex:InferContractType
 3) Fill in the values - I'd suggest cex:ContractTypeC, cex:DebitCard, and 1 for values

Click OK and a new template string will be displayed.

Run inferences again and it will define :InferAsContractTypeA as a type of :ContractTypeC.

This is a good example of how templates can be used to create
readable abstractions for rule systems. The text that appears in the spin:rule text box is defined by the pattern in the spin:labelTemplate for the cex:InferContractType template.

-- Scott


On 3/10/11 7:53 PM, aziza wrote:
Let's say  I have a template for all the contracts. where ?
contractName, ?No and ?class defined as parameters. I have a number of
contracts:ConatrcA,ContractB,ContractC..as sublass of Contract class.
Now, from some contract type (let's say contractA) I'm calling a
template1 (which accepts 3 above parameters) with passing actual
values which define this contract.For ex., I pass "contractA" for ?
contractName; "1" for ?No; "Cash" for ?class.
So,that's all defined under spin:rule. By the way, I defined several
templates and each differes by number of parameters.)
Template1.
CONSTRUCT { ?contract a :?contractName }
WHERE
{  ?contract :hasProcess ?p1 .
   ?p1 hasInitiator ?i1 .
   ?i1 a :Bank .
   ?p1 :hasRecipient ?r1 .
   ?r1 a :Supplier .
    ?p1 :hasSeqNo ?No .
    ?p1 :hasFinancialInstrument ?f1 .
   ?f1 rdf:type ?class.
  }
Imagine I do the same thing for each contract. And when i execute the
rule(by clicking the triangle whith promts says:"execute as SPARQL
query" ) then the system will infer a type of untyped resource which I
had under owl:Thing. As you can see I ', firing particular rule to
know what belongs to contactA.
But  is it possible for untyped resource the system identify an
appropriate template itself (probably, by watching on parameters which
this resource has - see an example below, for ex., ":Cash" and "1"
are parameters which matches with contractA ) which infer its
type.This I meant for  "...automatically finds a rule and fire it".

Resource (untyped instance)
    ?c :hasProcess ?p1 .
    ?p1 :hasInitiator ?i1 .
    ?i1 a :Bank .
    ?p1 :hasRecipient ?r1 .
    ?r1 a :Supplier .
    ?p1 :hasFinancialInstrument ?fi1 .
    ?fi1 a :Cash .
    ?p1 :hasSequenceNo "1" .

Thanks and Regards, Aziza



On 3/10/11 6:52 AM, aziza wrote:
Hey,all!
A couple of days ago I was describing my issue of a contract
compliance. I remind you abt it in few words.
Currently I have a number of resorces and a few rules which infer a
type of resource. To infer to which type a resource belongs to I need
manually to find an appropriate rule and fire it. But actually I want
that based on input data the system would automatically identify which
rule to fire and a firing a needed rule will infer a type of this
resource.
For ex.,
CONSTRUCT { ?contract a :ContractA }
WHERE
{  ?contract :hasProcess ?p1 .
   ?p1 hasInitiator ?i1 .
   ?i1 a :Bank .
   ?p1 :hasRecipient ?r1 .
   ?r1 a :Supplier .
  }
So, if i fire this rule it would infer that some resourceA which
satisfies some conditions under WHERE clause is a type of ContractA.
But I want other way around: based on the input data (some resource)
the system would automatically finds a rule and fire it.
Is it possible to do? Is it possible to do by  TopBraid or
AllegroGraph?
Would be very grateful to you help.
Regard,Aziza



--
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 Mar 10 22:13:48 CST 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#> .

[]    rdf:type inference:Configuration ;
      composite:child
              [ rdf:type <http://spinrdf.org/spin#TopSPIN> ;
                composite:index "0"^^xsd:int
              ] .
# Saved by TopBraid on Thu Mar 10 22:13:48 CST 2011
# baseURI: http://support.tq.com/examples/contractTypeEx
# imports: http://spinrdf.org/spin

@prefix cex:     <http://support.tq.com/examples/contractTypeEx#> .
@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 sp:      <http://spinrdf.org/sp#> .
@prefix spin:    <http://spinrdf.org/spin#> .
@prefix spl:     <http://spinrdf.org/spl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

sp:contractName
      rdf:type rdf:Property ;
      rdfs:label "contract name"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

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

sp:seqNo
      rdf:type rdf:Property ;
      rdfs:label "seq no"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

<http://support.tq.com/examples/contractTypeEx>
      rdf:type owl:Ontology ;
      owl:imports <http://spinrdf.org/spin> ;
      owl:versionInfo "Created with TopBraid Composer"^^xsd:string .

cex:Bank
      rdf:type owl:Class ;
      rdfs:label "Bank"^^xsd:string ;
      rdfs:subClassOf owl:Thing .

cex:Bank_1
      rdf:type cex:Bank ;
      rdfs:label "Bank 1"^^xsd:string .

cex:Cash
      rdf:type cex:FinancialInstrument ;
      rdfs:label "Cash"^^xsd:string .

cex:ContractType
      rdf:type owl:Class ;
      rdfs:label "Contract type"^^xsd:string ;
      rdfs:subClassOf owl:Thing .

cex:ContractTypeA
      rdf:type owl:Class ;
      rdfs:label "Contract type a"^^xsd:string ;
      rdfs:subClassOf cex:ContractType .

cex:ContractTypeB
      rdf:type owl:Class ;
      rdfs:label "Contract type b"^^xsd:string ;
      rdfs:subClassOf cex:ContractType .

cex:ContractTypeC
      rdf:type owl:Class ;
      rdfs:label "Contract type c"^^xsd:string ;
      rdfs:subClassOf cex:ContractType .

cex:CreditCard
      rdf:type cex:FinancialInstrument ;
      rdfs:label "Credit card"^^xsd:string .

cex:DebitCard
      rdf:type cex:FinancialInstrument ;
      rdfs:label "Debit card"^^xsd:string .

cex:FinancialInstrument
      rdf:type owl:Class ;
      rdfs:label "Financial instrument"^^xsd:string ;
      rdfs:subClassOf owl:Thing .

cex:InferAsContractTypeA
      rdf:type owl:Thing ;
      rdfs:label "Infer as contract type a"^^xsd:string ;
      cex:hasProcess cex:ProcessForTypeA .

cex:InferAsContractTypeB
      rdf:type owl:Thing ;
      rdfs:label "Infer as contract type b"^^xsd:string ;
      cex:hasProcess cex:ProcessForTypeB .

cex:InferAsContractTypeC
      rdf:type owl:Thing ;
      rdfs:label "Infer as contract type c"^^xsd:string ;
      cex:hasProcess cex:ProcessForTypeC .

cex:InferContractType
      rdf:type spin:Template ;
      rdfs:label "Infer contract type"^^xsd:string ;
      rdfs:subClassOf spin:Templates ;
      spin:body
              [ rdf:type sp:Construct ;
                sp:templates ([ sp:object
                                    [ sp:varName "contractName"^^xsd:string
                                    ] ;
                            sp:predicate rdf:type ;
                            sp:subject _:b1
                          ]) ;
                sp:where ([ sp:object _:b2 ;
                            sp:predicate cex:hasProcess ;
                            sp:subject _:b1
                          ] [ sp:object _:b3 ;
                            sp:predicate cex:hasInitiator ;
                            sp:subject _:b2
                          ] [ sp:object cex:Bank ;
                            sp:predicate rdf:type ;
                            sp:subject _:b3
                          ] [ sp:object _:b4 ;
                            sp:predicate cex:hasRecipient ;
                            sp:subject _:b2
                          ] [ sp:object cex:Supplier ;
                            sp:predicate rdf:type ;
                            sp:subject _:b4
                          ] [ sp:object
                                    [ sp:varName "seqNo"^^xsd:string
                                    ] ;
                            sp:predicate cex:hasSeqNo ;
                            sp:subject _:b2
                          ] [ sp:object _:b5 ;
                            sp:predicate cex:hasFinancialInstrument ;
                            sp:subject _:b2
                          ] [ sp:object
                                    [ sp:varName "class"^^xsd:string
                                    ] ;
                            sp:predicate rdf:type ;
                            sp:subject _:b5
                          ])
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:f1 ;
                spl:valueType cex:FinancialInstrument
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:contractName ;
                spl:valueType owl:Class
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                spl:predicate sp:seqNo ;
                spl:valueType xsd:integer
              ] ;
      spin:labelTemplate "Infer {?contractName} given Financial 
Instrument={?f1} and Sequence Number={?seqNo}"^^xsd:string .

cex:Process
      rdf:type owl:Class ;
      rdfs:label "Process"^^xsd:string ;
      rdfs:subClassOf owl:Thing .

cex:ProcessForTypeA
      rdf:type cex:Process ;
      rdfs:label "Process For Type A"^^xsd:string ;
      cex:hasFinancialInstrument
              cex:Cash ;
      cex:hasInitiator cex:Bank_1 ;
      cex:hasRecipient cex:Supplier_1 ;
      cex:hasSeqNo 1 .

cex:ProcessForTypeB
      rdf:type cex:Process ;
      rdfs:label "Process for type b"^^xsd:string ;
      cex:hasFinancialInstrument
              cex:CreditCard ;
      cex:hasInitiator cex:Bank_1 ;
      cex:hasRecipient cex:Supplier_1 ;
      cex:hasSeqNo 1 .

cex:ProcessForTypeC
      rdf:type cex:Process ;
      rdfs:label "Process for type c"^^xsd:string ;
      cex:hasFinancialInstrument
              cex:DebitCard ;
      cex:hasInitiator cex:Bank_1 ;
      cex:hasRecipient cex:Supplier_1 ;
      cex:hasSeqNo 1 .

cex:Supplier
      rdf:type owl:Class ;
      rdfs:label "Supplier"^^xsd:string ;
      rdfs:subClassOf owl:Thing .

cex:Supplier_1
      rdf:type cex:Supplier ;
      rdfs:label "Supplier 1"^^xsd:string .

cex:hasFinancialInstrument
      rdf:type owl:ObjectProperty ;
      rdfs:label "has financial instrument"^^xsd:string .

cex:hasInitiator
      rdf:type owl:ObjectProperty ;
      rdfs:label "hasinitiator"^^xsd:string .

cex:hasProcess
      rdf:type owl:ObjectProperty ;
      rdfs:label "has process"^^xsd:string .

cex:hasRecipient
      rdf:type owl:ObjectProperty ;
      rdfs:label "has recipient"^^xsd:string .

cex:hasSeqNo
      rdf:type owl:DatatypeProperty ;
      rdfs:label "has seq no"^^xsd:string ;
      rdfs:range xsd:integer .

owl:Thing
      spin:rule
              [ rdf:type cex:InferContractType ;
                sp:contractName cex:ContractTypeB ;
                sp:f1   cex:CreditCard ;
                sp:seqNo 1
              ] ;
      spin:rule
              [ rdf:type cex:InferContractType ;
                sp:contractName cex:ContractTypeA ;
                sp:f1   cex:Cash ;
                sp:seqNo 1
              ] .

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

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

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

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

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

Reply via email to