Mercurial > repos > mikel-egana-aranguren > oppl
diff OPPL/Tool.java @ 5:68935f90c2db
Added OWL imports closure
author | Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu> |
---|---|
date | Sat, 17 Sep 2011 13:41:28 +0200 |
parents | 4f60202c58d9 |
children | 3740505b579c |
line wrap: on
line diff
--- a/OPPL/Tool.java Wed Sep 14 19:52:06 2011 +0200 +++ b/OPPL/Tool.java Sat Sep 17 13:41:28 2011 +0200 @@ -47,8 +47,10 @@ import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLAxiomChange; +import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyIRIMapper; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; @@ -57,33 +59,62 @@ import org.semanticweb.owlapi.util.InferredAxiomGenerator; import org.semanticweb.owlapi.util.InferredOntologyGenerator; import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; +import org.semanticweb.owlapi.util.SimpleIRIMapper; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; - /** * @author Mikel EgaƱa Aranguren - * */ public class Tool { /** - * @param OWL file - * @param OPPL script * @throws FileNotFoundException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException */ - public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { - + public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { // Get the arguments from command-line String OWLFilePath = args [0]; String OPPL_script_file = args [1]; - String Output_format = args [2]; - String Add_inferred = args [3]; - String OPPL_script_source = ""; + 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 + + // Load the main ontology + File owl_file = new File(OWLFilePath); + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // Load the imports if any + if(!imports_file_path.equals("NoImports")){ + File imports_file = new File(imports_file_path); + Scanner imports_input = new Scanner(imports_file); + 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"); + 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); + manager.addIRIMapper(iriMapper); + } + } + imports_input.close(); + } + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); + + // Reasoner + OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); + OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology); + reasoner.isConsistent(); // Load the flat file with script in memory + String OPPL_script_source = ""; File file = new File(OPPL_script_file); Scanner input = new Scanner(file); while(input.hasNext()) { @@ -91,15 +122,6 @@ OPPL_script_source = OPPL_script_source + " " + nextToken; } input.close(); - - // Load the OWL ontology - File owl_file = new File(OWLFilePath); - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); - - // Sync reasoner and check consistency - OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); - OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology); // Parse the OPPL script ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner);