Skip to content
jorgearj edited this page Mar 28, 2013 · 1 revision

Please refer to the SPIN tutorial for a better explanation of its functionalities.

Example: Function_Web_Hosting

:Function_Web_Hosting
      a       spin:Function ;
      rdfs:label "Function Web Hosting"^^xsd:string ;
      spin:body
              [ a       sp:Select ;
                sp:resultVariables ([ sp:varName "price"^^xsd:string
                          ]) ;
                sp:where ([ sp:object
                                    [ sp:varName "a"^^xsd:string
                                    ] ;
                            sp:predicate usdl-price:hasValue ;
                            sp:subject :Variable_Number_of_WebSites
                          ] [ sp:object
                                    [ sp:varName "websites"^^xsd:string
                                    ] ;
                            sp:predicate <http://purl.org/goodrelations/v1#hasValueFloat> ;
                            sp:subject
                                    [ sp:varName "a"^^xsd:string
                                    ]
                          ] [ sp:object
                                    [ sp:varName "b"^^xsd:string
                                    ] ;
                            sp:predicate usdl-price:hasValue ;
                            sp:subject :Variable_WebSite_Cost
                          ] [ sp:object
                                    [ sp:varName "priceWS"^^xsd:string
                                    ] ;
                            sp:predicate <http://purl.org/goodrelations/v1#hasValueInteger> ;
                            sp:subject
                                    [ sp:varName "b"^^xsd:string
                                    ]
                          ] [ a       sp:Bind ;
                            sp:expression
                                    [ a       sp:mul ;
                                      sp:arg1 [ sp:varName "websites"^^xsd:string
                                              ] ;
                                      sp:arg2 [ sp:varName "priceWS"^^xsd:string
                                              ]
                                    ] ;
                            sp:variable
                                    [ sp:varName "price"^^xsd:string
                                    ]
                          ])
              ] ;
      usdl-price:hasVariable
              :Variable_WebSite_Cost , :Variable_Number_of_WebSites .

This is the example for the previous function for the :PriceComponent_Web_Hosting PriceComponent. In the final two lines we link the two needed variables to the Function itself with the property usdl-price:hasVariable. Note that this is a generated turtle sintax. Tools like TopBraid Composer can be used to manipulate Spin functions. These functions can be expressed in SPARQL language. The previous example can defined in the following way:

SELECT ?price
WHERE {
    :Variable_Number_of_WebSites usdl-price:hasValue ?a .
    ?a gr:hasValueFloat ?websites .
    :Variable_WebSite_Cost usdl-price:hasValue ?b .
    ?b gr:hasValueInteger ?priceWS .
    BIND ((?websites * ?priceWS) AS ?price) .
}
Clone this wiki locally