Mercurial > repos > mikel-egana-aranguren > oppl
annotate OPPL/src/OPPLQueryGalaxy.java @ 18:d3616fac4ca5 draft
Elk support added
author | Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu> |
---|---|
date | Thu, 20 Sep 2012 12:46:36 +0200 |
parents | 6c25e717c896 |
children |
rev | line source |
---|---|
15
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
1 /** |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
2 * |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
3 */ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
4 package es.upm.cbgp.opplquery.oppl.galaxy; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
5 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
6 import java.io.File; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
7 import java.io.FileNotFoundException; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
8 import java.util.Iterator; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
9 import java.util.Scanner; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
10 import java.util.Set; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
11 import java.util.logging.Logger; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
12 import java.util.regex.Matcher; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
13 import java.util.regex.Pattern; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
14 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
15 import org.semanticweb.owlapi.expression.ParserException; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
16 import org.semanticweb.owlapi.model.IRI; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
17 import org.semanticweb.owlapi.model.OWLObject; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
18 import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
19 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
20 import es.upm.fi.dia.oeg.oppl.galaxy.GalaxyOWLAPI; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
21 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
22 import org.coode.oppl.ChangeExtractor; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
23 import org.coode.oppl.ConstraintSystem; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
24 import org.coode.oppl.OPPLParser; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
25 import org.coode.oppl.OPPLScript; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
26 import org.coode.oppl.ParserFactory; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
27 import org.coode.parsers.ErrorListener; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
28 import org.coode.parsers.LoggerErrorListener; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
29 import org.coode.oppl.bindingtree.Assignment; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
30 import org.coode.oppl.bindingtree.BindingNode; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
31 import org.coode.oppl.exceptions.QuickFailRuntimeExceptionHandler; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
32 import org.coode.oppl.exceptions.RuntimeExceptionHandler; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
33 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
34 public class OPPLQueryGalaxy { |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
35 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
36 /** |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
37 * @param args |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
38 * @throws OWLOntologyCreationException |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
39 * @throws ParserException |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
40 * @throws FileNotFoundException |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
41 */ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
42 public static void main(String[] args) throws OWLOntologyCreationException, ParserException, FileNotFoundException { |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
43 // Get the arguments from command-line |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
44 String OWLFilePath = args [0]; // /home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/ontology/single/test.owl |
18
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
45 String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|HermiT|Elk |
15
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
46 String Answer_render = args [2]; // URI|URIfragment|URIfragment2OBO |
16
6c25e717c896
Source for OPPL query fixed
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
15
diff
changeset
|
47 String OPPL_script_source = args [3]; |
15
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
48 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
49 // String OPPL_script_file = args [3]; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
50 // File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query.oppl"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
51 // File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query_object_prop.oppl"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
52 // File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query_object_ind.oppl"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
53 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
54 // String OPPL_script_source = ""; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
55 // Scanner input = new Scanner(OPPL_script_file); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
56 // while(input.hasNext()) { |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
57 // String nextToken = input.next(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
58 // OPPL_script_source = OPPL_script_source + " " + nextToken; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
59 // } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
60 // input.close(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
61 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
62 // Create the manager |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
63 GalaxyOWLAPI galaxyowlapi = new GalaxyOWLAPI(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
64 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
65 // Load the main ontology and hope for the imported URIs to be resolvable |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
66 galaxyowlapi.loadMainOntology(OWLFilePath); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
67 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
68 // Set the reasoner |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
69 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
70 // Pellet |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
71 if(reasoner_type.equals("Pellet")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
72 galaxyowlapi.setReasonerPellet(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
73 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
74 // FaCTPlusPlus |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
75 else if (reasoner_type.equals("FaCTPlusPlus")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
76 galaxyowlapi.setReasonerFaCT(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
77 } |
18
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
78 // Elk |
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
79 else if (reasoner_type.equals("Elk")){ |
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
80 galaxyowlapi.setReasonerElk(); |
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
81 } |
15
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
82 // HermiT |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
83 else{ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
84 galaxyowlapi.setReasonerHermit(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
85 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
86 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
87 OPPL_script_source = completeOPPLScript(OPPL_script_source); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
88 // System.out.println(OPPL_script_source); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
89 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
90 ParserFactory parserFactory = new ParserFactory(galaxyowlapi.getOWLManager(), galaxyowlapi.getMainOntology(), galaxyowlapi.getReasoner()); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
91 Logger logger = Logger.getLogger(OPPLQueryGalaxy.class.getName()); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
92 ErrorListener errorListener = (ErrorListener) new LoggerErrorListener(logger); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
93 OPPLParser opplparser = parserFactory.build(errorListener); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
94 OPPLScript OPPLscript = opplparser.parse(OPPL_script_source); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
95 RuntimeExceptionHandler exceptionhandler = new QuickFailRuntimeExceptionHandler(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
96 ChangeExtractor extractor = new ChangeExtractor(exceptionhandler, true); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
97 extractor.visit(OPPLscript); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
98 ConstraintSystem cs = OPPLscript.getConstraintSystem(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
99 Set<BindingNode> nodes = cs.getLeaves(); |
18
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
100 |
d3616fac4ca5
Elk support added
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
16
diff
changeset
|
101 galaxyowlapi.disposeReasoner(); |
15
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
102 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
103 Iterator NodesIterator = nodes.iterator(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
104 while(NodesIterator.hasNext()){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
105 Set Assignments = ((BindingNode)NodesIterator.next()).getAssignments(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
106 Iterator AssignmentIterator = Assignments.iterator(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
107 while(AssignmentIterator.hasNext()){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
108 Assignment assignment = (Assignment)AssignmentIterator.next(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
109 System.out.print(assignment.getAssignedVariable().toString()); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
110 System.out.print("\t"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
111 String OWLObjectString = ((OWLObject)assignment.getAssignment()).toString(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
112 IRI entityIRI = IRI.create(OWLObjectString.substring(1,OWLObjectString.length()-1)); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
113 print_result_entity(entityIRI, Answer_render); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
114 System.out.print("\n"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
115 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
116 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
117 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
118 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
119 //URI|URIfragment|URIfragment2OBO |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
120 private static void print_result_entity (IRI iri, String Answer_render){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
121 if(Answer_render.equals("URI")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
122 System.out.print(iri); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
123 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
124 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
125 // Weird bug: in eclipse it can print out the IRIs of every entity, but in Galaxy it can't! |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
126 // done manually |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
127 else if(Answer_render.equals("URIfragment")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
128 if(iri.toString().contains("#")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
129 System.out.print(iri.getFragment()); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
130 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
131 else{ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
132 String [] iri_tokens = iri.toString().split("/"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
133 System.out.print(iri_tokens[iri_tokens.length-1]); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
134 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
135 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
136 else{ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
137 if(iri.toString().contains("#")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
138 System.out.print((iri.getFragment()).replace("_", ":")); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
139 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
140 else{ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
141 String [] iri_tokens = iri.toString().split("/"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
142 System.out.print((iri_tokens[iri_tokens.length-1]).replace("_", ":")); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
143 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
144 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
145 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
146 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
147 // Very crappy stuff: complete the query to make a whole OPPL script that can be parsed |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
148 private static String completeOPPLScript (String OPPLQuery){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
149 |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
150 // Get the first variable and add at least an axiom to make a whole script |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
151 Pattern p = Pattern.compile("(\\?\\w+):(CLASS|INDIVIDUAL|OBJECTPROPERTY|DATAPROPERTY|ANNOTATIONPROPERTY|CONSTANT)"); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
152 Matcher m = p.matcher(OPPLQuery); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
153 m.find(); |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
154 if (m.group(2).equals("CLASS")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
155 OPPLQuery = OPPLQuery + " BEGIN ADD " + m.group(1) + " SubClassOf !A END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
156 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
157 else if (m.group(2).equals("INDIVIDUAL")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
158 OPPLQuery = OPPLQuery + " BEGIN ADD " + m.group(1) + " !p !b END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
159 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
160 else if (m.group(2).equals("OBJECTPROPERTY")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
161 OPPLQuery = OPPLQuery + " BEGIN ADD Transitive ?p END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
162 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
163 // else if (m.group(2).equals("DATAPROPERTY")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
164 // OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
165 // } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
166 // else if (m.group(2).equals("ANNOTATIONPROPERTY")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
167 // OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
168 // } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
169 // else if (m.group(2).equals("CONSTANT")){ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
170 // OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
171 // } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
172 else{ |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
173 OPPLQuery = "Malformed OPPL query"; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
174 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
175 return OPPLQuery; |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
176 } |
622cde484f4c
Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff
changeset
|
177 } |