Archive

Adding Construct to your Ubuntu start menu.

In this post, I show you how to add construct to your ubuntu start menu. The assumption I am making is that you have the most recent version of construct (currently 0.74) downloaded and installed.

Step 1

This step allows you to run construct without being in the construct directory.

Open the ‘construct.sh’ file and change the line:

CONSTRUCT_HOME=.

to

CONSTRUCT_HOME=YOUR CONSTRUCT DIRECTORY

For me it is: $HOME/construct

Save the file and exit.

Step 2

Create a symbolic link to the executable shell script.

This allows you to just type ‘construct’ in the terminal, much the same way you would write ‘emacs’ etc.

Open a terminal and type:

cd /usr/bin/

now type:

ln -s LOCATION_OF_CONSTRUCT_DIRECTORY/construct.sh construct

Now type cd

Type ‘construct’. Construct should start running.

It will tell you, however that it could not find the properties file.

Step 3

Copy the construct.properties file to your home directory.

Exit construct if you have it open.

Open a terminal.

cd to your construct directory (in my case cd ~/construct)

Copy the file to your home directory:

cp construct.properties ~/ (~/ is a shorthand notation for your home directory)

Step 4

In your ubuntu status bar, double click on the ’start menu’ — the orange circular icon on the left.

Click on ‘Edit Menus’

Click on the ‘New Item’ button on the right

For ‘Name’, type ‘Construct’

For ‘Command’, type ‘construct’

Click OK.

That’s it!

Construct is now in your start menu!

Understanding the construct.properties file

As the name suggests, the construct.properties file defines settings for the Construct platform. The settings cover three things: global properties for Construct, the components to be instantiated at runtime, and the individual properties of each component.

In the current release, all (bar one) of the global properties are related to logging. The other refers to the hostname of the machine running the Construct software:

Logging level The level of log messages to be recorded
The Logging limit The maximum number of bytes to write to any one log file
The logging file count The number of log files to rotate
The logging file name The base name to use for log files
The logging directory The directory in which the log files are stored
The hostname The hostname or IP address of the machine running the Construct software

The components that you wish to instantiate once the Construct framework is started are also contained in the properties file. Some components also contain properties which are specific to those components and must be declared as children of the components in the properties file. The structure of the properties file is explained further on. Below is an example of some Construct components. More thorough explanations can be found elsewhere on the Wiki.

Data Store Manager Provides a single point of access to the data store
Query Service Processes application and entity queries made in SPARQL
Data Port Accepts RDF data provided by sensors and adds them to the data store
Registry Service Stores information on registered services
Discovery Service Handles requests from clients for available Construct services
Gossiping Components Allows distribution of data store contents
Extension Components Add-on components such as a Query Viewer

Once the start button is clicked on the Construct GUI, a Component Loader is created which reads in the contents of the properties file and instantiates any components that are specified. On instantiation, each component fetches it’s properties and caters for them.

Reading and Writing to the construct.properties File

The construct.properties file is and XML encoded file in which all properties and components must be contained within the parent node, construct (i.e. it takes the form … ). Global properties must be contained directly inside the construct tags and they are indicated by a property tag. Thus, all properties take the form,

  1. <property name=“[the name here]“ value=“[the value here]“ />

Components must also be defined directly inside the construct tags. The component specific properties must be declared directly inside the opening and closing tags of the component in question. Components are scripted as follows:

  1. <component interface=“[the interface to the component here]“ implementation=“[the implementation of the component here]“>
  2. <property/>
  3. </component>

where the interface specifies the path to the interface for the component and the implementation specifies the path to the concrete implementation of the component.

There is an example properties file contained in the release of Construct. To add new properties follow the structure of the document as explained above. HTML style comments (i.e. <!– [the code to comment here] –>) can be used to prevent a property or component contained in the file from being read in. Ensure to comment the property or component by adding the opening comment (<!–) before the opening tag of the component or property and adding the closing comment (–>) after the closing tag.

HTTP Port - Part 2

In part 1 of this post I described the new HTTP Port in Construct. In this part of the post I’ll explain how to write a web form and style the return values.

SPARQL Query

You can send a query to Construct with GET or POST. Here is how we do it in HTML with GET:

  1. <form method=“GET” action=“http://duvel.ucd.ie:8888/”>
  2. <textarea name=“q” cols=“64″ rows=“10″>SELECT ?subject ?predicate ?object WHERE {?subject ?predicate ?object}</textarea><br/>URL of XSLT to apply (optional):<br/><input type=“text” name=“xsl” size=“56″ value=“http://www.construct-infrastructure.org/stylesheets/default.xsl type=”submit” value=”Submit Query“>
  3. </form>

the only thing the HTTP Port wants is the query field to be called either “q” or “query”. The returned XML will be sent back to your browser. Something like this:

  1. <?xml version=“1.0″?>
  2. <?xml-stylesheet type=“text/xsl” href=“http://duvel.ucd.ie:8888/xsl/www.construct-infrastructure.org/stylesheets/default.xsl”?>
  3. <sparql
  4. xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#”
  5. xmlns:xs=“http://www.w3.org/2001/XMLSchema#”
  6. xmlns=“http://www.w3.org/2005/sparql-results#”>
  7. <head>
  8. <variable name=“subject”/>
  9. <variable name=“predicate”/>
  10. <variable name=“object”/>
  11. </head>
  12. <results>
  13. <result>
  14. <binding name=“subject”> <uri>http://www.pervasive-ontologies.org/ontologies/sensors/bluetooth#reading00:19:63:96:56:01@00:80:98:94:AE:4B@1201631502</uri>
  15. </binding>
  16. <binding name=“predicate”>