Skip to content
m0mo edited this page Dec 13, 2011 · 1 revision

As mentioned prior, the ERP API supports RDFS and OWL constructs. Since they can be described by using RDF triples, it is possible to simply create a Statement object to define RDFS or OWL constructs. To increase efficiency, we provide predefined con- stants for namespaces and prefixes as well as for important URIs such as owl:Class, owl:subClass or rdfs:Comment.

As we presented prior, it is easy to add a statement to the model. We simply have to use the node and statement objects of the ERP API and create elements using the right URIs. For instance, code 5.11 illustrates the creation of a statement for describing an OWL class called Person.

<?php
       $s = new Statements(
		new BlankNode("Person"), 
		new Resource(RDF_TYPE), 
		new Resource(OWL_CLASS)
	);       
?>

If we add this statement to a model, we created our first OWL statement. As usual, other statements can simply refer to this statement. Code 5.12 illustrates, how we can simply define the sutdent of the previous example to be an instance of the Person class.

<?php
       $r = $model->newResource("e0625287")
		->addProperty(
			new Resource(RDF_TYPE), 
			new BlankNode("person)
		);
?>

Alike this example, we can also define RDFS and other OWL resources for the model. Using the same way as presented in code 5.12 it is also possible to define re- lationships such as rdfs:subClassOf (for example, the line $r->addProperty(new Re- source(RDFS_SUBCLASSOF), new BlankNode("animal")) defines the class person to be a sub-class of the animal class).

Further, since these constructs are creating using the statement-centric or resource- centric approach, they can be simply edited, removed or searched by using the same functions as normal statements or resources. For instance, the command $result = $model->search(NULL, NULL, OWL_CLASS); returns a list of all OWL classes. An example for editing a class is illustrated in code 5.13.

<?php
	require_once 'path/to/API.php';
	
	// create or load a model
	// define a statement, e.g., $oldStatement
        
	$oldClass = new Statements(
		new BlankNode("Person"), 
		new Resource(RDF_TYPE), 
		new Resource(OWL_CLASS)
	);    
	
	$newClass = new Statements(
		new BlankNode("PersonNew"), 
		new Resource(RDF_TYPE), 
		new Resource(OWL_CLASS)
	);     
                
        // modify statement
        $model->edit($oldClass, $newClass);
?>

Serializers such as Turtle or N-Triple, which simply use the URI strings for describ- ing a triple, have no problem to serialize statements as defined in code 5.14. Anyway, other serializers and parsers may need further adaptation. For instance, the RDF/XML serializer. By default, subject nodes are described using a rdf:Description XML node. An example of this serialization of the previously defined OWL class is illustrated in code 5.14.

<rdf:Description rdf:ID="person">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class">
</rdf:Description>

Even though the fragment in code 5.14 is a valid description of an OWL class, it is not what more experienced users are expecting. For the definition of an OWL class, experienced users expect output such as <owl:Class rdf:about="#person" />. Anyway, The RDF fragment of code 5.14 presents the the raw form of the RDF serialization into XML for such a statement. In terms of RDF’s information model, it expresses the same semantics as the compressed form <owl:Class rdf:about="#person" />. Therefore, the two code fragments are equivalent. However, <owl:Class rdf:about="#person" /> is considerably easier to read and tends to be the form most people come across when reading OWL. Therefore, we im- plemented a variable called $type that can be used to specify the name of the subject node for the RDF/XML serialization. For instance, using the constant OWL_CLASS, we can define the type of a subject $r by using the function $r->setType(OWL_CLASS). As expected, the default type is rdf:Description or, in terms of available constants, RDF_DESCRIPTION. If types are set correctly, it is possible to create a more defined serialization output. For example, by defining the type of the subject (using the com- mand $r->setType(OWL_CLASS)) we achieve a serialization of the form <owl:Class rdf:about="#person" />.

Anyway, we still consider this implementation as a "workaround". Future devel- opment for the ERP API will contain the implementation of special classes and ob- ject (for instance, an OWL class could be defined by using the code $c = new OWL- Class("person") to further ease the creation of OWL and RDFS constructs. Another idea how to refine the use of OWL and RDFS is to extend the API by a further RDF/XML serializer to provide both, the raw RDF output as well as a compressed output.

Clone this wiki locally