Mercurial > repos > mikel-egana-aranguren > oppl
comparison src/OWLQueryGalaxy.java @ 19:cc270db37d33 draft
Directories re-arranged
author | Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu> |
---|---|
date | Sat, 06 Oct 2012 21:50:39 +0200 |
parents | OPPL/src/OWLQueryGalaxy.java@d3616fac4ca5 |
children |
comparison
equal
deleted
inserted
replaced
18:d3616fac4ca5 | 19:cc270db37d33 |
---|---|
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|Elk | |
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 // Elk | |
45 else if (reasoner_type.equals("Elk")){ | |
46 galaxyowlapi.setReasonerElk(); | |
47 } | |
48 // HermiT | |
49 else{ | |
50 galaxyowlapi.setReasonerHermit(); | |
51 } | |
52 | |
53 // Parse the expression to an OWLexpression | |
54 OWLClassExpression class_expr = galaxyowlapi.parseMOSClassExpression(MOS_query); | |
55 | |
56 // Execute query and print results | |
57 if(Answer_type.equals("Individuals")){ | |
58 Set<OWLNamedIndividual> inds = galaxyowlapi.getIndividuals(class_expr); | |
59 galaxyowlapi.disposeReasoner(); | |
60 for(OWLNamedIndividual ind : inds){ | |
61 print_result_entity(ind.getIRI(), Answer_render); | |
62 } | |
63 } | |
64 else if (Answer_type.equals("EquivalentClasses")) { | |
65 Set<OWLClass> answer_classes = galaxyowlapi.getEquivalentClasses(class_expr); | |
66 galaxyowlapi.disposeReasoner(); | |
67 for(OWLClass cls : answer_classes){ | |
68 print_result_entity(cls.getIRI(), Answer_render); | |
69 } | |
70 } | |
71 else if (Answer_type.equals("DirectSuperClasses")) { | |
72 Set<OWLClass> answer_classes = galaxyowlapi.getDirectSuperClasses(class_expr); | |
73 galaxyowlapi.disposeReasoner(); | |
74 for(OWLClass cls : answer_classes){ | |
75 print_result_entity(cls.getIRI(), Answer_render); | |
76 } | |
77 } | |
78 else if (Answer_type.equals("Ancestors")) { | |
79 Set<OWLClass> answer_classes = galaxyowlapi.getAncestors(class_expr); | |
80 galaxyowlapi.disposeReasoner(); | |
81 for(OWLClass cls : answer_classes){ | |
82 print_result_entity(cls.getIRI(), Answer_render); | |
83 } | |
84 } | |
85 else if (Answer_type.equals("DirectSubClasses")) { | |
86 Set<OWLClass> answer_classes = galaxyowlapi.getDirectSubClasses(class_expr); | |
87 galaxyowlapi.disposeReasoner(); | |
88 for(OWLClass cls : answer_classes){ | |
89 print_result_entity(cls.getIRI(), Answer_render); | |
90 } | |
91 } | |
92 // Descendants | |
93 else { | |
94 Set<OWLClass> answer_classes = galaxyowlapi.getDescendants(class_expr); | |
95 galaxyowlapi.disposeReasoner(); | |
96 for(OWLClass cls : answer_classes){ | |
97 print_result_entity(cls.getIRI(), Answer_render); | |
98 } | |
99 } | |
100 } | |
101 | |
102 //URI|URIfragment|URIfragment2OBO | |
103 private static void print_result_entity (IRI iri, String Answer_render){ | |
104 if(Answer_render.equals("URI")){ | |
105 System.out.println(iri); | |
106 } | |
107 | |
108 // Weird bug: in eclipse it can print out the IRIs of every entity, but in Galaxy it can't! | |
109 // done manually | |
110 else if(Answer_render.equals("URIfragment")){ | |
111 if(iri.toString().contains("#")){ | |
112 System.out.println(iri.getFragment()); | |
113 } | |
114 else{ | |
115 String [] iri_tokens = iri.toString().split("/"); | |
116 System.out.println(iri_tokens[iri_tokens.length-1]); | |
117 } | |
118 } | |
119 else{ | |
120 if(iri.toString().contains("#")){ | |
121 System.out.println((iri.getFragment()).replace("_", ":")); | |
122 } | |
123 else{ | |
124 String [] iri_tokens = iri.toString().split("/"); | |
125 System.out.println((iri_tokens[iri_tokens.length-1]).replace("_", ":")); | |
126 } | |
127 } | |
128 } | |
129 } |