Archive for the 'Beginners' Category

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.

Construct and Python - Part 3

This tutorial shows how to insert RDF from a file (joebloggs_foaf.rdf) into Construct. It then shows how to send a SPARQL query to query this data from Construct. The resulting QueryResults object is printed in N3 format.

  1. from construct.proxy import proxy
  2. from construct.constructservice import ServiceError
  3. from rdflib.Graph import ConjunctiveGraph
  4. # Create a new proxy object.
  5. proxy = proxy()
  6. print “Executing Script”
  7. try:
  8. # Generate a piece of FOAF RDF
  9. store = ConjunctiveGraph()
  10. store.load(“joebloggs_foaf.rdf”)
  11. data = store.serialize(format=“nt”)
  12. # Send the FOAF RDF to the data store
  13. if(proxy.insert(data)):
  14. # Now query for joebloggs web address
  15. query = “”“SELECT ?nickname WHERE{
  16. ?subject <http://xmlns.com/foaf/0.1/name> “Joe Bloggs“.
  17. ?subject <http://xmlns.com/foaf/0.1/nick> ?nickname.}
  18. “”
  19. results = proxy.query(query)
  20. print “Here is the N3 form of the QueryResults Object:”
  21. print results
  22. except ServiceError, e:
  23. print e
  24. # Close the proxy.
  25. proxy.close()

If this script executes properly something like the following should be printed out:

Executing Script

Here is the N3 form of the QueryResults Object:

_:A6a94e801X3aX118515eda06X3aXX2dX7ffa <http://www.w3.org/2001/sw/DataAccess/tests/result-set#value> “joe” .

_:A6a94e801X3aX118515eda06X3aXX2dX7ffa <http://www.w3.org/2001/sw/DataAccess/tests/result-set#variable> “nickname” .

_:A6a94e801X3aX118515eda06X3aXX2dX7ffb <http://www.w3.org/2001/sw/DataAccess/tests/result-set#binding> _:A6a94e801X3aX118515eda06X3aXX2dX7ffa .

_:A6a94e801X3aX118515eda06X3aXX2dX7ffc <http://www.w3.org/2001/sw/DataAccess/tests/result-set#solution> _:A6a94e801X3aX118515eda06X3aXX2dX7ffb .

_:A6a94e801X3aX118515eda06X3aXX2dX7ffc <http://www.w3.org/2001/sw/DataAccess/tests/result-set#resultVariable> “nickname” .

_:A6a94e801X3aX118515eda06X3aXX2dX7ffc <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet> .
This post is the final part of a python and Construct tutorial. Part 1 is here and part 2 is here.

Construct and Python - Part 2

This code demonstrates how to interact with the client proxy using the RDFLib package:

  1. from construct.proxy import proxy
  2. from construct.constructservice import ServiceError
  3. from rdflib import RDF, Namespace, Literal
  4. from rdflib.Graph import ConjunctiveGraph
  5. FOAF = Namespace(“http://xmlns.com/foaf/0.1/”)
  6. exampleNS = Namespace(“http://www.example.com/”)
  7. # Create a new Proxy object.
  8. proxy = proxy()
  9. print “Executing Script”
  10. try:
  11. # Generate a piece of FOAF RDF
  12. store = ConjunctiveGraph()
  13. store.bind(“foaf”, “http://xmlns.com/foaf/0.1/”)
  14. store.add((exampleNS["~joebloggs"], RDF.type, FOAF["Person"]))
  15. store.add((exampleNS["~joebloggs"], FOAF["name"], Literal(“Joe Bloggs”)))
  16. store.add((exampleNS["~joebloggs"], FOAF