Mercurial > repos > mikel-egana-aranguren > oppl
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:68935f90c2db | 6:3740505b579c |
---|---|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package es.upm.fi.dia.oeg.oppl.galaxy; | 18 package es.upm.fi.dia.oeg.oppl.galaxy; |
19 | 19 |
20 import java.io.BufferedOutputStream; | |
21 import java.io.BufferedWriter; | |
22 import java.io.File; | 20 import java.io.File; |
23 import java.io.FileNotFoundException; | 21 import java.io.FileNotFoundException; |
24 import java.io.FilterOutputStream; | |
25 import java.io.OutputStream; | |
26 import java.io.PipedOutputStream; | |
27 import java.io.PrintStream; | |
28 import java.util.ArrayList; | 22 import java.util.ArrayList; |
29 import java.util.List; | 23 import java.util.List; |
30 import java.util.Scanner; | 24 import java.util.Scanner; |
31 import java.util.logging.Level; | 25 import java.util.logging.Level; |
32 import java.util.logging.Logger; | 26 import java.util.logging.Logger; |
39 import org.coode.oppl.log.Logging; | 33 import org.coode.oppl.log.Logging; |
40 import org.coode.owlapi.obo.parser.OBOOntologyFormat; | 34 import org.coode.owlapi.obo.parser.OBOOntologyFormat; |
41 import org.coode.parsers.ErrorListener; | 35 import org.coode.parsers.ErrorListener; |
42 import org.coode.parsers.LoggerErrorListener; | 36 import org.coode.parsers.LoggerErrorListener; |
43 import org.semanticweb.owlapi.apibinding.OWLManager; | 37 import org.semanticweb.owlapi.apibinding.OWLManager; |
44 import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget; | |
45 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; | 38 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; |
46 import org.semanticweb.owlapi.io.SystemOutDocumentTarget; | 39 import org.semanticweb.owlapi.io.SystemOutDocumentTarget; |
47 import org.semanticweb.owlapi.model.IRI; | 40 import org.semanticweb.owlapi.model.IRI; |
48 import org.semanticweb.owlapi.model.OWLAxiom; | 41 import org.semanticweb.owlapi.model.OWLAxiom; |
49 import org.semanticweb.owlapi.model.OWLAxiomChange; | 42 import org.semanticweb.owlapi.model.OWLAxiomChange; |
61 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; | 54 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; |
62 import org.semanticweb.owlapi.util.SimpleIRIMapper; | 55 import org.semanticweb.owlapi.util.SimpleIRIMapper; |
63 | 56 |
64 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; | 57 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; |
65 | 58 |
59 import org.semanticweb.HermiT.Reasoner; | |
60 | |
66 /** | 61 /** |
67 * @author Mikel Egaña Aranguren | 62 * @author Mikel Egaña Aranguren |
68 */ | 63 */ |
69 public class Tool { | 64 public class Tool { |
70 | 65 |
78 String OWLFilePath = args [0]; | 73 String OWLFilePath = args [0]; |
79 String OPPL_script_file = args [1]; | 74 String OPPL_script_file = args [1]; |
80 String Output_format = args [2]; // OWL|OBO | 75 String Output_format = args [2]; // OWL|OBO |
81 String Add_inferred = args [3]; // Add_inferred|Whatever | 76 String Add_inferred = args [3]; // Add_inferred|Whatever |
82 String imports_file_path = args [4]; // Flat tab delimited file: URI Document URI | 77 String imports_file_path = args [4]; // Flat tab delimited file: URI Document URI |
78 String reasoner_type = args [5]; // Pellet|HermiT | |
83 | 79 |
84 // Load the main ontology | 80 // Load the main ontology |
85 File owl_file = new File(OWLFilePath); | 81 File owl_file = new File(OWLFilePath); |
86 OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | 82 OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); |
87 | 83 |
90 File imports_file = new File(imports_file_path); | 86 File imports_file = new File(imports_file_path); |
91 Scanner imports_input = new Scanner(imports_file); | 87 Scanner imports_input = new Scanner(imports_file); |
92 while(imports_input.hasNext()){ | 88 while(imports_input.hasNext()){ |
93 String nextLine = imports_input.nextLine(); | 89 String nextLine = imports_input.nextLine(); |
94 if(!nextLine.startsWith("#")){ | 90 if(!nextLine.startsWith("#")){ |
95 String [] URI_documentURI = nextLine.split("\t"); | 91 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]); | 92 IRI ontology_IRI = IRI.create(URI_documentURI[0]); |
101 IRI document_IRI = IRI.create("file://" + URI_documentURI[1]); | 93 IRI document_IRI = IRI.create("file://" + URI_documentURI[1]); |
102 OWLOntologyIRIMapper iriMapper = new SimpleIRIMapper(ontology_IRI,document_IRI); | 94 OWLOntologyIRIMapper iriMapper = new SimpleIRIMapper(ontology_IRI,document_IRI); |
103 manager.addIRIMapper(iriMapper); | 95 manager.addIRIMapper(iriMapper); |
104 } | 96 } |
107 } | 99 } |
108 OWLDataFactory factory = manager.getOWLDataFactory(); | 100 OWLDataFactory factory = manager.getOWLDataFactory(); |
109 OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); | 101 OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file); |
110 | 102 |
111 // Reasoner | 103 // Reasoner |
112 OWLReasonerFactory reasonerFactory = new PelletReasonerFactory(); | 104 OWLReasonerFactory reasonerFactory = null; |
113 OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology); | 105 OWLReasoner reasoner = null; |
114 reasoner.isConsistent(); | 106 if(reasoner_type.equals("Pellet")){ |
107 reasonerFactory = new PelletReasonerFactory(); | |
108 reasoner = reasonerFactory.createReasoner(OWL_ontology); | |
109 } | |
110 else{ | |
111 reasonerFactory = new Reasoner.ReasonerFactory(); | |
112 reasoner = reasonerFactory.createReasoner(OWL_ontology); | |
113 } | |
115 | 114 |
116 // Load the flat file with script in memory | 115 // Load the flat file with script in memory |
117 String OPPL_script_source = ""; | 116 String OPPL_script_source = ""; |
118 File file = new File(OPPL_script_file); | 117 File file = new File(OPPL_script_file); |
119 Scanner input = new Scanner(file); | 118 Scanner input = new Scanner(file); |
124 input.close(); | 123 input.close(); |
125 | 124 |
126 // Parse the OPPL script | 125 // Parse the OPPL script |
127 ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner); | 126 ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner); |
128 Logger logger = Logger.getLogger(Tool.class.getName()); | 127 Logger logger = Logger.getLogger(Tool.class.getName()); |
129 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy | 128 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy (Fixed in Galaxy by 2 > /dev/null) |
130 ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger); | 129 ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger); |
131 OPPLParser opplparser = parserFactory.build(errorListener); | 130 OPPLParser opplparser = parserFactory.build(errorListener); |
132 OPPLScript OPPLscript = opplparser.parse(OPPL_script_source); | 131 OPPLScript OPPLscript = opplparser.parse(OPPL_script_source); |
133 | 132 |
134 // Execute the script | 133 // Execute the script |
140 if(Add_inferred.equals("Add_inferred")){ | 139 if(Add_inferred.equals("Add_inferred")){ |
141 reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); | 140 reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); |
142 List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>(); | 141 List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>(); |
143 gens.add(new InferredSubClassAxiomGenerator()); | 142 gens.add(new InferredSubClassAxiomGenerator()); |
144 InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens); | 143 InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens); |
145 iog.fillOntology(manager, OWL_ontology); | 144 iog.fillOntology(manager, OWL_ontology); |
146 } | 145 } |
147 | 146 |
148 // Print the ontology to the standard output so other galaxy tools can operate on the output | 147 // Print the ontology to the standard output so other galaxy tools can operate on the output |
149 OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget(); | |
150 if(Output_format.equals("OBO")){ | 148 if(Output_format.equals("OBO")){ |
151 manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget()); | 149 manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget()); |
152 } | 150 } |
153 else{ | 151 else{ |
154 manager.saveOntology(OWL_ontology, new RDFXMLOntologyFormat(), new SystemOutDocumentTarget()); | 152 manager.saveOntology(OWL_ontology, new RDFXMLOntologyFormat(), new SystemOutDocumentTarget()); |