comparison OPPL/src/OWLQueryGalaxy.java @ 13:7e6604a5ee55

New query tool added
author Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Thu, 29 Mar 2012 14:49:22 +0200
parents
children d3616fac4ca5
comparison
equal deleted inserted replaced
12:d0722148cb59 13:7e6604a5ee55
1 package es.upm.fi.dia.oeg.oppl.galaxy;
2
3 import java.util.Set;
4
5 import org.semanticweb.owlapi.expression.ParserException;
6 import org.semanticweb.owlapi.model.IRI;
7 import org.semanticweb.owlapi.model.OWLClass;
8 import org.semanticweb.owlapi.model.OWLClassExpression;
9 import org.semanticweb.owlapi.model.OWLNamedIndividual;
10 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
11
12 public class OWLQueryGalaxy {
13
14 /**
15 * @param args
16 * @throws OWLOntologyCreationException
17 * @throws ParserException
18 */
19 public static void main(String[] args) throws OWLOntologyCreationException, ParserException {
20 // Get the arguments from command-line
21 String OWLFilePath = args [0]; // /home/pik/UPM/Paper/SWAT4LS_2011/JBS/Workflows_JBS/GO_module_transitive/go_no_trans.owl
22 String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|HermiT
23
24 String Answer_type = args [2]; // Individuals|EquivalentClasses|DirectSuperClasses|Ancestors|DirectSubClasses|Descendants
25 String Answer_render = args [3]; // URI|URIfragment|URIfragment2OBO
26 String MOS_query = args [4]; // GO_0007049 or part_of some GO_0007049
27
28 // Create the manager
29 GalaxyOWLAPI galaxyowlapi = new GalaxyOWLAPI();
30
31 // Load the main ontology and hope for the imported URIs to be resolvable
32 galaxyowlapi.loadMainOntology(OWLFilePath);
33
34 // Set the reasoner
35
36 // Pellet
37 if(reasoner_type.equals("Pellet")){
38 galaxyowlapi.setReasonerPellet();
39 }
40 // FaCTPlusPlus
41 else if (reasoner_type.equals("FaCTPlusPlus")){
42 galaxyowlapi.setReasonerFaCT();
43 }
44 // HermiT
45 else{
46 galaxyowlapi.setReasonerHermit();
47 }
48
49 // Parse the expression to an OWLexpression
50 OWLClassExpression class_expr = galaxyowlapi.parseMOSClassExpression(MOS_query);
51
52 // Execute query and print results
53 if(Answer_type.equals("Individuals")){
54 Set<OWLNamedIndividual> inds = galaxyowlapi.getIndividuals(class_expr);
55 for(OWLNamedIndividual ind : inds){
56 print_result_entity(ind.getIRI(), Answer_render);
57 }
58 }
59 else if (Answer_type.equals("EquivalentClasses")) {
60 Set<OWLClass> answer_classes = galaxyowlapi.getEquivalentClasses(class_expr);
61 for(OWLClass cls : answer_classes){
62 print_result_entity(cls.getIRI(), Answer_render);
63 }
64 }
65 else if (Answer_type.equals("DirectSuperClasses")) {
66 Set<OWLClass> answer_classes = galaxyowlapi.getDirectSuperClasses(class_expr);
67 for(OWLClass cls : answer_classes){
68 print_result_entity(cls.getIRI(), Answer_render);
69 }
70 }
71 else if (Answer_type.equals("Ancestors")) {
72 Set<OWLClass> answer_classes = galaxyowlapi.getAncestors(class_expr);
73 for(OWLClass cls : answer_classes){
74 print_result_entity(cls.getIRI(), Answer_render);
75 }
76 }
77 else if (Answer_type.equals("DirectSubClasses")) {
78 Set<OWLClass> answer_classes = galaxyowlapi.getDirectSubClasses(class_expr);
79 for(OWLClass cls : answer_classes){
80 print_result_entity(cls.getIRI(), Answer_render);
81 }
82 }
83 // Descendants
84 else {
85 Set<OWLClass> answer_classes = galaxyowlapi.getDescendants(class_expr);
86 for(OWLClass cls : answer_classes){
87 print_result_entity(cls.getIRI(), Answer_render);
88 }
89 }
90 }
91
92 //URI|URIfragment|URIfragment2OBO
93 private static void print_result_entity (IRI iri, String Answer_render){
94 if(Answer_render.equals("URI")){
95 System.out.println(iri);
96 }
97
98 // Weird bug: in eclipse it can print out the IRIs of every entity, but in Galaxy it can't!
99 // done manually
100 else if(Answer_render.equals("URIfragment")){
101 if(iri.toString().contains("#")){
102 System.out.println(iri.getFragment());
103 }
104 else{
105 String [] iri_tokens = iri.toString().split("/");
106 System.out.println(iri_tokens[iri_tokens.length-1]);
107 }
108 }
109 else{
110 if(iri.toString().contains("#")){
111 System.out.println((iri.getFragment()).replace("_", ":"));
112 }
113 else{
114 String [] iri_tokens = iri.toString().split("/");
115 System.out.println((iri_tokens[iri_tokens.length-1]).replace("_", ":"));
116 }
117 }
118 }
119 }