aboutsummaryrefslogtreecommitdiff
path: root/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-19 13:35:52 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-19 13:35:52 +0100
commit5d54af2638a53721b414a41356a93686a9616272 (patch)
treee28c64b1887e7e964661d12d96df5b09abd4d9ee /test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java
parentc7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 (diff)
downloadACQuA-5d54af2638a53721b414a41356a93686a9616272.tar.gz
ACQuA-5d54af2638a53721b414a41356a93686a9616272.zip
Backup before changes in MyQueryReasoner.
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java')
-rw-r--r--test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java310
1 files changed, 291 insertions, 19 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java
index 7d9b49c..274946d 100644
--- a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java
+++ b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java
@@ -1,46 +1,318 @@
1package uk.ac.ox.cs.pagoda.tester; 1package uk.ac.ox.cs.pagoda.tester;
2 2
3import uk.ac.ox.cs.pagoda.query.AnswerTuple;
4import uk.ac.ox.cs.pagoda.query.AnswerTuples;
3import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; 5import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner;
4import uk.ac.ox.cs.pagoda.util.Properties; 6import uk.ac.ox.cs.pagoda.util.Properties;
5import uk.ac.ox.cs.pagoda.util.Timer; 7import uk.ac.ox.cs.pagoda.util.Timer;
6import uk.ac.ox.cs.pagoda.util.Utility; 8import uk.ac.ox.cs.pagoda.util.Utility;
7 9
8// TODO clean it, or code another one 10import java.io.File;
11import java.io.FileNotFoundException;
12import java.io.IOException;
13import java.util.Scanner;
14
15@Deprecated
9public class PagodaTester { 16public class PagodaTester {
10 17
18 // public static final String onto_dir = "/media/RDFData/yzhou/";
19// public static final String onto_dir = "/users/yzhou/ontologies/";
20// public static final String onto_dir = "/home/scratch/yzhou/ontologies/";
21 public static final String onto_dir = "/home/alessandro/Big_files/Ontologies/";
22
23 public static final String fly = onto_dir + "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl";
24 public static final String fly_query = onto_dir + "fly/queries/fly.sparql";
25
26 public static final String test_tbox = onto_dir + "smallExampleFromAna/dummy.owl";
27 public static final String test_abox = onto_dir + "smallExampleFromAna/initialABox.ttl";
28 public static final String test_query = onto_dir + "smallExampleFromAna/queries.dlog";
29
30 public static final int lubm_number = 1;
31 public static final String lubm_tbox = onto_dir + "lubm/univ-bench.owl";
32 public static final String lubm_abox = onto_dir + "lubm/data/lubm" + lubm_number + ".ttl";
33 public static final String lubm_abox_copy = onto_dir + "lubm/data/lubm" + lubm_number + " (copy).ttl";
34 public static final String lubm_query = onto_dir + "lubm/queries/test.sparql";
35 public static final String lubm_query6 = onto_dir + "lubm/queries/test_q6.sparql";
36 public static final String lubm_query20 = onto_dir + "lubm/queries/test_q16.sparql";
37
38 public static final int uobm_number = 1;
39 public static final String uobm_tbox = onto_dir + "uobm/univ-bench-dl.owl";
40 public static final String uobm_abox = onto_dir + "uobm/data/uobm" + uobm_number + ".ttl";
41 public static final String uobm_query = onto_dir + "uobm/queries/test.sparql";
42 public static final String uobm_query_temp = onto_dir + "uobm/queries/temp.sparql";
43 public static final String uobm_query2 = onto_dir + "uobm/queries/standard_q2.sparql";
44 public static final String uobm_query9 = onto_dir + "uobm/queries/standard_q9.sparql";
45 public static final String uobm_query11 = onto_dir + "uobm/queries/standard_q11.sparql";
46 public static final String uobm_query12 = onto_dir + "uobm/queries/standard_q12.sparql";
47 public static final String uobm_query14 = onto_dir + "uobm/queries/standard_q14.sparql";
48 public static final String uobm_query15 = onto_dir + "uobm/queries/standard_q15.sparql";
49 public static final String uobm_query_multi = onto_dir + "uobm/queries/standard_multi.sparql";
50 public static final String uobm_generated_query1 = onto_dir + "uobm/queries/generated_q1.sparql";
51 public static final String uobm_query_group3 = onto_dir + "uobm/queries/standard_group3.sparql";
52
53 public static final String npd_tbox = onto_dir + "npd/npd-all-minus-datatype.owl";
54 // "npd/npd-all.owl";
55 // "npd-all-minus-datatype.owl";
56 public static final String npd_abox = onto_dir + "npd/data/npd-data-dump-minus-datatype-new.ttl";
57 // "npd/data/npd-data-dump-processed.ttl";
58 // "npd-data-dump-minus-datatype-old.ttl";
59 public static final String npd_query = onto_dir + "npd/queries/atomic.sparql";
60
61 public static final String npd_bench_tbox = onto_dir + "npd-benchmark/npd-v2-ql_a.owl";
62 // npd-all-minus-datatype.owl";
63 public static final String npd_bench_abox = onto_dir + "npd-benchmark/npd-v2-ql_a.ttl";
64 // npd-data-dump-minus-datatype-old.ttl";
65 public static final String npd_bench_query = onto_dir + "npd-benchmark/queries/all.sparql";
66
67 public static final String dbpedia_tbox = onto_dir + "dbpedia/integratedOntology-all-in-one-minus-datatype.owl";
68 public static final String dbpedia_abox = onto_dir + "dbpedia/data/dbpedia-minus-datatype-new.ttl";
69 public static final String dbpedia_query = onto_dir + "dbpedia/queries/atomic_ground.sparql";
70 public static final String dbpedia_query274 = onto_dir + "dbpedia/atomic_q274.sparql";
71
72 public static final String dbpedia_latest_tbox = onto_dir + "dbpedia/dbpedia_2014.owl";
73 public static final String travel_tbox = onto_dir + "dbpedia/travel.owl";
74 public static final String dbpedia_tbox_simple = onto_dir + "dbpedia/dbpedia_simple.owl";
75
76 public static final String bioModels_tbox = onto_dir + "biomodels/biomodels-21.owl";
77 public static final String bioModels_abox = onto_dir + "biomodels/data_processed_1.ttl";
78 public static final String bioModels_queries = onto_dir + "biomodels/queries/queries.sparql";
79
80 public static final String chembl_tbox = onto_dir + "bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl";
81 public static final String chembl_abox = onto_dir + "bio2rdf/chembl/graph sampling old/sample_100.nt";
82 public static final String chembl_queries = onto_dir + "bio2rdf/chembl/queries/problematic.sparql";
83 //"bio2rdf/chembl/queries/atomic_one_filtered.sparql"; //
84
85 public static final String reactome_tbox = onto_dir + "bio2rdf/reactome/biopax-level3-processed.owl";
86 public static final String reactome_abox = onto_dir + "bio2rdf/reactome/graph sampling old/sample.ttl";
87 //data/data.ttl"; //graph sampling old/reactome_sample_10.ttl"; //
88 public static final String reactome_queries = onto_dir + "bio2rdf/reactome/queries/atomic.sparql";
89
90 public static final String uniprot_tbox = onto_dir + "bio2rdf/uniprot/core-processed.owl";
91 public static final String uniprot_abox = onto_dir + "bio2rdf/uniprot/graph sampling/sample_1.nt";
92 public static final String uniprot_queries = onto_dir + "bio2rdf/uniprot/queries/atomic_one.sparql";
93
94 public static final String atlas_tbox = onto_dir + "bio2rdf/atlas/gxaterms.owl";
95 public static final String atlas_abox = onto_dir + "bio2rdf/atlas/graph sampling/sample_1.nt";
96 public static final String atlas_queries = onto_dir + "bio2rdf/atlas/queries/atomic_one.sparql";
97 QueryReasoner pagoda;
98
99 // private void printPredicatesWithGap() {
100// for (String p: ((MyQueryReasoner) pagoda).getPredicatesWithGap()) {
101// System.out.println(p);
102// }
103// }
104 Timer timer = new Timer();
105
106 public PagodaTester(QueryReasoner reasoner) {
107 pagoda = reasoner;
108 }
109
11 public static void main(String... args) { 110 public static void main(String... args) {
12// Properties properties = new Properties(PagodaTester.class. 111 if(args.length == 0) {
13// getClassLoader().getResource("uobm.properties").getPath()); 112// args = new String[] {test_tbox, test_abox, test_query};
14 Properties properties = new Properties(); 113// args = new String[] {lubm_tbox, lubm_abox, lubm_query};
15 114// args = new String[] {uobm_tbox, uobm_abox, uobm_query};
16 int index = 0; 115// args = new String[] {fly, "null", fly_query};
17 if (args.length > index) properties.setOntologyPath(args[index++]); 116// args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query};
18 if (args.length > index && (args[index].endsWith(".ttl") || args[index].endsWith(".nt"))) properties.setDataPath(args[index++]); 117// args = new String[] {travel_tbox, null, dbpedia_query274};
19 if (args.length > index && args[index].endsWith(".sparql")) properties.setQueryPath(args[index++]); 118 args = new String[]{fly, fly_query};
20 if (args.length > index && !args[index].startsWith("-")) properties.setAnswerPath(args[index++]); 119// args = new String[] {npd_tbox, npd_abox, npd_query};
21 if (args.length > index) properties.setToClassify(Boolean.parseBoolean(args[index++].substring(1))); 120// args = new String[] {npd_bench_tbox, npd_bench_abox, npd_bench_query};
22 if (args.length > index) properties.setToCallHermiT(Boolean.parseBoolean(args[index++].substring(1))); 121// args = new String[] {"../SemFacet/WebContent/WEB-INF/data/dbpedia.owl", "../SemFacet/WebContent/WEB-INF/data/dbpediaA.nt", null};
23 122// args = new String[] {"../core/WebContent/WEB-INF/data/fly.owl", "../core/WebContent/WEB-INF/data/fly-data.nt", null};
123// args = new String[] {"data/lubm/univ-bench.owl", "data/lubm/lubm1.ttl", "data/lubm/lubm.sparql", "lubm.ans"};
124// args = new String[] {"data/uobm/univ-bench-dl.owl", "data/uobm/uobm1.ttl", "data/uobm/uobm.sparql", "uobm.ans"};
125// args = new String[] {"data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", "data/fly/fly.sparql", "fly.ans"};
126// args = new String[] {bioModels_tbox, bioModels_abox, bioModels_queries};
127// args = new String[] {chembl_tbox, chembl_abox, chembl_queries};
128// args = new String[] {reactome_tbox, reactome_abox, reactome_queries};
129// args = new String[] {reactome_tbox, "/users/yzhou/temp/reactome_debug.ttl", onto_dir +"bio2rdf/reactome/queries/atomic_one_q65.sparql"};
130// args = new String[] {uniprot_tbox.replace(".owl", "-noDis.owl"), "/users/yzhou/temp/uniprot_debug/sample_1_string.nt", uniprot_queries};
131// args = new String[] {uniprot_tbox.replace(".owl", "-noDis.owl"), uniprot_abox, uniprot_queries};
132// args = new String[] {atlas_tbox, atlas_abox, atlas_queries};
133// args = new String[] {onto_dir + "test/unsatisfiable.owl", null, onto_dir + "test/unsatisfiable_queries.sparql"};
134// args = new String[] {onto_dir + "test/jair-example.owl", null, onto_dir + "test/jair-example_query.sparql"};
135// args[2] = args[2].replace(".sparql", "_all_pagoda.sparql");
136// args[2] = args[2].replace(".sparql", "_pellet.sparql");
137 }
138
139 Properties properties = new Properties("config/uobm.properties");
140
141 int index = 0;
142 if(args.length > index) properties.setOntologyPath(args[index++]);
143 if(args.length > index && (args[index].endsWith(".ttl") || args[index].endsWith(".nt")))
144 properties.setDataPath(args[index++]);
145 if(args.length > index && args[index].endsWith(".sparql")) properties.setQueryPath(args[index++]);
146 if(args.length > index && !args[index].startsWith("-")) properties.setAnswerPath(args[index++]);
147 if(args.length > index) properties.setToClassify(Boolean.parseBoolean(args[index++].substring(1)));
148 if(args.length > index) properties.setToCallHermiT(Boolean.parseBoolean(args[index++].substring(1)));
149
24 Utility.logInfo("Ontology file: " + properties.getOntologyPath()); 150 Utility.logInfo("Ontology file: " + properties.getOntologyPath());
25 Utility.logInfo("Data files: " + properties.getDataPath()); 151 Utility.logInfo("Data files: " + properties.getDataPath());
26 Utility.logInfo("Query files: " + properties.getQueryPath()); 152 Utility.logInfo("Query files: " + properties.getQueryPath());
27 Utility.logInfo("Answer file: " + properties.getAnswerPath()); 153 Utility.logInfo("Answer file: " + properties.getAnswerPath());
28 154
29 QueryReasoner pagoda = null; 155 QueryReasoner pagoda = null;
30 156
31 try { 157 try {
32 Timer t = new Timer(); 158 Timer t = new Timer();
33 pagoda = QueryReasoner.getInstance(properties); 159 pagoda = QueryReasoner.getInstance(properties);
34 if (pagoda == null) return; 160 if (pagoda == null) return;
35 161
36 Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); 162 Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds.");
37 163
38 if (properties.getQueryPath() != null) 164 if (properties.getQueryPath() != null)
39 for (String queryFile: properties.getQueryPath().split(";")) 165 for (String queryFile: properties.getQueryPath().split(";"))
40 pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile)); 166 pagoda.evaluate(pagoda.getQueryManager().collectQueryRecords(queryFile));
167
168 if(properties.getShellMode())
169 try {
170 evaluateConsoleQuery(pagoda);
171 } catch(IOException e) {
172 e.printStackTrace();
173 }
41 } finally { 174 } finally {
42 if (pagoda != null) pagoda.dispose(); 175 if (pagoda != null) pagoda.dispose();
43 } 176 }
177
178// Utility.closeCurrentOut();
179
180 if(properties.getShellMode()) System.exit(0);
181 }
182
183 private static void evaluateConsoleQuery(QueryReasoner pagoda) throws IOException {
184 int ending = (int) '$', symbol;
185 while(true) {
186 Utility.logInfo("Input your query ending with $");
187 StringBuilder queryBuilder = new StringBuilder();
188 while((symbol = System.in.read()) != ending) {
189 queryBuilder.append((char) symbol);
190 }
191 System.in.read();
192 if(queryBuilder.length() == 0) return;
193 pagoda.evaluate_shell(queryBuilder.toString());
194 }
195 }
196
197 void testReactomeQueries() {
198 evaluate("select ?x where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.biopax.org/release/biopax-level3.owl#DnaReference> . }");
199 evaluate("select ?y ?z where { <http://identifiers.org/ensembl/ENSG00000157557> ?y ?z . }");
200 evaluate("select ?y where { <http://identifiers.org/ensembl/ENSG00000157557> <http://www.biopax.org/release/biopax-level3.owl#name> ?y . }", true);
201
202 }
203
204 void testSemFacetQueries() {
205// try {
206// BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("query.line")));
207// for (String line; (line = reader.readLine()) != null && !line.isEmpty(); )
208// evaluate(line, true);
209// reader.close();
210// } catch (FileNotFoundException e) {
211// e.printStackTrace();
212// } catch (IOException e) {
213// e.printStackTrace();
214// }
215 evaluate("select ?x ?z where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z }", true);
216 evaluate("select distinct ?y where { ?x ?y ?z }", true);
217 evaluate("select distinct ?z where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z }", true);
218 evaluate("select ?y ?z where { <http://www.reactome.org/biopax/46/49633#Protein3885> ?y ?z .}", true);
219 }
220
221 void testISGQueries() {
222 evaluate("select ?z where {<http://cs.ox.ac.uk/Evgeny_Kharlamov> <http://cs.ox.ac.uk/lat> ?z .}", false);
223 evaluate("select ?x where {?x <http://cs.ox.ac.uk/type> <http://cs.ox.ac.uk/person> .}", false);
224 }
225
226 void testSomeTravelQueries() {
227 evaluate("select ?y ?z where {<http://www.owl-ontologies.com/travel.owl#BlueMountains> ?y ?z. }", true);
228 evaluate("select ?x where {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.owl-ontologies.com/travel.owl#RetireeDestination>. }");
229 evaluate("select ?x where {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.owl-ontologies.com/travel.owl#BackpackersDestination>. }");
230 }
231
232 void testSomeFlyQueries() {
233 evaluate("select ?x where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00005106> . }", false);
234
235 evaluate("select DISTINCT ?z where { ?x <http://purl.obolibrary.org/obo/FBbt#develops_from> ?any . ?any <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z . ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00067123> . } ", true);
236
237 evaluate("Select ?x where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "
238 + "<http://purl.obolibrary.org/obo/FBbt_00067123>. ?x "
239 + "<http://purl.obolibrary.org/obo/RO_0002131> ?any . ?any "
240 + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "
241 + "<http://purl.obolibrary.org/obo/FBbt_00005140> . }", true);
242
243 evaluate("Select ?x where {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "
244 + "<http://purl.obolibrary.org/obo/FBbt_00067363> . ?x "
245 + "<http://purl.obolibrary.org/obo/RO_0002131> ?any . ?any "
246 + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "
247 + "<http://purl.obolibrary.org/obo/FBbt_00005140> . }", true);
248
249// evaluate("Select ?x where { "
250// + "?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00003660>. "
251// + "?x <http://purl.obolibrary.org/obo/FBbt#develops_from> ?any . "
252// + "?any <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00001446> . }", true);
253
254 evaluate("select DISTINCT ?z where { ?x <http://purl.obolibrary.org/obo/RO_0002110> ?any . "
255 + "?any <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z . "
256 + "?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00007016> . } ", true);
257
258 evaluate("Select * where {"
259 + "<http://www.virtualflybrain.org/ontologies/individuals/VFB_00100607> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00007364>. "
260 + "<http://www.virtualflybrain.org/ontologies/individuals/VFB_00100607> <http://www.w3.org/2002/07/owl#sameAs> ?z }", true);
261
262 evaluate("SELECT DISTINCT ?x ?z WHERE {?x <http://www.w3.org/2002/07/owl#sameAs> ?z}", true);
263 evaluate("SELECT DISTINCT ?x ?z WHERE {?x <http://purl.obolibrary.org/obo/BFO_0000051> ?z}", true);
264
265 evaluate("select DISTINCT ?y where { ?x ?y ?z . "
266 + "?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/FBbt_00007364> }", true);
267
268 evaluateQueriesFromFile("/users/yzhou/Downloads/logs(1).log");
269 evaluateQueriesFromFile("/users/yzhou/Downloads/logs.log");
270
271 evaluate("SELECT DISTINCT ?x ?z WHERE {?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z}", true);
272 evaluate("SELECT DISTINCT ?x ?z WHERE {?x <http://xmlns.com/foaf/0.1/depicts> ?z}", true);
273
274 evaluate("select ?x ?z where { ?x <http://www.w3.org/2002/07/owl#sameAs> ?z } ", true);
275 evaluate("select ?x ?z where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?z } ", true);
276 }
277
278 public void evaluateQueriesFromFile(String fileName) {
279 Scanner scanner = null;
280 try {
281 scanner = new Scanner(new File(fileName));
282 String line;
283 while(scanner.hasNextLine()) {
284 line = scanner.nextLine();
285 if(line.startsWith("select"))
286 evaluate(line, true);
287 }
288 } catch(FileNotFoundException e) {
289 e.printStackTrace();
290 } finally {
291 if(scanner != null)
292 scanner.close();
293 }
294 }
295
296 private void evaluate(String query) {
297 evaluate(query, false);
298 }
299
300 private void evaluate(String query, boolean tag) {
301 timer.reset();
302 AnswerTuples tuples = pagoda.evaluate(query, tag);
303 int arity = tuples.getArity();
304 int count = 0;
305 for(AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) {
306 tuple = tuples.getTuple();
307 for(int i = 0; i < arity; ++i)
308 tuple.getGroundTerm(i).toString();
309// System.out.print(tuple.getGroundTerm(i).toString() + "\t");
310// System.out.println();
311 ++count;
312 }
313 tuples.dispose();
314 Utility.logInfo("The number of answers for this SemFacet query: " + count);
315 Utility.logInfo("Total time for this SemFacet query: " + timer.duration());
44 } 316 }
45 317
46} 318}