@@ -0,0 +1,2044 @@
+package ontologyapi;%0A%0Aimport java.io.InputStream;%0A%0Aimport com.hp.hpl.jena.ontology.Individual;%0Aimport com.hp.hpl.jena.ontology.OntClass;%0Aimport com.hp.hpl.jena.ontology.OntModel;%0Aimport com.hp.hpl.jena.ontology.OntModelSpec;%0Aimport com.hp.hpl.jena.ontology.OntResource;%0Aimport com.hp.hpl.jena.rdf.model.ModelFactory;%0Aimport com.hp.hpl.jena.rdf.model.ResIterator;%0Aimport com.hp.hpl.jena.rdf.model.Resource;%0Aimport com.hp.hpl.jena.util.FileManager;%0Aimport com.hp.hpl.jena.util.iterator.ExtendedIterator;%0Aimport com.hp.hpl.jena.vocabulary.VCARD;%0A%0A/**%0A * Task 07: Querying ontologies (RDFs)%0A * @author elozano%0A *%0A */%0Apublic class Task07%0A%7B%0A%09public static String ns = %22http://somewhere#%22;%0A%09%0A%09public static void main(String args%5B%5D)%0A%09%7B%0A%09%09String filename = %22example6.rdf%22;%0A%09%09%0A%09%09// Create an empty model%0A%09%09OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);%0A%09%09%0A%09%09// Use the FileManager to find the input file%0A%09%09InputStream in = FileManager.get().open(filename);%0A%09%0A%09%09if (in == null)%0A%09%09%09throw new IllegalArgumentException(%22File: %22+filename+%22 not found%22);%0A%09%0A%09%09// Read the RDF/XML file%0A%09%09model.read(in, null);%0A%09%09%0A%09%09%0A%09%09// ** TASK 7.1: List all individuals of %22Person%22 **%0A%09%09System.out.println(%22TASK 7.1%22);%0A%09%09%0A%09%09%0A%09%09OntClass person = model.getOntClass(ns + %22Person%22);%0A%09%09ExtendedIterator%3C? extends OntResource%3E eIter = person.listInstances();%0A%09%09%09%09%0A%09%09while (eIter.hasNext()) %0A%09%09%7B%0A%09%09%09Individual i = (Individual) eIter.next();%0A%09%09%09System.out.println(%22Individual: %22 +i);%0A%09%09%7D%0A%09%09%0A%09%09System.out.println(%22%22);%0A%09%09%0A%09%09%0A%09%09%0A%09%09// ** TASK 7.2: List all subclasses of %22Person%22 **%0A%09%09System.out.println(%22TASK 7.2%22);%0A%09%09OntClass person2 = model.getOntClass(ns + %22Person%22);%0A%09%09ExtendedIterator%3COntClass%3E eIter2=person.listSubClasses();%0A%09%09%0A%09%09while (eIter2.hasNext()) %0A%09%09%7B%0A%09%09%09Resource s = eIter2.next();%0A%09%09%09System.out.println(%22Subclass: %22 +s);%0A%09%09%7D%0A%09%09%09%09%0A%09%09System.out.println(%22%22);%0A%09%09%0A%09%09%0A%09%09%0A%09%09// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **%0A%09%09System.out.println(%22TASK 7.3%22);%0A%09%09//no yet%0A%09%7D%0A%7D%0A

Task 7