All messages that are exchanged between Construct services and applications take the following format: [3 bytes][10 bytes][payload]
- The first 3 bytes correspond to the message type identifier (see below).
The next 10 bytes correspond to the length of the message payload in bytes. For example, a message with a 64 byte payload would be written as 0000000064.
- Finally, the message payload consists of a number of bytes indicated by the previous part of the message. The contents of the payload are protocol specific.
The message identifier codes used are as follows:
| The protocol identifier for querying | QUERY | 200 |
| The protocol identifier used for responding to queries | QUERY_RESPONSE | 210 |
| The protocol identifier used for sending rdf statements to the data port | RDF_ADD | 100 |
| The protocol identifier used for responding to an add rdf statements request | RDF_ADD_RESPONSE | 110 |
| The protocol identifier used for sending a service descriptor | SERVICE_DESCRIPTOR_RESPONSE | 310 |
When most service send a response to the client, the payload also takes the form of a code:
| The operation succeeded | OK | 600 |
| An error occured during the operation | ERROR | 610 |
| The service code was unrecognised | UNKNOWN | 650 |
Working with the discovery service
Open a connection to the host/port given in the bonjour resolution (there is no need to send any data). You will be sent an XML descriptor file of the form -
-
<services>
-
<servicecomponentdescriptor>
-
<name>Construct DataPort</name>
-
<description>Raw data port: Connect via a socket and send N-TRIPLE RDF strings. Response string will be ok or error if it fails.</description>
-
<host>erdinger</host>
-
<port>3528</port>
-
<misc>See example applications.</misc>
-
</servicecomponentdescriptor>
-
<servicecomponentdescriptor>
-
<name>Construct QueryService</name>
-
<description>The query service: Connect via a socket and send SPARQL queries. Response string will be a SPARQL result set in RDF.</description>
-
<host>erdinger</host>
-
<port>3531</port>
-
<misc>See example applications.</misc>
-
</servicecomponentdescriptor>
-
</services>
This provides you with all the information required to open a connection to the data port or query service directly.
Working with the data port
Use the protocol described above. This is an example of adding a single line:
-
1000000000043<http://hello> <http://construct> "world" .
NOTE: The data RDF Triple must have the trailing full stop . Example responses might be:
-
1100000000003600(OK) -
1100000000003610(ERROR) -
1100000000003650(UNKNOWN)
Working with the query service
The point of contact for application developers to Construct is the Query Service. It takes a SPARQL query as an input. This query is run on the data store (a list of RDF triples). If the query is valid and answerable, a string of data will be returned. This section will try to help you write a SPARQL query, and make sense of the returned information.
Writing a SPARQL query
The presence of a query service implies that there must be something to query. The data in Construct is stored in the data store. All the data is represented in RDF triples. Here’s a few examples of these: For readability, we will replace the URIs with the prefixes “sighting:” and “person:”. NOTE: The prefixes in the query(below) is valid SPARQL syntax.
-
PREFIX: sighting:http://srg.ucd.ie/construct/sighting#
-
PREFIX: person:http://www.pervasive-ontologies.org/ontologies/context/person.owl#
-
<sighting:Waldo109> <sighting:person> <person:Waldo>
-
<sighting:Waldo109> <sighing:computer> <http://srg.cs.ucd.ie/construct/computer/waldo.ucd.ie>
-
<sighting:Waldo109> <sighting:time> <2006-10-04T13:17:59Z>
-
<sighitng:Waldo109> <sightingstatus> <Active>
These four statements represent a sighting from a computer activity sensor.
The Query
To retrieve information from construct, a query must be written in the SPARQL format. This has a similar “Select X From Y Where Z” form to an SQL query. Here is an example query which relates to the RDF Triples above. It finds all the times of sightings of Waldo(note the time triple above).
-
String personQuery = “PREFIX sighting:<http://srg.ucd.ie/construct/sighting#> “
-
+ “PREFIX user:<http://www.pervasive-ontologies.org/ontologies/context/person.owl#> “
-
+ “SELECT ?time “
-
+ “WHERE {”
-
+ “?sighting sighting:person user:Waldo . “
-
+ “?sighting sighting:status sighting:Active . “
-
+ “?sighting sighting:time ?time”
-
+ “}”;
For a more comprehensive tutorial on SPARQL, visit the website at: http://www.w3.org/TR/rdf-sparql-query/
In order to send a query to the query service we must use the protocol described above. Below is an example.
-
200[payload length][SPARQL QUERY]
The Response
You will be sent back a string of the form
-
210[payload length][SPARQL result set in RDF form] - OR
2100000000003610(if an error occured)
This String is a SPARQL ResultSet. This is a valid RDF string, represented in N-TRIPLE format. This means that way in which it is processed is dependent on the RDF parsing capabilities of the language used. For example, in java, a new Jena model (or indeed a ResultSet object) can be created from it, and it can be then easily traversed.
![[del.icio.us]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/email.png)
