annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
1 /**
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
2 * Copyright (C) 2011, Mikel Egaña Aranguren
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
3 *
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
4 * This program is free software: you can redistribute it and/or modify
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
7 * (at your option) any later version.
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
8 *
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
12 * GNU General Public License for more details.
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
13 *
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
16 */
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
17
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
18 package es.upm.fi.dia.oeg.oppl.galaxy;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
19
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
20 import java.io.File;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
21 import java.io.FileNotFoundException;
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
22 import java.util.ArrayList;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
23 import java.util.List;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
24 import java.util.Scanner;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
25 import java.util.logging.Level;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
26 import java.util.logging.Logger;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
27
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
28 import org.coode.oppl.ChangeExtractor;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
29 import org.coode.oppl.OPPLParser;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
30 import org.coode.oppl.OPPLScript;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
31 import org.coode.oppl.ParserFactory;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
32 import org.coode.oppl.exceptions.QuickFailRuntimeExceptionHandler;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
33 import org.coode.oppl.log.Logging;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
34 import org.coode.owlapi.obo.parser.OBOOntologyFormat;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
35 import org.coode.parsers.ErrorListener;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
36 import org.coode.parsers.LoggerErrorListener;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
37 import org.semanticweb.owlapi.apibinding.OWLManager;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
38 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
39 import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
40 import org.semanticweb.owlapi.model.IRI;
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
41 import org.semanticweb.owlapi.model.OWLAxiom;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
42 import org.semanticweb.owlapi.model.OWLAxiomChange;
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
43 import org.semanticweb.owlapi.model.OWLDataFactory;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
44 import org.semanticweb.owlapi.model.OWLOntology;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
45 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
46 import org.semanticweb.owlapi.model.OWLOntologyIRIMapper;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
47 import org.semanticweb.owlapi.model.OWLOntologyManager;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
48 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
49 import org.semanticweb.owlapi.reasoner.InferenceType;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
50 import org.semanticweb.owlapi.reasoner.OWLReasoner;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
51 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
52 import org.semanticweb.owlapi.util.InferredAxiomGenerator;
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
53 import org.semanticweb.owlapi.util.InferredOntologyGenerator;
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
54 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator;
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
55 import org.semanticweb.owlapi.util.SimpleIRIMapper;
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
56
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
57 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
58
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
59 import org.semanticweb.HermiT.Reasoner;
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
60
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
61 /**
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
62 * @author Mikel Egaña Aranguren
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
63 */
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
64 public class Tool {
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
65
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
66 /**
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
67 * @throws FileNotFoundException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
68 * @throws OWLOntologyCreationException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
69 * @throws OWLOntologyStorageException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
70 */
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
71 public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException {
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
72 // Get the arguments from command-line
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
73 String OWLFilePath = args [0];
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
74 String OPPL_script_file = args [1];
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
75 String Output_format = args [2]; // OWL|OBO
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
76 String Add_inferred = args [3]; // Add_inferred|Whatever
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
77 String imports_file_path = args [4]; // Flat tab delimited file: URI Document URI
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
78 String reasoner_type = args [5]; // Pellet|HermiT
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
79
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
80 // Load the main ontology
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
81 File owl_file = new File(OWLFilePath);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
82 OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
83
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
84 // Load the imports if any
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
85 if(!imports_file_path.equals("NoImports")){
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
86 File imports_file = new File(imports_file_path);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
87 Scanner imports_input = new Scanner(imports_file);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
88 while(imports_input.hasNext()){
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
89 String nextLine = imports_input.nextLine();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
90 if(!nextLine.startsWith("#")){
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
91 String [] URI_documentURI = nextLine.split("\t");
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
92 IRI ontology_IRI = IRI.create(URI_documentURI[0]);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
93 IRI document_IRI = IRI.create("file://" + URI_documentURI[1]);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
94 OWLOntologyIRIMapper iriMapper = new SimpleIRIMapper(ontology_IRI,document_IRI);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
95 manager.addIRIMapper(iriMapper);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
96 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
97 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
98 imports_input.close();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
99 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
100 OWLDataFactory factory = manager.getOWLDataFactory();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
101 OWLOntology OWL_ontology = manager.loadOntologyFromOntologyDocument(owl_file);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
102
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
103 // Reasoner
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
104 OWLReasonerFactory reasonerFactory = null;
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
105 OWLReasoner reasoner = null;
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
106 if(reasoner_type.equals("Pellet")){
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
107 reasonerFactory = new PelletReasonerFactory();
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
108 reasoner = reasonerFactory.createReasoner(OWL_ontology);
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
109 }
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
110 else{
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
111 reasonerFactory = new Reasoner.ReasonerFactory();
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
112 reasoner = reasonerFactory.createReasoner(OWL_ontology);
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
113 }
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
114
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
115 // Load the flat file with script in memory
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
116 String OPPL_script_source = "";
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
117 File file = new File(OPPL_script_file);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
118 Scanner input = new Scanner(file);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
119 while(input.hasNext()) {
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
120 String nextToken = input.next();
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
121 OPPL_script_source = OPPL_script_source + " " + nextToken;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
122 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
123 input.close();
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
124
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
125 // Parse the OPPL script
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
126 ParserFactory parserFactory = new ParserFactory(manager, OWL_ontology, reasoner);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
127 Logger logger = Logger.getLogger(Tool.class.getName());
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
128 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy (Fixed in Galaxy by 2 > /dev/null)
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
129 ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
130 OPPLParser opplparser = parserFactory.build(errorListener);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
131 OPPLScript OPPLscript = opplparser.parse(OPPL_script_source);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
132
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
133 // Execute the script
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
134 ChangeExtractor extractor = new ChangeExtractor(new QuickFailRuntimeExceptionHandler(), true);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
135 List<OWLAxiomChange> changes = extractor.visit(OPPLscript);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
136 manager.applyChanges(changes);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
137
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
138 // Add the inferred axioms as asserted axioms to the original ontology
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
139 if(Add_inferred.equals("Add_inferred")){
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
140 reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
141 List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
142 gens.add(new InferredSubClassAxiomGenerator());
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
143 InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
144 iog.fillOntology(manager, OWL_ontology);
4
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
145 }
4f60202c58d9 Added option to push inferred subsumption axioms into output ontology
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 3
diff changeset
146
6
3740505b579c Added reasoner option: Pellet or HermiT
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 5
diff changeset
147 // Print the ontology to the standard output so other galaxy tools can operate on the output
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
148 if(Output_format.equals("OBO")){
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
149 manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget());
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
150 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
151 else{
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
152 manager.saveOntology(OWL_ontology, new RDFXMLOntologyFormat(), new SystemOutDocumentTarget());
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
153 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
154 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
155 }