Rodolfo; There may be a couple of SPIN principles that may be helpful to you.  The first is that constraints, constructors and rules are defined for a class and applied to its members.  The second is that ?this should be used to state that the query is applied to individual members.  I.e. in the following query:
 1) is defined as a spin:constraint property for bad:Device
 2) the triple pattern <?dev rdf:type bad:Device> is not necessary because ?this is pre-bound to each member of bad:Device

CONSTRUCT {
    _:b0 a spin:ConstraintViolation .
    _:b0 spin:violationRoot ?this .
    _:b0 spin:violationPath bad:deviceIngressProtection .
    _:b0 rdfs:label "the value should be between 20 and 30" .
}
WHERE {
    ?this bad:deviceIngressProtection ?value .
    FILTER ((?value < 20) || (?value > 30)) .
}

In this case, I'm using Composer's constraint violation infrastructure to show this, so I'm creating a ConstraintViolation instance and hanging it on the bad:deviceIngressProtection property.

I'm attaching a model that demonstrates this.  You can try it out in TBC Free/SE/ME.

-- Scott


On 10/7/10 1:29 AM, dennis wrote:
Hi Rodolfo,

could it be that ?value refers to a plain literal? I've realized that
arithmetic operations don't work if the literals are not explicitly
typed e.g. as xsd:integer or xsd:double, and maybe this holds for <
and > comparisons as well...

Cheers,
Dennis

On 7 Okt., 03:37, Holger Knublauch <[email protected]> wrote:
Hi Rudolfo,

I am not sure where the problem is in your example. I think I need more information - feel free to send me your specific example (off-list). I notice that you are creating the CONSTRUCT query but it is unclear whether this constraint is also attached to the model somehow.

Holger

On Oct 7, 2010, at 5:00 AM, Rodolfo Rieckhof wrote:

Hello Holger,
thanks for your quick response. I have downloaded the new API and it works just fine. But i have another question.
How can  i insert a SPIN constraint dynamically in my ontology ? I have tried the following:
I create a constraint, just like in the examples with:

        
...
String query = prefixes +
"CONSTRUCT { _:b0 bad:deviceIngressProtection ?value;" +
"      rdfs:label 'the value should be between 20 an 30'} " +
"WHERE { ?dev rdf:type bad:Device ; bad:deviceIngressProtection ?value ." +
"      FILTER ( ?value < 20 || ?value > 30) " +
"}";

        
Query arqQuery = ARQFactory.get().createQuery(model, query);
ARQ2SPIN arq2SPIN = new ARQ2SPIN(model);
Construct spinQuery = (Construct) arq2SPIN.createQuery(arqQuery, null);

        
//then i load my Onotology

        
File root = new File("ontologies");
String  dataURL = new File(root.getAbsolutePath() + "/Thermokon_Easysens_Funkschalter_BJ_V1.owl").toURI().toString();
Reasoner reasoner = PelletReasonerFactory.theInstance().create();

        
 // create an empty model
   OntModel  PelletReasonerFactory.THE_SPEC );
   ontModel.read( dataURL );

        
//add the   model with the Constraint
ontModel.addl(model);
SPINModuleRegistry.get().registerAll(ontModel);

        
// let SPIN do its work
List<ConstraintViolation> cvs = SPINConstraints.check(ontModel, null);
System.out.println("Constraint violations:" + cvs.size());
for(ConstraintViolation cv : cvs) {
System.out.println(" - at " + SPINLabels.get().getLabel(cv.getRoot()) + ": " + cv.getRoot());
}

        
the Problem is that i don´t get any constrains violation  (cvs = 0). Although when i run the query with ARQ I get 1. Could you tell me please wich is the wright way to do this ? . Is it a problem, that the is Ontology in rdf ?

        
Regards,
Rodolfo

        
2010/10/6 Holger Knublauch <[email protected]>:
Hi Rodolfo,

        
thanks a lot for this bug report. It was indeed a (simple) recursive loop. Since this was a small but rather critical bug, I have just updated the SPIN API that is on the web with a fix. The file has still the same version number etc, but the infinite loop should be gone now. I plan to do a proper release with a couple of new features in a few weeks after it went through QA.

        
Thanks again
Holger

        
On Oct 6, 2010, at 4:28 AM, [email protected] wrote:

        
Hello everyone,
I just downloaded the implementation of the SPIN API 1.1.2 and  when
i run the example KennedysInferencingAndConstraintsExample i get an
StackOverflowError. I haven't changed anything in the source and i
think the problem is in this piece of code:

        
...
// Run constraints on a single instance only
              Resource person = cvs.get(0).getRoot();
              List<ConstraintViolation> localCVS = SPINConstraints.check(person,
null);
              System.out.println("Constraint violations for " +
SPINLabels.get().getLabel(person) + ": " + localCVS.size());

        
i am using jena 2.6.3 and ARQ  2.8.5. I would be very thankful for any
help.

        
Regards
Rodolfo

        
Console output:

        
Inferred triples: 136
Constraint violations:
- at spin:AskTemplates:
- at spin:UpdateTemplates:
- at spin:SelectTemplates:
- at spin:ConstructTemplates:
- at kennedys:JosephKennedy: age must be within a realistic range
- at kennedys:StephenSmith: Same-sex marriage not permitted (in this
model)
- at kennedys:JeanKennedy: Same-sex marriage not permitted (in this
model)
Exception in thread "main" java.lang.StackOverflowError
      at
org.topbraid.spin.constraints.SPINConstraints.check(SPINConstraints.java:
259)
      at
org.topbraid.spin.constraints.SPINConstraints.check(SPINConstraints.java:
259)
....

        
--
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

        
--
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 Oct 07 09:41:50 CDT 2010
# baseURI: http://support.tq.com/RodolfoCVW
# imports: http://spinrdf.org/spin

@prefix bad:     <http://support.tq.com/RodolfoCVW#> .
@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 xsd:     <http://www.w3.org/2001/XMLSchema#> .

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

bad:Device
      rdf:type owl:Class ;
      rdfs:subClassOf owl:Thing ;
      spin:constraint
              [ rdf:type sp:Construct ;
                sp:templates ([ sp:object spin:ConstraintViolation ;
                            sp:predicate rdf:type ;
                            sp:subject _:b1
                          ] [ sp:object spin:_this ;
                            sp:predicate spin:violationRoot ;
                            sp:subject _:b1
                          ] [ sp:object bad:deviceIngressProtection ;
                            sp:predicate spin:violationPath ;
                            sp:subject _:b1
                          ] [ sp:object "the value should be between 20 and 30" 
;
                            sp:predicate rdfs:label ;
                            sp:subject _:b1
                          ]) ;
                sp:where ([ sp:object _:b2 ;
                            sp:predicate bad:deviceIngressProtection ;
                            sp:subject spin:_this
                          ] [ rdf:type sp:Filter ;
                            sp:expression
                                    [ rdf:type sp:or ;
                                      sp:arg1 [ rdf:type sp:lt ;
                                                sp:arg1 _:b2 ;
                                                sp:arg2 20
                                              ] ;
                                      sp:arg2 [ rdf:type sp:gt ;
                                                sp:arg1 _:b2 ;
                                                sp:arg2 30
                                              ]
                                    ]
                          ])
              ] .

bad:Device_1
      rdf:type bad:Device ;
      bad:deviceIngressProtection
              55 .

bad:Device_2
      rdf:type bad:Device ;
      bad:deviceIngressProtection
              25 .

bad:deviceIngressProtection
      rdf:type owl:DatatypeProperty ;
      rdfs:range xsd:integer .

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

Reply via email to