Hi William,

let me guess that you are using the SPIN API programmatically? I have (re)constructed your example in a Turtle file (attached for your reference) which works fine when run inside of TBC, so I assume you are executing this differently.

With the API, you need to make that when using spin:_arg1 etc, that your function's graph includes the SPIN system triples, so that it knows that spin:_arg1 is indeed a sp:Variable. But it seems that you have already excluded that possibility. In any case, using named properties from the arg: namespace is probably a better choice, making the query more readable. I have done that in the attached copy if you want to try it out if it makes a difference.

If this does not help, I would need more details of the Java code, ideally a self-contained scenario.

Thanks
Holger


On 4/9/2014 5:06, William Van Woensel wrote:
Hi,

I can't seem to get a very basic thing right, namely passing parameters to custom defined functions..

The data:

    @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix sp:    <http://spinrdf.org/sp#> .
    @prefix spl:   <http://spinrdf.org/spl#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
    @prefix spin:  <http://spinrdf.org/spin#> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix impact: <http://www.dal.ca/nichegroup/impactaf#> .
    @prefix owl: <http://www.w3.org/2002/07/owl#> .
    impact:PatientProfileChart0 impact:hasSystolicBloodPressure
    impact:SystolicBloodPressure41 .
    impact:SystolicBloodPressure41 impact:hasValue "142.84"^^xsd:double .
    impact:SystolicBloodPressure41 rdf:type impact:SystolicBloodPressure .
    impact:SystolicBloodPressure41 impact:hasLatestDate
    "true"^^xsd:boolean .
    impact:hasLatestDate rdf:type rdf:Property .


The rule (attached to the proper class):

    impact:SystolicBloodPressure
    spin:rule
    [ a             sp:Construct ;
     sp:templates  ( [ sp:object impact:HighSystolicBloodPressure ;
                       sp:predicate  impact:hasDSSFinding ;
                       sp:subject    [ sp:varName  "p"^^xsd:string ]
                     ] [ sp:object "DiaryHighSystolicBloodPressure" ;
                         sp:predicate  impact:hasTriggeredRule ;
                         sp:subject  impact:HighSystolicBloodPressure
                       ] [ sp:object     "Patient's systolic
    bloodpressure is uncontrolled" ;
                           sp:predicate  impact:hasLabel ;
                           sp:subject  impact:HighSystolicBloodPressure
                         ] [ sp:object     impact:DSSFinding ;
                             sp:predicate  rdf:type ;
                             sp:subject  impact:HighSystolicBloodPressure
                           ] ) ;
     sp:where      ( [ sp:object     [ sp:varName  "h"^^xsd:string ] ;
                       sp:predicate  impact:hasSystolicBloodPressure ;
                       sp:subject    [ sp:varName  "p"^^xsd:string ]
                     ] [ sp:object     [ sp:varName  "v"^^xsd:string ] ;
                         sp:predicate  impact:hasValue ;
                         sp:subject    [ sp:varName  "h"^^xsd:string ]
                       ] [ a              sp:Filter ;
                           sp:expression  [ a  impact:latest2 ;
                                            sp:arg1  [ sp:varName
    "h"^^xsd:string ]
                                          ]
                         ] [ a              sp:Filter ;
                             sp:expression  [ a        sp:ge ;
                                              sp:arg1  [ sp:varName
     "v"^^xsd:string ] ;
                                              sp:arg2  135
                                            ]
                           ] )
    ] .


And finally, the custom function:

    impact:latest2  a         spin:Function ;
            rdfs:comment     "Checks whether the given resource is the
    'latest' of its type" ;
            rdfs:label       "latest"^^xsd:string ;
            rdfs:subClassOf  spin:Functions ;
            spin:body        [ a         sp:Ask ;
                               sp:where  ( [ sp:object
    "true"^^xsd:boolean ;
                                             sp:predicate
     impact:hasLatestDate ;
                                             sp:subject  spin:_arg1
                                           ] )
                             ] ;
            spin:constraint  [ a              spl:Argument ;
                               rdfs:comment   "The resource to check
    for 'latestness'."^^xsd:string ;
                               spl:predicate  sp:arg1
                             ] .


Nothing is returned, although it should infer some triples. In fact, when I replace the "spin:_arg1" by the concrete resource (impact:SystolicBloodPressure41), the triples /are correctly /inferred. I tried a bunch of things, such as replacing the "[ sp:varName "h"^^xsd:string ]" by spin:_h, the spin:_arg1 by "[ sp:varName "arg1"^^xsd:string ]", etc, but to no avail..

PS: I know the latest function is trivial and can be replaced by a triple pattern, but the actual function has been simplified for the purposes of this example.

Any ideas?


Thanks,

William
--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL Web Pages 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 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 Enterprise Vocabulary 
Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL 
Web Pages 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 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.
# baseURI: http://example.org/unnamed
# imports: http://spinrdf.org/spin

@prefix impact: <http://example.org/unnamed#> .
@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#> .

<http://example.org/unnamed>
  rdf:type owl:Ontology ;
  owl:imports <http://spinrdf.org/spin> ;
  owl:versionInfo "Created with TopBraid Composer"^^xsd:string ;
.
impact:PatientProfileChart0
  impact:hasSystolicBloodPressure impact:SystolicBloodPressure41 ;
.
impact:SystolicBloodPressure
  rdf:type owl:Class ;
  spin:rule [
      rdf:type sp:Construct ;
      sp:templates (
          [
            sp:object impact:HighSystolicBloodPressure ;
            sp:predicate impact:hasDSSFinding ;
            sp:subject [
                sp:varName "p"^^xsd:string ;
              ] ;
          ]
          [
            sp:object "DiaryHighSystolicBloodPressure" ;
            sp:predicate impact:hasTriggeredRule ;
            sp:subject impact:HighSystolicBloodPressure ;
          ]
          [
            sp:object "Patient's systolic bloodpressure is uncontrolled" ;
            sp:predicate impact:hasLabel ;
            sp:subject impact:HighSystolicBloodPressure ;
          ]
          [
            sp:object impact:DSSFinding ;
            sp:predicate rdf:type ;
            sp:subject impact:HighSystolicBloodPressure ;
          ]
        ) ;
      sp:where (
          [
            sp:object [
                sp:varName "h"^^xsd:string ;
              ] ;
            sp:predicate impact:hasSystolicBloodPressure ;
            sp:subject [
                sp:varName "p"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "v"^^xsd:string ;
              ] ;
            sp:predicate impact:hasValue ;
            sp:subject [
                sp:varName "h"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Filter ;
            sp:expression [
                rdf:type impact:latest2 ;
                sp:arg1 [
                    sp:varName "h"^^xsd:string ;
                  ] ;
              ] ;
          ]
          [
            rdf:type sp:Filter ;
            sp:expression [
                rdf:type sp:ge ;
                sp:arg1 [
                    sp:varName "v"^^xsd:string ;
                  ] ;
                sp:arg2 135 ;
              ] ;
          ]
        ) ;
    ] ;
.
impact:SystolicBloodPressure41
  rdf:type impact:SystolicBloodPressure ;
  impact:hasLatestDate "true"^^xsd:boolean ;
  impact:hasValue "142.84"^^xsd:double ;
.
impact:hasLatestDate
  rdf:type rdf:Property ;
.
impact:latest2
  rdf:type spin:Function ;
  spin:body [
      rdf:type sp:Ask ;
      sp:where (
          [
            sp:object "true"^^xsd:boolean ;
            sp:predicate impact:hasLatestDate ;
            sp:subject [
                sp:varName "systolicBloodPressure"^^xsd:string ;
              ] ;
          ]
        ) ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate <http://spinrdf.org/arg#systolicBloodPressure> ;
      spl:valueType impact:SystolicBloodPressure ;
    ] ;
  rdfs:comment "Checks whether the given resource is the 'latest' of its type" ;
  rdfs:label "latest"^^xsd:string ;
  rdfs:subClassOf spin:Functions ;
.
<http://spinrdf.org/arg#systolicBloodPressure>
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.

Reply via email to