annotate OPPL/src/OPPLQueryGalaxy.java @ 16:6c25e717c896 draft

Source for OPPL query fixed
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Thu, 02 Aug 2012 09:22:57 +0200
parents 622cde484f4c
children d3616fac4ca5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
45 String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|HermiT
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 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
78 // HermiT
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
79 else{
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
80 galaxyowlapi.setReasonerHermit();
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
81 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
82
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
83 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
84 // 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
85
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 Set<BindingNode> nodes = cs.getLeaves();
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
96
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
110 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
111 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
112
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
113 //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
114 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
115 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
116 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
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 // 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
120 // done manually
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
121 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
122 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
123 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
124 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
125 else{
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
126 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
127 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
128 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
129 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
130 else{
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
131 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
132 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
133 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
134 else{
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
135 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
136 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
137 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
138 }
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
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
141 // 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
142 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
143
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
144 // 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
145 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
146 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
147 m.find();
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
148 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
149 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
150 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
151 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
152 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
153 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
154 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
155 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
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("DATAPROPERTY")){
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 ?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
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("ANNOTATIONPROPERTY")){
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 ?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
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("CONSTANT")){
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{
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
167 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
168 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
169 return OPPLQuery;
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
170 }
622cde484f4c Add new tool to perform OPPL queries
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
171 }