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