HOWTO - Query for TriplesAssertion Metadata

This document describes how to query for an entity by a piece of metadata that is in the form of TriplesAssertion.

TriplesAssertion

Grimoires supports attaching a metadata to an entity. A metadata has a metadata type, which dictates the type of this annotation, and a metadata value, which dictates the value of this annotation. For instance, a service can be attached with a metadata type/value pair (http://someNameSpace/QoS, 5) to state that this service has observed to have a quality of service at a value of 5.

Furthermore, three forms of metadata value are supported in Grimoires: string to describe some simple fact, URI to refer to some defined ontology concept, and TriplesAssertion to describe some complicated metadata. By using TriplesAssertion, we can attach a RDF graph that contains multiple RDF statements to an entity.

The XML schema for metadata value:

  <xsd:element name="metadataValue" type="meta:MetadataValue"/>
  <xsd:complexType name="MetadataValue">
    <xsd:choice>
      <xsd:element ref="meta:triplesAssertion"/>
      <xsd:element ref="meta:stringValue"/>
      <xsd:element ref="meta:uriValue"/>
    </xsd:choice>
  </xsd:complexType>
  
  <xsd:element name="stringValue" type="xsd:string"/>
  <xsd:element name="uriValue" type="xsd:anyURI"/>

  <xsd:element name="triplesAssertion" type="meta:TriplesAssertion"/>
  <xsd:complexType name="TriplesAssertion">
    <xsd:sequence>
      <xsd:element name="triples" type="xsd:string"/>
      <xsd:element name="resourceIdentifier" type="xsd:string"/>
      <xsd:element name="language" type="xsd:string"/>
      <xsd:element name="base" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>

In the TriplesAssertion structure, "triples" is the RDF graph encoded n a string. "language" is the format in which the RDF graph is encoded. Predefined values are "RDF/XML", "N-TRIPLE" and "N3".  "base" is used when converting relative URI's to absolute URI's in the RDF graph. The base URI may be null if there are no relative URIs to convert. A base URI of "" may permit relative URIs to be used in the model.

The usage of "resourceIdentifier" is as follows:

The metadata attachment looks like to set up a new RDF triple (annotatedEntity, hasMetadataType, metadataValue). Let's call it Triple M. The metadataValue in Triple M can be a  RDF resource if you attach a URI metadata or a triplesAssertion metadata. The triples assertion contains multiple RDF triples, which in fact is able to forms a RDF graph. If the triples assertion only forms a tree, we know the root of the tree must be the metadataValue in Triple M. However, when the triples assertion forms a graph, there is no way for us to tell which RDF resource should be the metadataValue in Triple M. Therefore, the "resourceIdentifier" is used to tell Grimoires which resource inside the triples assertion is used as the metadataValue in Triple M.

For instance, we have a service description for Grimoires, and we want to attach a metadata to say Grimoires has a developer called Weijian. We also want to annotate some information for Weijian, such as Weijian is a Research Fellow working in the school of ECS, while ECS is a part of Univ. of Southampton. By using TriplesAssertion, we can model this information in the following way:

We attach a TriplesAssertion metadata to the Grimoires service, the metadata type is http://someNameSpace/hasDeveloper. The metadata value is a TriplesAssertion. Its language is RDF/XML. Its base is omitted. its triples is

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:tns="http://someNameSpace/">
  <rdf:description rdf:about="tns:Weijian">
    <tns:worksIn rdf:nodeID="tns:ECS"/>
  </rdf:description>  
  <rdf:description rdf:about="tns:ECS">
    <tns:belongsTo rdf:nodeID="tns:SOTON"/>
  </rdf:description>
</rdf:RDF>  

Obviously, the resourceIdentifier of the above triplesAssertion is http://someNameSpace/Weijian.

RDF Query for TriplesAssertion

Grimoires provides a findEntityByMetadata operation, through which an entity can be found by specifying the metadata attached to it. In findEntityByMetadata, we need to specify the both the metadata type and metadata value. This works fine for the string metadata and the URI metadata. But more flexibility is required for the TriplesAssertion metadata. The motive is that since a RDF graph is provided as a metadata value, the user should be able to locate the metadata by only giving some pattern of the RDF graph instead of the whole graph. For instance, in the above triplesAssertion example, the user may want to find all services that are developed in Univ. of Southampton.

The solution is that a RDF query language is allowed to be used to describe the pattern of the TriplesAssertion when constructing the metadata value. More precisely, when constructing a TriplesAssertion which makes the metadata value, the language is set to be a RDF query language (currently, we only support RDQL), and the triples is a query segment in that language and describes the pattern of the triples. This query segment will then be incorporated into the findEntityByMetadata RDF query clause generated by Grimoires.

For instance, to find all services that are developed in Univ. of Southampton, the metadata looks like:

<meta:metadata meta:metadataKey="">
  <meta:metadataType>http://someNameSpace/hasDeveloper</meta:metadataType>
  <meta:metadataValue>
    <meta:triplesAssertion>
      <meta:triples>
        (?developer, <http://someNameSpace/worksIn>, ?school)
        (?school, <http://someNameSpace/belongsTo>, <http://someNameSpace/SOTON>)
      </meta:triples>
      <meta:resourceIdentifier>?developer</meta:resourceIdentifier>
      <meta:language>RDQL</meta:language>
    </meta:triplesAssertion>
  </meta:metadataValue>
</meta:metadata>

The "triples" in the "triplesAssertion" actually describes the RDF graph pattern in RDQL, with variables allowed. In the RDQL segment, the AND clause is allowed. Do not use the USING clause to define the name space prefix.