From semanticweb.org
Jump to: navigation, search

Frequently asked questions about RDFReactor


[edit] If I have an RDF2Go model, how can I get a collection or iterator over all instances of a given type as a RDFReactor instances?

If you generated the class Person, then Person.getAllInstances( model ) gives you an array of Person back.

[edit] How does a complete example of RDFReactor (upon RDF2Go) look like?

The following method shows a process where a existing RDF file is read, existing Instances of type NepomukTask are retrieved and printed. Then 10 new Instances of NepomukTask are created, then the model is saved back to a RDF XML file.

public static void main(String[] args) {
  Random random = new Random();
  try {
   // create the RDF2GO Model
   Model model = new ModelFactoryImpl().createModel();
   String rdfStoreFileName = "RDF_XML_TripleStore.rdf";
   // if the File already exists, the existing triples are read and added to the model
   File rdfStoreFile = new File(rdfStoreFileName);
   if (rdfStoreFile.exists()) {
    try {
     FileReader reader = new FileReader(rdfStoreFile);
     model.readFrom(reader, Syntax.RdfXml);
    } catch (IOException e) {
   } else {
    // File will be created on save only
   // get references for all objects of a certain class, by calling a static method upon this class
   NepomukTask[] taskArray = NepomukTask.getAllInstances(model);
   // print all instances
   for (int i = 0; i < taskArray.length; i++) {
   // create 10 new instances
   for (int i = 0; i < 10; i++) {
    // create a new ID
    int aID = random.nextInt(100000);
    NepomukTask _NepomukTask = new NepomukTask(model,"http://ontologies.semanticdesktop.org/task#Task" + aID);
    _NepomukTask.setName("This is a further task." + i);
    // save back model to file
    try {
     String outFileName = rdfStoreFileName;
     FileWriter writer = new FileWriter(outFileName);
     model.writeTo(writer, Syntax.RdfXml);
    } catch (IOException e) {
    // close the model
    // model.close();
    // -NO!!! since there is more than one Thread, close would be performed before the data is added to the model, resulting in a NullPointerException of the RDF2GO model
  } catch (ModelException e) {

[edit] What does this warning mean: WARN [main] (ModelGenerator.java:488) - Property http://www.w3.org/2002/07/owl#inverseOf has no domain, so we ignore it

Properties with no domain specified are considered to belong to Thing, a generated superclass for all RDFReactor generated classes. Works only since RDFReactor 4.3.0.

[edit] Which syntax elements of RDF, RDFS and OWL are covered by the RDFReactor?

RDFReactor has built-in classes for all RDF, RDFS, OWL and XSD URIs. But for code generation only a subset is used to create the internal Java model.

RDFReactor uses the following vocabulary in RDFS semantics mode:

rdfs:label   - used to created class and property names in Java
rdfs:comment - copied to generated source 
rdfs:subClassOf  - for class hierarchy
rdfs:domain   - which classes have this property
rdfs:range    - which values are expected

In OWL mode,


is used. The OWL mode is less mature than the RDFS mode.

[edit] Calandar vs. Date

RDFReactor uses only java.util.Calendar (which has a timezone information) and does not work with java.util.Date. You can convert a Date into a Calendar like this:

Calendar cal = new GregorianCalendar();
Personal tools