I tried replacing the current spin:body in spl:Attribute with:
# Type or Cardinality Constraint
CONSTRUCT {
_:b0 a spin:Constraint ;
spin:violationRoot ?this ;
spin:violationPath ?predicate ;
}
WHERE {
?this ?predicate ?value
FILTER (bound(?maxCount) && (spl:objectCount(?this, ?predicate) > ?maxCount)
||
(bound(?minCount) && (spl:objectCount(?this, ?predicate) <
?minCount)) ||
(bound(?valueType) && (!spl:instanceOf(?value, ?valueType))))
} limit 1
But TBC doesn't catch the constraint error after the change, so I'm assuming
the spin code (SPINConstraints.check) won't catch it either. A couple of
points about the above query:
1. For some reason the UNIONs around the FILTERs wouldn't work for me when I
was testing the query, so I had to change it to one big FILTER using ||'s.
2. When testing in the SPARQL tab, I pre-filled the variables using LET
statements at the start of the WHERE clause, and this did work in that it
correclty detected constraint errors in the resource, e.g.
# Type or Cardinality Constraint
CONSTRUCT {
_:b0 a spin:Constraint ;
spin:violationRoot ?this ;
spin:violationPath ?predicate ;
}
WHERE {
LET (?minCount := 1)
LET (?maxCount := 1)
LET (?predicate := Neutral:hasActionOutcomeValue)
LET (?valueType := Neutral:ActionOutcomeValue)
?this ?predicate ?value
FILTER (bound(?maxCount) && (spl:objectCount(?this, ?predicate) > ?maxCount)
||
(bound(?minCount) && (spl:objectCount(?this, ?predicate) <
?minCount)) ||
(bound(?valueType) && (!spl:instanceOf(?value, ?valueType))))
} limit 1
Anyway, not that this is a long term solution (can't change the SPIN models),
but perhaps it's a step towards a solution if I can get this working. I hate
to not be able to use the spl:Attribute template because I currently use it
extensively in my models.
Thanks,
Jeff
Work: 314-232-1997
Cell: 636-448-5990
> -----Original Message-----
> From: Schmitz, Jeffrey A
> Sent: Thursday, December 03, 2009 9:28 AM
> To: [email protected]
> Subject: RE: [tbc-users] [SPIN API] Access SPIN cardinality
> contraint violation messages
>
> >
> > Which SPIN template did you use for cardinality checking?
> If this is
> > under your control, why don't you CONSTRUCT the
> spin:violationPath to
> > remember the property at creation time?
> >
> >
> I'm using the spl:Attribute spin:Template that gets created
> when using the "Create from SPIN Template" tool to add
> attributes to a Class. I'm still trying to wrap my mind
> around exactly how this template works in regards to raising
> constraint violations. I see it has a spin:body that looks
> like the ASK query that should get invoked to check for
> cardinality and type constraint checking:
>
> ASK WHERE {
> {
> FILTER (bound(?minCount) && (spl:objectCount(?this,
> ?predicate) < ?minCount)) .
> }
> UNION
> {
> FILTER (bound(?maxCount) && (spl:objectCount(?this,
> ?predicate) > ?maxCount)) .
> }
> UNION
> {
> FILTER bound(?valueType) .
> ?this ?predicate ?value .
> FILTER (!spl:instanceOf(?value, ?valueType)) .
> } .
> }
>
> But why is it specified with a spin:body property, and not
> spin:constraint? And I think you're saying to replace this
> ASK constraint check with a CONSTRUCT constraint check, but
> the ASK constraint check is part of the spl model, so I don't
> have control over that, right? Perhaps I won't be able to
> use the spl:Attribute template to do what I want and will
> have to create my own Attribute template? If that's the
> case, then I'd like to understand why the constraint check
> SPARQL is referenced with a spin:body property.
>
> Or perhaps the Create form SPIN Template tool could add a
> "spin:constraint" property where the constraint checking code
> could optionally be provided by the user? OR (and this may be
> asking a lot) could the Create from SPIN Template tool add an
> option to auto-generate a CONSTRUCT constraint check instead
> of the ASK constraint check, injecting the added information
> from the other parameters used to instantiate the
> spl:Attribute template (e.g. minCount, maxCount, predicate,
> valueType)? Something like:
>
> CONSTRUCT {
> _:b0 a spin:Constraint ;
> spin:violationRoot ?this ;
> spin:violationPath ?predicate ;
> rdfs:label ?labelTemplate ;
> }
> WHERE {
> {
> FILTER (bound(?minCount) && (spl:objectCount(?this,
> ?predicate) < ?minCount)) .
> }
> UNION
> {
> FILTER (bound(?maxCount) && (spl:objectCount(?this,
> ?predicate) > ?maxCount)) .
> }
> UNION
> {
> FILTER bound(?valueType) .
> ?this ?predicate ?value .
> FILTER (!spl:instanceOf(?value, ?valueType)) .
> }
> ?this spin:labelTempalte ?labelTemplate .
> }
>
> Would it work if I just substituted the current ASK query in
> the spl model with something like the above?
>
>
> > Regards,
> > Holger
> >
> > --
> >
> > You received this message because you are subscribed to the Google
> > Groups "TopBraid Composer Users" group.
> > 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-composer-users?hl=en.
> >
> >
> >
>
> --
>
> You received this message because you are subscribed to the
> Google Groups "TopBraid Composer Users" group.
> 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-composer-users?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"TopBraid Composer Users" group.
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-composer-users?hl=en.