package ontologyapi;

import java.io.InputStream;
import java.util.Iterator;
import java.util.List;

import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.sparql.function.library.e;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

/**
 * Task 07: Querying ontologies (RDFs)
 * @author Isaac Olguin
 *
 */
public class Task07
{
	public static String ns = "http://somewhere#";
	
	public static void main(String args[])
	{
		String filename = "example6.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);
		
		
		// ** TASK 7.1: List all individuals of "Person" **
		System.out.println("\n\n----------TASK 7.1");
		OntClass person = model.createClass(ns + "Person");
		ExtendedIterator<Individual> extIter = model.listIndividuals();
		while(extIter.hasNext())
		{
			Individual ind = (Individual)extIter.next();
			System.out.println(ind.getURI() + " - " +ind.getLocalName());
		}
		
		
		// ** TASK 7.2: List all subclasses of "Person" **
		System.out.println("\n\n----------TASK 7.2");
		Iterator iter = person.listSubClasses();
		while(iter.hasNext())
		{
			OntClass subClase = (OntClass)iter.next(); 
			System.out.println(subClase.getURI() + " - " + subClase.getLocalName());
		}	
		
		
		// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
		System.out.println("\n\n----------TASK 7.3");
		/*String inferenciaString = "[(?p rdfs:subClassOf ?o) -> ...]";
		List<Rule> rules = Rule.parseRules(inferenciaString);
		Reasoner reasoner = new GenericRuleReasoner(rules);	*/
		//inconcluso
	}
}

@@ -2080,251 +2080,928 @@
 %0D%0A%09%09
-System.out.println(%22%5Cn%5Cn----------TASK 7.3%22);%0D%0A%09%09/*String inferenciaString = %22%5B(?p rdfs:subClassOf ?o) -%3E ...%5D%22;%0D%0A%09%09List%3CRule%3E rules = Rule.parseRules(inferenciaString);%0D%0A%09%09Reasoner reason
+/*%0D%0A%09%09We can write some lines, and try to codify the inference. But another idea, is to change from %0D%0A%09%09ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);%0D%0A%09%09TO%0D%0A%09%09ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF);%0D%0A%09%09I repeat some lines cause' I'd like to see the differences with the 2 Ontology Model Specifications%0D%0A%09%09*/%0D%0A%09%09System.out.println(%22%5Cn%5Cn----------TASK 7.3%22);%0D%0A%09%09OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF);%0D%0A%09%09InputStream in2 = FileManager.get().open(filename);%09%0D%0A%09%09if (in2 == null)%0D%0A%09%09%09throw new IllegalArgumentException(%22File: %22+filename+%22 not found%22);%0D%0A%09%09model2.read(in2, null);%0D%0A%09%09OntClass person2 = model2.createClass(ns + %22Person%22);%0D%0A%09%09Iterator it
 er
+2
  = 
-new GenericRuleReasoner(rules);%09*/%0D%0A%09%09//inconcluso
+person2.listSubClasses();%0D%0A%09%09while(iter2.hasNext())%0D%0A%09%09%7B%0D%0A%09%09%09OntClass subClase = (OntClass)iter2.next(); %0D%0A%09%09%09System.out.println(subClase.getURI() + %22 - %22 + subClase.getLocalName());%0D%0A%09%09%7D
 %0D%0A%09%7D

Changes to the task 7.3