annotate 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
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.BufferedOutputStream;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
21 import java.io.BufferedWriter;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
22 import java.io.File;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
23 import java.io.FileNotFoundException;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
24 import java.io.FilterOutputStream;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
25 import java.io.OutputStream;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
26 import java.io.PipedOutputStream;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
27 import java.io.PrintStream;
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
28 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
29 import java.util.List;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
30 import java.util.Scanner;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
31 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
32 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
33
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
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.io.RDFXMLOntologyFormat;
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
64 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
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 * @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
68 */
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
69 public class Tool {
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
70
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
71 /**
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
72 * @throws FileNotFoundException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
73 * @throws OWLOntologyCreationException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
74 * @throws OWLOntologyStorageException
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
75 */
5
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
76 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
77 // 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
78 String OWLFilePath = args [0];
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
79 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
80 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
81 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
82 String imports_file_path = args [4]; // Flat tab delimited file: URI Document URI
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 main ontology
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
85 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
86 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
87
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
88 // 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
89 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
90 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
91 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
92 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
93 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
94 if(!nextLine.startsWith("#")){
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
95 String [] URI_documentURI = nextLine.split("\t");
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
96 // System.out.println(URI_documentURI[0]);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
97 // System.out.println(URI_documentURI[1]);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
98 // IRI ontology_IRI = IRI.create("http://purl.obolibrary.org/obo/CHEBI_ONTOLOGY_chebi_ontology");
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
99 // IRI document_IRI = IRI.create("file://" + "/home/pik/UPM/OPPL_galaxy/SWAT4LS_2011/GONG/chebi.owl");
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
100 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
101 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
102 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
103 manager.addIRIMapper(iriMapper);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
104 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
105 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
106 imports_input.close();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
107 }
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
108 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
109 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
110
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
111 // Reasoner
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
112 OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
113 OWLReasoner reasoner = reasonerFactory.createReasoner(OWL_ontology);
68935f90c2db Added OWL imports closure
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents: 4
diff changeset
114 reasoner.isConsistent();
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
115
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
116 // 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
117 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
118 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
119 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
120 while(input.hasNext()) {
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
121 String nextToken = input.next();
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
122 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
123 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
124 input.close();
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
125
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
126 // Parse the OPPL script
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
127 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
128 Logger logger = Logger.getLogger(Tool.class.getName());
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
129 Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
130 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
131 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
132 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
133
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
134 // Execute the script
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
135 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
136 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
137 manager.applyChanges(changes);
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
138
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
139 // 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
140 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
141 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
142 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
143 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
144 InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
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 iog.fillOntology(manager, OWL_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
146 }
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
147
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
148 // Print the ontology to the standard output so other galaxy tools can operate on the output
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
149 OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget();
3
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
150 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
151 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
152 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
153 else{
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
154 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
155 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
156 }
5255f1333cc4 Version 1.0.1
Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
157 }