diff OPPL/Tool.java @ 6:3740505b579c

Added reasoner option: Pellet or HermiT
author Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Sun, 18 Sep 2011 12:35:18 +0200
parents 68935f90c2db
children 756f1f5798bf
line wrap: on
line diff
--- a/OPPL/Tool.java	Sat Sep 17 13:41:28 2011 +0200
+++ b/OPPL/Tool.java	Sun Sep 18 12:35:18 2011 +0200
@@ -17,14 +17,8 @@
 
 package es.upm.fi.dia.oeg.oppl.galaxy;
 
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FilterOutputStream;
-import java.io.OutputStream;
-import java.io.PipedOutputStream;
-import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
@@ -41,7 +35,6 @@
 import org.coode.parsers.ErrorListener;
 import org.coode.parsers.LoggerErrorListener;
 import org.semanticweb.owlapi.apibinding.OWLManager;
-import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
 import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
 import org.semanticweb.owlapi.model.IRI;
@@ -63,6 +56,8 @@
 
 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
 
+import org.semanticweb.HermiT.Reasoner;
+
 /**
  * @author Mikel EgaƱa Aranguren
  */
@@ -80,6 +75,7 @@
 		String Output_format = args [2]; // OWL|OBO
 		String Add_inferred = args [3]; // Add_inferred|Whatever
 		String imports_file_path = args [4]; // Flat tab delimited file: URI	Document URI
+		String reasoner_type = args [5]; // Pellet|HermiT
 		
 		// Load the main ontology		
 		File owl_file = new File(OWLFilePath);
@@ -92,11 +88,7 @@
 			while(imports_input.hasNext()){
 			    String nextLine = imports_input.nextLine();
 			    if(!nextLine.startsWith("#")){
-				    String [] URI_documentURI = nextLine.split("\t");
-		//		    System.out.println(URI_documentURI[0]);
-		//		    System.out.println(URI_documentURI[1]);
-		//			IRI ontology_IRI = IRI.create("http://purl.obolibrary.org/obo/CHEBI_ONTOLOGY_chebi_ontology");
-		//			IRI document_IRI = IRI.create("file://" + "/home/pik/UPM/OPPL_galaxy/SWAT4LS_2011/GONG/chebi.owl");		
+				    String [] URI_documentURI = nextLine.split("\t");	
 				    IRI ontology_IRI = IRI.create(URI_documentURI[0]);
 					IRI document_IRI = IRI.create("file://" + URI_documentURI[1]);	
 					OWLOntologyIRIMapper iriMapper = new SimpleIRIMapper(ontology_IRI,document_IRI);
@@ -109,9 +101,16 @@
 		OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file);
 		
 		// Reasoner
-		OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); 
-		OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology);
-		reasoner.isConsistent();
+		OWLReasonerFactory reasonerFactory = null;
+		OWLReasoner reasoner = null;
+		if(reasoner_type.equals("Pellet")){
+			reasonerFactory = new PelletReasonerFactory(); 
+			reasoner = reasonerFactory.createReasoner(OWL_ontology);
+		}
+		else{
+			reasonerFactory = new Reasoner.ReasonerFactory();
+			reasoner = reasonerFactory.createReasoner(OWL_ontology);
+		}
 		
 		// Load the flat file with script in memory
 		String OPPL_script_source = "";
@@ -126,7 +125,7 @@
 		// Parse the OPPL script
 		ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner); 
 		Logger logger = Logger.getLogger(Tool.class.getName());
-		Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy
+		Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy (Fixed in Galaxy by 2 > /dev/null)
 		ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger);
 		OPPLParser opplparser = parserFactory.build(errorListener);
 		OPPLScript OPPLscript = opplparser.parse(OPPL_script_source);
@@ -142,11 +141,10 @@
 			List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
 			gens.add(new InferredSubClassAxiomGenerator());
 			InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
-			iog.fillOntology(manager, OWL_ontology);
+			iog.fillOntology(manager, OWL_ontology);	
 		}
 
-		// Print the ontology to the standard output so other galaxy tools can operate on the output
-		OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget();	
+		// Print the ontology to the standard output so other galaxy tools can operate on the output	
 		if(Output_format.equals("OBO")){
 			manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget());
 		}