RDFReactor/FAQ

From semanticweb.org
Jump to: navigation, search

Frequently asked questions about RDFReactor

Contents

[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) {
     e.printStackTrace();
    }
   } 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++) {
    System.out.println(taskArray[i]_NepomukTask.getName());
   }
   // 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);
    _NepomukTask.setId(Integer.toString(aID));
    // save back model to file
    try {
     String outFileName = rdfStoreFileName;
     FileWriter writer = new FileWriter(outFileName);
     model.writeTo(writer, Syntax.RdfXml);
    } catch (IOException e) {
     e.printStackTrace();
    }
    // 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) {
   e.printStackTrace();
  }
 }
}

[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:Class
rdfs:Property
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
owl:minCardinality
owl:cardinality
owl:maxCardinality

In OWL mode,

owl:Class

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();
cal.setDate(myDate);
Personal tools
Namespaces

Variants
Actions
Navigation
services
Toolbox