Search Strings in the Management Tool
As some people around the globe start working on the OpenNetinf code, there are already some results to report. Petteri Pöyhönen tried to get used to the search function in the management tool and couldn't find too much information about it in the documentation (as most of the search functionality was only used for the shopping scenario). This is a small report on what he found out.
First, I will shortly describe what the search component is doing. If we speak about resolution, we mean resolving from an Identifier to the actual Information Object. The resolution controller and its services are also responsible for storing Information Objects in the node. The search controller and its services are responsible for returning Identifiers from a given search query. It is important to note that, in order to get the actual Information Object, the client has to send another request with the Identifier he just received to the resolution controller.
The interesting thing now is, how these search queries are constructed. Only one of the two datamodels used in Netinf (RDF and Impl) are needed for this construction. If you look at an Information Object in RDF, you see triplets. We chose to use the XML Serialization of those RDF resources as transmission format. For example, a DataObject might look like this. For further information regarding RDF and triplets, please refer to Wikipedia.
There is a special query language for RDF, named SPARQL. In SPARQL, you can specify which information you want to retrieve from the RDF data that is queried. As a search service always returns Identifiers, a part of the query is already predefined in the search controller code. Whatever you send to the controller will be prepended by
SELECT ?id WHERE {?bNode <http://rdf.netinf.org/2009/netinf-rdf/1.0/#transportedIO> ?id.
The rest of the query has to use ?id as a variable name for the Information Object. An example for a query would be (thanks to Petteri Pöyhönen for finding it)
?id netinf:owner ?bNode2.
which returns any Information Object that has an owner. More complicated queries are possible, too. Petteri Pöyhönen describes them as follows:
Here is the test setup what we have used for doing simple tests for queries.
We created 2 new IOs where both had attribute named as "http://rdf.netinf.org/2009/netinf-rdf/1.0/#keywords".
For first IO, the value of this keywords attribute was "String:A B C D"
and for another "String:E D G"
Now, to search all IOs with the "default" owner named attribute, input the following string to the GUI;
?id netinf:owner ?bNode2.
To search all IOs that has string "D" in their keywords attribute value field, input to the GUI;
?id netinf:keywords ?bNode2. ?bNode2 netinf:attributeValue ?kw. FILTER(regex(str(?kw),"D")).
This results the list of two our new IO IDs having matching keywords attribute. Note: you can replace "bNode2" and "kw" with some other unique IDs/strings in the query; e.g.
?id netinf:keywords ?xyz. ?xyz netinf:attributeValue ?abc. FILTER(regex(str(?abc),"D")).
Note: I have not tried this but I believe it works like that unless there are some reserved words/strings that cannot be used as variable IDs/names, i.e. ID/name starting with ?.
The command "?id netinf:keywords ?bNode2. ?bNode2 netinf:attributeValue ?kw. FILTER(regex(str(?kw),"A"))." only returns the ID of the 1st IO and respectively "
?id netinf:keywords ?bNode2. ?bNode2 netinf:attributeValue ?kw. FILTER(regex(str(?kw),"G"))." returns the ID of the 2nd IO.
... and so on. The query is pretty straightforward to modify once you have the correct basic format/syntax.
Thanks again for that info and good luck and a lot of fun to everybody working with OpenNetinf!