Exemplo n.º 1
0
  public static void main(String args[]) {
    String filename = "example5.rdf";

    // Create an empty model
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);

    // Use the FileManager to find the input file
    InputStream in = FileManager.get().open(filename);

    if (in == null) throw new IllegalArgumentException("File: " + filename + " not found");

    // Read the RDF/XML file
    model.read(in, null);

    // Create a new class named "Researcher"
    OntClass researcher = model.createClass(ns + "Researcher");

    // ** TASK 6.1: Create a new class named "University" **
    OntClass university = model.createClass(ns + "University");

    // ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
    model.getOntClass(ns + "Person").addSubClass(researcher);

    // ** TASK 6.3: Create a new property named "worksIn" **
    Property worksIn = model.createProperty(ns + "worksIn");

    // ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
    Individual jane = researcher.createIndividual(ns + "JaneSmith");

    // ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
    jane.addProperty(VCARD.FN, "Jane Smith");
    jane.addProperty(VCARD.Given, "Jane");
    jane.addProperty(VCARD.Family, "Smith");

    // ** TASK 6.6: Add UPM as the university where John Smith works **
    Individual john = model.getIndividual(ns + "JohnSmith");
    Individual upm = university.createIndividual(ns + "UPM");
    john.addProperty(worksIn, upm);

    model.write(System.out, "RDF/XML-ABBREV");
  }