Skip to content
jorgearj edited this page Mar 28, 2013 · 24 revisions

SPIN:Function

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) .
}

Deduction

Deduction is a negative price component. The total price will be reduced by a certain amount. Deductions are defined in the same way as any PriceComponent as they are a specialization.

Example 1: Deduction

:PriceComponent_Usage_Discount
      rdf:type usdl-price:Deduction ;
      rdfs:label "Usage Discount"^^xsd:string ;
      usdl-price:hasPriceFuntion
              :Function_Usage_Discount ;
      usdl-price:hasTextFuntion
              "If number of hosted web-sites > 5 apply discount of 10%"^^xsd:string .

In this example we have a Deduction which is a special PriceComponent. This deduction specifies that if one user has more than 5 hosted web-sites he has a discount of 10% in the final price. Note that for better comprehension of the price calculation formula we use the property usdl-price:hasTextFuntion with a natural language description of the expression.

PriceVariable

A variable can be used for price function expressions of dynamic price models. It has a name (rdfs:label) and a quantitative value. This quantitative value may not be specified if the variable is not known prior to a user service configuration (e.g. usage variables) Variables can be referred from different price functions.

Example 1: Constant

:Variable_WebSite_Cost
      rdf:type usdl-price:Constant ;
      rdfs:label "hosting for one Web-Site Cost"^^xsd:string ;
      usdl-price:hasValue
              [ rdf:type gr:QuantitativeValue ;
                gr:hasValueFloat "5.0"^^xsd:float
              ] .

This is a usdl-price:Constant definition where a specific value is assigned with the property usdl-price:hasValue. In this case the cost for hosting one web-site is 5 (No currency was defined). However we can have Usage Variables.

Example 2: Usage

:Variable_Number_of_WebSites
      rdf:type usdl-price:Usage ;
      rdfs:label "The number of hosted web-sites"^^xsd:string ;

Some variables do not have as assigned value prior to service contracting. Usage Variables as used in this cases. This examples shows an usdl-price:Usage Variable for storing the total number of web-sites the user needs to be hosted. These are particularly important in pay-per-use models.

Clone this wiki locally