Mercurial > repos > mikel-egana-aranguren > oppl
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:4f60202c58d9 | 5:68935f90c2db |
---|---|
45 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; | 45 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; |
46 import org.semanticweb.owlapi.io.SystemOutDocumentTarget; | 46 import org.semanticweb.owlapi.io.SystemOutDocumentTarget; |
47 import org.semanticweb.owlapi.model.IRI; | 47 import org.semanticweb.owlapi.model.IRI; |
48 import org.semanticweb.owlapi.model.OWLAxiom; | 48 import org.semanticweb.owlapi.model.OWLAxiom; |
49 import org.semanticweb.owlapi.model.OWLAxiomChange; | 49 import org.semanticweb.owlapi.model.OWLAxiomChange; |
50 import org.semanticweb.owlapi.model.OWLDataFactory; | |
50 import org.semanticweb.owlapi.model.OWLOntology; | 51 import org.semanticweb.owlapi.model.OWLOntology; |
51 import org.semanticweb.owlapi.model.OWLOntologyCreationException; | 52 import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
53 import org.semanticweb.owlapi.model.OWLOntologyIRIMapper; | |
52 import org.semanticweb.owlapi.model.OWLOntologyManager; | 54 import org.semanticweb.owlapi.model.OWLOntologyManager; |
53 import org.semanticweb.owlapi.model.OWLOntologyStorageException; | 55 import org.semanticweb.owlapi.model.OWLOntologyStorageException; |
54 import org.semanticweb.owlapi.reasoner.InferenceType; | 56 import org.semanticweb.owlapi.reasoner.InferenceType; |
55 import org.semanticweb.owlapi.reasoner.OWLReasoner; | 57 import org.semanticweb.owlapi.reasoner.OWLReasoner; |
56 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; | 58 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; |
57 import org.semanticweb.owlapi.util.InferredAxiomGenerator; | 59 import org.semanticweb.owlapi.util.InferredAxiomGenerator; |
58 import org.semanticweb.owlapi.util.InferredOntologyGenerator; | 60 import org.semanticweb.owlapi.util.InferredOntologyGenerator; |
59 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; | 61 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; |
62 import org.semanticweb.owlapi.util.SimpleIRIMapper; | |
60 | 63 |
61 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; | 64 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; |
62 | 65 |
63 | |
64 /** | 66 /** |
65 * @author Mikel Egaña Aranguren | 67 * @author Mikel Egaña Aranguren |
66 * | |
67 */ | 68 */ |
68 public class Tool { | 69 public class Tool { |
69 | 70 |
70 /** | 71 /** |
71 * @param OWL file | |
72 * @param OPPL script | |
73 * @throws FileNotFoundException | 72 * @throws FileNotFoundException |
74 * @throws OWLOntologyCreationException | 73 * @throws OWLOntologyCreationException |
75 * @throws OWLOntologyStorageException | 74 * @throws OWLOntologyStorageException |
76 */ | 75 */ |
77 public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { | 76 public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { |
78 | |
79 // Get the arguments from command-line | 77 // Get the arguments from command-line |
80 String OWLFilePath = args [0]; | 78 String OWLFilePath = args [0]; |
81 String OPPL_script_file = args [1]; | 79 String OPPL_script_file = args [1]; |
82 String Output_format = args [2]; | 80 String Output_format = args [2]; // OWL|OBO |
83 String Add_inferred = args [3]; | 81 String Add_inferred = args [3]; // Add_inferred|Whatever |
84 String OPPL_script_source = ""; | 82 String imports_file_path = args [4]; // Flat tab delimited file: URI Document URI |
83 | |
84 // Load the main ontology | |
85 File owl_file = new File(OWLFilePath); | |
86 OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | |
87 | |
88 // Load the imports if any | |
89 if(!imports_file_path.equals("NoImports")){ | |
90 File imports_file = new File(imports_file_path); | |
91 Scanner imports_input = new Scanner(imports_file); | |
92 while(imports_input.hasNext()){ | |
93 String nextLine = imports_input.nextLine(); | |
94 if(!nextLine.startsWith("#")){ | |
95 String [] URI_documentURI = nextLine.split("\t"); | |
96 // System.out.println(URI_documentURI[0]); | |
97 // System.out.println(URI_documentURI[1]); | |
98 // IRI ontology_IRI = IRI.create("http://purl.obolibrary.org/obo/CHEBI_ONTOLOGY_chebi_ontology"); | |
99 // IRI document_IRI = IRI.create("file://" + "/home/pik/UPM/OPPL_galaxy/SWAT4LS_2011/GONG/chebi.owl"); | |
100 IRI ontology_IRI = IRI.create(URI_documentURI[0]); | |
101 IRI document_IRI = IRI.create("file://" + URI_documentURI[1]); | |
102 OWLOntologyIRIMapper iriMapper = new SimpleIRIMapper(ontology_IRI,document_IRI); | |
103 manager.addIRIMapper(iriMapper); | |
104 } | |
105 } | |
106 imports_input.close(); | |
107 } | |
108 OWLDataFactory factory = manager.getOWLDataFactory(); | |
109 OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); | |
110 | |
111 // Reasoner | |
112 OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); | |
113 OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology); | |
114 reasoner.isConsistent(); | |
85 | 115 |
86 // Load the flat file with script in memory | 116 // Load the flat file with script in memory |
117 String OPPL_script_source = ""; | |
87 File file = new File(OPPL_script_file); | 118 File file = new File(OPPL_script_file); |
88 Scanner input = new Scanner(file); | 119 Scanner input = new Scanner(file); |
89 while(input.hasNext()) { | 120 while(input.hasNext()) { |
90 String nextToken = input.next(); | 121 String nextToken = input.next(); |
91 OPPL_script_source = OPPL_script_source + " " + nextToken; | 122 OPPL_script_source = OPPL_script_source + " " + nextToken; |
92 } | 123 } |
93 input.close(); | 124 input.close(); |
94 | |
95 // Load the OWL ontology | |
96 File owl_file = new File(OWLFilePath); | |
97 OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | |
98 OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); | |
99 | |
100 // Sync reasoner and check consistency | |
101 OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); | |
102 OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology); | |
103 | 125 |
104 // Parse the OPPL script | 126 // Parse the OPPL script |
105 ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner); | 127 ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner); |
106 Logger logger = Logger.getLogger(Tool.class.getName()); | 128 Logger logger = Logger.getLogger(Tool.class.getName()); |
107 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy | 129 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy |