RDFReactor/User Guide

From semanticweb.org
Jump to: navigation, search

back to RDFReactor.

[edit] Introduction to use RDFReactor

The easiest way is to generate Java classes from an RDFS ontology by simply calling a very short Java program from within eclipse. Here you see such a mini-application. It will load an RDF schema from ./data/schema.n3, and generate .java files in src/gen. The generated classes will all have the package declaration org.ontoware.myproject and the ontology will be interpreted as RDFS semantics. Automatically, however, OWL cardinality constraints will be used, if present. The true,true at the end of the method call means that build-ins are skipped. If you set this to false, you re-generate classes for e.g. rdf:Resource, which is redundant. The second true triggers whether rdf:type statements are automatically written to the model. If you create a new Person p with p = new Person( model, someURI ) then automatically the statement (someURI, rdf:type, :Person) will be added to the model.

package org.ontoware.rdfreactor.example;
import org.ontoware.rdf2go.Reasoning;
import org.ontoware.rdfreactor.generator.CodeGenerator;
public class GenerateSomething {
 
	public static void main(String[] args) throws Exception {
		// "./data/myschema.n3" - 
           // "src/gen" -
           // 
		CodeGenerator.generate("./data/myschema.n3", "src/gen",
				"org.ontoware.myproject", Reasoning.rdfs, true, true);
	}
}

[edit] Developer Workflow

Create API

  • Write or find an RDF Schema
  • Generate API
CodeGenerator.generate("./data/schema.n3", "./src", "org.ontoware.rdfreactor.example","rdfs", true, true);

Use API - Set up RDFReactor

// create an RDF2Go wrapper, e.g. around a Jena data model, which holds all data at runtime
Model m = ...

Use RDFReactor

Person p1 = new Person(m, "http://www.example.com/ns/2005/#person1");
Person p2 = new Person(m, "http://www.example.com/ns/2005/#person2");
Person p3 = new Person(m, "http://www.example.com/ns/2005/#person3");
p1.setName("Joe");
p1.addKnows(p2);
p1.addKnows(p3);
p2.setName("Jim");
p3.setName("Jon");
               
Person[] p1friends = p1.getAllKnows();
for (int i = 0; i < p1friends.length; i  ) {
 System.out.println(p1.getName() " knows " p1friends[i].getName() );
}

[edit] Usage in Maven2

Simply include

<dependency>
	<groupId>org.semweb4j</groupId>
	<artifactId>rdfreactor.runtime</artifactId>
	<version>4.7.0</version>
</dependency>
<dependency>
	<groupId>org.semweb4j</groupId>
	<artifactId>rdfreactor.generator</artifactId>
	<version>4.7.0</version>
</dependency>
<repositories>
       <repository>
         <id>semweb4j</id>
         <name>semweb4j repo</name>
         <url>http://mavenrepo.fzi.de/semweb4j.org/repo/</url>
       </repository>
</repositories>

into your pom.xml.

Personal tools
Namespaces

Variants
Actions
Navigation
services
Toolbox