This SPARQLMotion script defines a Web Service that can be called to get the name of the country for a given calling code. The script takes a calling code as input and then runs a query against the DBPedia SPARQL end point to retrieve the label of the first place with this calling code. Then, it constructs a response string and sends it back as text.
To try this example, download the file below into your TopBraid Composer (Maestro) workspace, then open the file to activate the services registry at Maestro's internal web server, and then open a URL such as the following in your web browser:
http://localhost:8083/tbl/actions?action=sparqlmotion&id=
FindByCallingCode&callingCode=61
Example response: 61 is the calling code of Australia.
Download in N3 format (2009-04-06)
(for 3.0 or above) for TBS 2.6.2 or earlier, use this

Details on the steps (in order to execution from top to bottom) follow.
| Argument callingCode (type: Argument). This module is created when the SPIN function
is created (see below). It takes an argument from a query string (or user input if executed in TopBraid Composer-ME) and
convert it into an xsd:integer variable named ?callingCode that can be used in the rest of the script. |
 |
| Get country from DBPedia (type: Bind by select). Performs a SPARQL SELECT query on the DBPedia SPARQL end point (specified in the FROM clause). The query already has the value for callingCode bound with the parameter from the first step. It will first ask for the country with the given calling code and then get the label of that country. The label will be assigned to the variable label and passed to the next modules. |
 |
| Construct response (type: Bind literal value). Creates a single text value by inserting the callingCode and the label into a template. The text variable has the same name as the input variable of the next module and therefore will serve as input to the final step. |
 |
| Find by calling code module (type: Return text).
Takes the text as input and returns it to the function that defines the service. |
 |
 |
Web service identifier.
The SPIN function FindByCallingCode is defined as a subclass of spin:functions (left) and serves as the identifier for this Web Service. |
 |
Defining arguments passed to script. Arguments are defined by by creating
an instance of spin:constraint in the function class (see spin:constraint in Class Form below).
Use "Create from SPIN template..." and define an argument using a defined predicate ("callingCode"). The predicate will be bound to a variable (?callingCode)
in the SPARQLMotion script. Set the value type to the type required for the variable. |
 |
Connecting Web service to script. sm:returnModule is used to link the defined function to the script endpoint.
FindByCallingCode is used to identify the script (sparqlmotionid=FindByCallingCode")and the argument names are used to identify
parameters passed via the service call ("callingCode=61"). |
|