annotate src/OPPLQueryGalaxy.java @ 22:8d4bbaa99b4a draft

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