comparison OPPL/Tool.java @ 4:4f60202c58d9

Added option to push inferred subsumption axioms into output ontology
author Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Wed, 14 Sep 2011 19:52:06 +0200
parents 5255f1333cc4
children 68935f90c2db
comparison
equal deleted inserted replaced
3:5255f1333cc4 4:4f60202c58d9
23 import java.io.FileNotFoundException; 23 import java.io.FileNotFoundException;
24 import java.io.FilterOutputStream; 24 import java.io.FilterOutputStream;
25 import java.io.OutputStream; 25 import java.io.OutputStream;
26 import java.io.PipedOutputStream; 26 import java.io.PipedOutputStream;
27 import java.io.PrintStream; 27 import java.io.PrintStream;
28 import java.util.ArrayList;
28 import java.util.List; 29 import java.util.List;
29 import java.util.Scanner; 30 import java.util.Scanner;
30 import java.util.logging.Level; 31 import java.util.logging.Level;
31 import java.util.logging.Logger; 32 import java.util.logging.Logger;
32 33
42 import org.semanticweb.owlapi.apibinding.OWLManager; 43 import org.semanticweb.owlapi.apibinding.OWLManager;
43 import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget; 44 import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
44 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; 45 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
45 import org.semanticweb.owlapi.io.SystemOutDocumentTarget; 46 import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
46 import org.semanticweb.owlapi.model.IRI; 47 import org.semanticweb.owlapi.model.IRI;
48 import org.semanticweb.owlapi.model.OWLAxiom;
47 import org.semanticweb.owlapi.model.OWLAxiomChange; 49 import org.semanticweb.owlapi.model.OWLAxiomChange;
48 import org.semanticweb.owlapi.model.OWLOntology; 50 import org.semanticweb.owlapi.model.OWLOntology;
49 import org.semanticweb.owlapi.model.OWLOntologyCreationException; 51 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
50 import org.semanticweb.owlapi.model.OWLOntologyManager; 52 import org.semanticweb.owlapi.model.OWLOntologyManager;
51 import org.semanticweb.owlapi.model.OWLOntologyStorageException; 53 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
54 import org.semanticweb.owlapi.reasoner.InferenceType;
52 import org.semanticweb.owlapi.reasoner.OWLReasoner; 55 import org.semanticweb.owlapi.reasoner.OWLReasoner;
53 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; 56 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
57 import org.semanticweb.owlapi.util.InferredAxiomGenerator;
58 import org.semanticweb.owlapi.util.InferredOntologyGenerator;
59 import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator;
54 60
55 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; 61 import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
56 62
57 63
58 /** 64 /**
72 78
73 // Get the arguments from command-line 79 // Get the arguments from command-line
74 String OWLFilePath = args [0]; 80 String OWLFilePath = args [0];
75 String OPPL_script_file = args [1]; 81 String OPPL_script_file = args [1];
76 String Output_format = args [2]; 82 String Output_format = args [2];
83 String Add_inferred = args [3];
77 String OPPL_script_source = ""; 84 String OPPL_script_source = "";
78 85
79 // Load the flat file with script in memory 86 // Load the flat file with script in memory
80 File file = new File(OPPL_script_file); 87 File file = new File(OPPL_script_file);
81 Scanner input = new Scanner(file); 88 Scanner input = new Scanner(file);
105 // Execute the script 112 // Execute the script
106 ChangeExtractor extractor = new ChangeExtractor(new QuickFailRuntimeExceptionHandler(), true); 113 ChangeExtractor extractor = new ChangeExtractor(new QuickFailRuntimeExceptionHandler(), true);
107 List<OWLAxiomChange> changes = extractor.visit(OPPLscript); 114 List<OWLAxiomChange> changes = extractor.visit(OPPLscript);
108 manager.applyChanges(changes); 115 manager.applyChanges(changes);
109 116
117 // Add the inferred axioms as asserted axioms to the original ontology
118 if(Add_inferred.equals("Add_inferred")){
119 reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
120 List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
121 gens.add(new InferredSubClassAxiomGenerator());
122 InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
123 iog.fillOntology(manager, OWL_ontology);
124 }
125
110 // Print the ontology to the standard output so other galaxy tools can operate on the output 126 // Print the ontology to the standard output so other galaxy tools can operate on the output
111 OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget(); 127 OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget();
112
113 if(Output_format.equals("OBO")){ 128 if(Output_format.equals("OBO")){
114 manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget()); 129 manager.saveOntology(OWL_ontology, new OBOOntologyFormat(), new SystemOutDocumentTarget());
115 } 130 }
116 else{ 131 else{
117 manager.saveOntology(OWL_ontology, new RDFXMLOntologyFormat(), new SystemOutDocumentTarget()); 132 manager.saveOntology(OWL_ontology, new RDFXMLOntologyFormat(), new SystemOutDocumentTarget());
118 } 133 }
119
120 } 134 }
121 } 135 }