Mercurial > repos > mikel-egana-aranguren > oppl
comparison src/OPPLGalaxy.java @ 19:cc270db37d33 draft
Directories re-arranged
author | Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu> |
---|---|
date | Sat, 06 Oct 2012 21:50:39 +0200 |
parents | OPPL/src/OPPLGalaxy.java@d3616fac4ca5 |
children |
comparison
equal
deleted
inserted
replaced
18:d3616fac4ca5 | 19:cc270db37d33 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package es.upm.fi.dia.oeg.oppl.galaxy; | |
5 | |
6 import java.io.File; | |
7 import java.io.IOException; | |
8 import java.util.List; | |
9 import java.util.Scanner; | |
10 import java.util.logging.Level; | |
11 import java.util.logging.Logger; | |
12 | |
13 //import org.apache.log4j.Level; | |
14 import org.coode.oppl.ChangeExtractor; | |
15 import org.coode.oppl.OPPLParser; | |
16 import org.coode.oppl.OPPLScript; | |
17 import org.coode.oppl.ParserFactory; | |
18 import org.coode.oppl.exceptions.QuickFailRuntimeExceptionHandler; | |
19 import org.coode.oppl.log.Logging; | |
20 import org.coode.parsers.ErrorListener; | |
21 import org.coode.parsers.LoggerErrorListener; | |
22 import org.semanticweb.owlapi.model.OWLAxiomChange; | |
23 import org.semanticweb.owlapi.model.OWLOntology; | |
24 import org.semanticweb.owlapi.model.OWLOntologyCreationException; | |
25 import org.semanticweb.owlapi.model.OWLOntologyManager; | |
26 import org.semanticweb.owlapi.model.OWLOntologyStorageException; | |
27 import org.semanticweb.owlapi.reasoner.OWLReasoner; | |
28 | |
29 | |
30 | |
31 | |
32 /** | |
33 * @author Mikel Ega��a Aranguren | |
34 * | |
35 */ | |
36 public class OPPLGalaxy { | |
37 | |
38 /** | |
39 * @param args | |
40 * @throws OWLOntologyCreationException | |
41 * @throws OWLOntologyStorageException | |
42 * @throws IOException | |
43 */ | |
44 public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException, IOException { | |
45 // Get the arguments from command-line | |
46 String OWLFilePath = args [0]; | |
47 String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|Elk|HermiT | |
48 | |
49 String OPPL_script_file = args [2]; | |
50 String OWL = args [3]; // OWL|OBO | |
51 | |
52 // Create the manager | |
53 GalaxyOWLAPI galaxyowlapi = new GalaxyOWLAPI(); | |
54 | |
55 // Load the main ontology and hope for the imported URIs to be resolvable | |
56 galaxyowlapi.loadMainOntology(OWLFilePath); | |
57 | |
58 // Set the reasoner | |
59 | |
60 // Pellet | |
61 if(reasoner_type.equals("Pellet")){ | |
62 galaxyowlapi.setReasonerPellet(); | |
63 } | |
64 // FaCTPlusPlus | |
65 else if (reasoner_type.equals("FaCTPlusPlus")){ | |
66 galaxyowlapi.setReasonerFaCT(); | |
67 } | |
68 // Elk | |
69 else if (reasoner_type.equals("Elk")){ | |
70 galaxyowlapi.setReasonerElk(); | |
71 } | |
72 // HermiT | |
73 else{ | |
74 galaxyowlapi.setReasonerHermit(); | |
75 } | |
76 | |
77 // Load the OPPL flat file with script in memory | |
78 String OPPL_script_source = ""; | |
79 File file = new File(OPPL_script_file); | |
80 Scanner input = new Scanner(file); | |
81 while(input.hasNext()) { | |
82 String nextToken = input.next(); | |
83 OPPL_script_source = OPPL_script_source + " " + nextToken; | |
84 } | |
85 input.close(); | |
86 | |
87 OWLOntologyManager manager = galaxyowlapi.getOWLManager(); | |
88 OWLOntology ontology = galaxyowlapi.getMainOntology(); | |
89 OWLReasoner reasoner = galaxyowlapi.getReasoner(); | |
90 | |
91 // Parse the OPPL script | |
92 ParserFactory parserFactory = new ParserFactory(manager, ontology, reasoner); | |
93 Logger logger = Logger.getLogger(OPPLGalaxy.class.getName()); | |
94 // logger.setLevel(Level.OFF); | |
95 // Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy (Fixed in Galaxy by 2 > /dev/null) | |
96 | |
97 ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger); | |
98 OPPLParser opplparser = parserFactory.build(errorListener); | |
99 OPPLScript OPPLscript = opplparser.parse(OPPL_script_source); | |
100 | |
101 // Execute the script | |
102 ChangeExtractor extractor = new ChangeExtractor(new QuickFailRuntimeExceptionHandler(), true); | |
103 List<OWLAxiomChange> changes = extractor.visit(OPPLscript); | |
104 manager.applyChanges(changes); | |
105 | |
106 galaxyowlapi.disposeReasoner(); | |
107 | |
108 // Merge imported ontologies if requested | |
109 // if(merge.equals("Merge")){ | |
110 // galaxyowlapi.merge(); | |
111 // } | |
112 | |
113 // Save the ontology | |
114 if(OWL.equals("OWL")){ | |
115 galaxyowlapi.saveOntology(true); | |
116 } | |
117 else{ | |
118 galaxyowlapi.saveOntology(false); | |
119 } | |
120 } | |
121 } |