Editing SPARQLMotion Scripts

As you can see below, SPARQLMotion scripts can be modeled with any RDF compliant tool, including TopBraid Composer's graph editor. The modules are instances of classes in a SPARQLMotion module library, such as the default TopBraid SPARQLMotion module library, and form-base editors can be used to fill in the parameters of each module, for example to specify the SPARQL query that shall be executed to populate a spreadsheet.

SPARQLMotion in TBC

 

One way of editing SPARQLMotion scripts in TopBraid Composer is by opening a secondary editor window (right-click on the editor tab and select New Editor) and then drag them side by side, showing the graph in one editor and the form in the other. Double-clicking any module in the graph will select its form on the right hand side. Alternatively, if you don't have enough screen real-estate to display graph and form side by side, you can double-click on a node to open the form for that node in a dialog.

 

In order to get started with a new SPARQLMotion script, create a new file and then go to Scripts > Create SPARQLMotion script... This may prompt you to import the SPARQLMotion standard module library, which you need to do first. You will then see an empty graph editor. (As a shortcut to creating a SPARQLMotion script, you can also pick Scripts > Create SPARQLMotion function/web service. This displays the Create SPARQLMotion function wizard, which automates the setup of a SPARQLMotion script that you can use as the basis of a function to use in your applications or as a web service to call from outside of TopBraid. After prompting you for your new function's name, SPARQLMotion return module type, and optional comment and arguments for the function, the wizard declares a new subclass of sm:Functions with the function name you entered and creates a SPARQLMotion script based on the values you entered. If the right libraries have not been imported when you first select this menu choice, it will only import the libraries after prompting you about this; the second time, it will start the wizard.)

When SPARQLMotion has been imported, the graph will provide additional capabilities. In particular it will present a palette of available module types on the side. You can drag and drop modules from this palette into the graph to add items. (On Mac the drag and drop is not supported - click on the type first and then on an empty area on the screen to place a new node). Note that you need to make sure that all modules are connected (somehow) so that they belong to the same script.

Double-clicking on a node in the graph will open a form. While you are editing a script, the graph editor will display yellow warning symbols over those nodes that are incomplete or otherwise violate SPARQLMotion syntactical constraints. Additional errors will be detected when the script is executed.

In order to get an alternative overview of an existing SPARQLMotion script, you may want to open the outline view, using Window > Show View > Script Outline. An example screenshot of this view is shown below.

SPARQLMotion Script Outline View

 

As an alternative to the graphical notation, TopBraid Composer 3.6 (or above) makes it possible to embed model SM modules into SPARQL Web Pages (SWP) snippets. This provides a text-based syntax that is sometimes less verbose than the graphical notation.

 

As SPARQLMotion scripts become more complex, it is often advisable to split them into multiple smaller chunks. SPARQLMotion scripts can "call" sub-scripts, that are encoded as sm:Functions. In order to convert a script snippet into a function, select the modules that you would like to extract and press the Extract SPARQLMotion function... button in the graph tool bar. This will ask you for a name of the sub-function, and then do all the remaining steps automatically: it will create a sm:Function with corresponding arguments and control logic to execute the snippet in the correct context, and then create an instance of this function that is inserted instead of the original block. Note that in order to use this refactoring, the selected block must be all connected and have a single endpoint. If that endpoint binds one result variable, then the function will return that value as function result. Care needs to be taken to make sure that the new function preserves the same semantics as before - especially double-check that the extracted block did not bind any other variables that are then used outside, in the surrounding script.