diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-10 18:17:06 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-11 12:34:47 +0100 |
| commit | 17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch) | |
| tree | 47e9310a0cff869d9ec017dcb2c81876407782c8 /src/test/java/uk/ac/ox/cs | |
| parent | 8651164cd632a5db310b457ce32d4fbc97bdc41c (diff) | |
| download | ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip | |
[pagoda] Move project to Scala
This commit includes a few changes:
- The repository still uses Maven to manage dependency but it is now a
Scala project.
- The code has been ported from OWLAPI 3.4.10 to 5.1.20
- A proof of concept program using both RSAComb and PAGOdA has been
added.
Diffstat (limited to 'src/test/java/uk/ac/ox/cs')
31 files changed, 3577 insertions, 0 deletions
diff --git a/src/test/java/uk/ac/ox/cs/hermit/HermitQueryReasoner.java b/src/test/java/uk/ac/ox/cs/hermit/HermitQueryReasoner.java new file mode 100644 index 0000000..957790f --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/hermit/HermitQueryReasoner.java | |||
| @@ -0,0 +1,200 @@ | |||
| 1 | package uk.ac.ox.cs.hermit; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.Reasoner; | ||
| 4 | import org.semanticweb.HermiT.model.Atom; | ||
| 5 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 6 | import org.semanticweb.owlapi.model.*; | ||
| 7 | import org.semanticweb.owlapi.model.parameters.Imports; | ||
| 8 | import org.semanticweb.owlapi.reasoner.Node; | ||
| 9 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 10 | import uk.ac.ox.cs.pagoda.owl.QueryRoller; | ||
| 11 | import uk.ac.ox.cs.pagoda.query.QueryManager; | ||
| 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 14 | |||
| 15 | import java.io.*; | ||
| 16 | import java.util.HashSet; | ||
| 17 | import java.util.Set; | ||
| 18 | import java.util.concurrent.*; | ||
| 19 | |||
| 20 | public class HermitQueryReasoner { | ||
| 21 | |||
| 22 | public static void main(String... args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { | ||
| 23 | if (args.length == 0) { | ||
| 24 | // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/lubm/lubm1_merged.owl", null, PagodaTester.lubm_query}; | ||
| 25 | // args = new String[] {"/users/yzhou/ontologies/uobm/uobm1_merged.owl", null, "/users/yzhou/ontologies/uobm/queries/standard.sparql"}; | ||
| 26 | // args = new String[] {"/users/yzhou/ontologies/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", null, "/users/yzhou/ontologies/fly/queries/fly.sparql"}; | ||
| 27 | // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all-minus-datatype.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-minus-datatype-new.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; | ||
| 28 | // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-processed.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; | ||
| 29 | // args = new String[] {PagodaTester.dbpedia_tbox, PagodaTester.dbpedia_abox, PagodaTester.dbpedia_query}; | ||
| 30 | // args = new String[] {"/users/yzhou/ontologies/answersCorrectness/unsatisfiable.owl", null, "/users/yzhou/ontologies/answersCorrectness/unsatisfiable_queries.sparql"}; | ||
| 31 | |||
| 32 | // args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/graph sampling/sample_100.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/queries/atomic_one_filtered.sparql", "../answersCorrectness-share/results/chembl/hermit_1p"}; | ||
| 33 | args = | ||
| 34 | new String[]{"/users/yzhou/temp/uniprot_debug/core-processed-noDis.owl", "/users/yzhou/temp/uniprot_debug/sample_1_removed.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; | ||
| 35 | } | ||
| 36 | // args = new String[] {"imported.owl", "", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; } | ||
| 37 | |||
| 38 | |||
| 39 | PrintStream ps = args.length < 4 ? null : new PrintStream(new File(args[3])); | ||
| 40 | for (int i = 0; i < args.length; ++i) { | ||
| 41 | if (args[i] == null || args[i].equalsIgnoreCase("null")) args[i] = ""; | ||
| 42 | System.out.println("Argument " + i + ": " + args[i]); | ||
| 43 | } | ||
| 44 | |||
| 45 | // PrintStream ps = null; // new PrintStream(new File("../answersCorrectness-share/results/reactome/ ")); | ||
| 46 | if (ps != null) System.setOut(ps); | ||
| 47 | |||
| 48 | Timer t = new Timer(); | ||
| 49 | OWLOntology onto = OWLHelper.loadOntology(args[0]); | ||
| 50 | OWLOntologyManager man = onto.getOWLOntologyManager(); | ||
| 51 | |||
| 52 | OWLDatatype date = man.getOWLDataFactory().getOWLDatatype(IRI.create("http://www.w3.org/2001/XMLSchema#date")); | ||
| 53 | |||
| 54 | if (onto.containsEntityInSignature(date)) { | ||
| 55 | for (OWLOntology o: onto.getImportsClosure()) | ||
| 56 | for (OWLAxiom axiom: o.getAxioms()) | ||
| 57 | if (axiom.getDatatypesInSignature().contains(date)) { | ||
| 58 | System.out.println("The axiom: " + axiom + " is being ingored. "); | ||
| 59 | man.removeAxiom(onto, axiom); | ||
| 60 | } | ||
| 61 | man.saveOntology(onto, new FileOutputStream(args[0] = "tbox_hermit.owl")); | ||
| 62 | man.removeOntology(onto); | ||
| 63 | onto = OWLHelper.loadOntology(man, args[0]); | ||
| 64 | System.out.println("TBox processed in " + t.duration()); | ||
| 65 | } | ||
| 66 | |||
| 67 | try { | ||
| 68 | onto = OWLHelper.getImportedOntology(onto, args[1]); | ||
| 69 | } catch (IOException e) { | ||
| 70 | e.printStackTrace(); | ||
| 71 | } | ||
| 72 | System.out.println("Ontology loaded in " + t.duration()); | ||
| 73 | System.out.println("ABox axioms:" + onto.getABoxAxioms(Imports.INCLUDED).size()); | ||
| 74 | // for (OWLOntology o: onto.getImportsClosure()) | ||
| 75 | // for (OWLAxiom axiom: o.getAxioms()) | ||
| 76 | // System.out.println(axiom); | ||
| 77 | |||
| 78 | Reasoner hermit = new Reasoner(onto); | ||
| 79 | if (!hermit.isConsistent()) { | ||
| 80 | System.out.println("The ontology is inconsistent."); | ||
| 81 | return ; | ||
| 82 | } | ||
| 83 | System.out.println("Preprocessing DONE in " + t.duration()); | ||
| 84 | |||
| 85 | // System.out.println(hermit.isConsistent()); | ||
| 86 | |||
| 87 | QueryManager queryManager = new QueryManager(); | ||
| 88 | QueryRoller roller = new QueryRoller(onto.getOWLOntologyManager().getOWLDataFactory()); | ||
| 89 | int failedCounter = 0; | ||
| 90 | Timer total = new Timer(); | ||
| 91 | for (QueryRecord record: queryManager.collectQueryRecords(args[2])) { | ||
| 92 | if (Integer.parseInt(record.getQueryID()) < 10) continue; | ||
| 93 | if (total.duration() > 18000) { | ||
| 94 | System.out.println("Time out 5h."); | ||
| 95 | return ; | ||
| 96 | } | ||
| 97 | System.out.println("--------------------- Query " + record.getQueryID() + " -----------------------"); | ||
| 98 | System.out.println(record.getQueryText()); | ||
| 99 | ExecutorService exec = Executors.newSingleThreadExecutor(); | ||
| 100 | try { | ||
| 101 | Future<Boolean> succ = exec.submit(new QueryThread(record, onto, hermit, roller)); | ||
| 102 | try { | ||
| 103 | try { | ||
| 104 | if (record.getQueryID().equals("1")) | ||
| 105 | System.out.println(succ.get(60, TimeUnit.MINUTES)); | ||
| 106 | else | ||
| 107 | System.out.println(succ.get(20, TimeUnit.MINUTES)); | ||
| 108 | } catch (InterruptedException e) { | ||
| 109 | // e.printStackTrace(); | ||
| 110 | } catch (ExecutionException e) { | ||
| 111 | // e.printStackTrace(); | ||
| 112 | } catch (TimeoutException e) { | ||
| 113 | // e.printStackTrace(); | ||
| 114 | } | ||
| 115 | } finally { | ||
| 116 | if (succ.cancel(true)) { | ||
| 117 | System.out.println("Trying to cancel the current query thread " + (++failedCounter)); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } finally { | ||
| 121 | exec.shutdownNow(); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | if (ps != null) ps.close(); | ||
| 126 | System.exit(0); | ||
| 127 | } | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 131 | class QueryThread implements Callable<Boolean> { | ||
| 132 | |||
| 133 | QueryRecord record; | ||
| 134 | OWLOntology onto; | ||
| 135 | Reasoner hermit; | ||
| 136 | QueryRoller roller; | ||
| 137 | |||
| 138 | public QueryThread(QueryRecord record2, OWLOntology onto2, Reasoner hermit2, QueryRoller roller2) { | ||
| 139 | record = record2; onto = onto2; hermit = hermit2; roller = roller2; | ||
| 140 | } | ||
| 141 | |||
| 142 | @Override | ||
| 143 | public Boolean call() throws Exception { | ||
| 144 | Set<String> answers = new HashSet<String>(); | ||
| 145 | Timer t = new Timer(); | ||
| 146 | if (record.getDistinguishedVariables().length > 1) { | ||
| 147 | if (record.getDistinguishedVariables().length == 2 && record.getClause().getBodyLength() == 1) { | ||
| 148 | dealWithAtomicBinaryQuery(record.getClause().getBodyAtom(0), answers); | ||
| 149 | System.out.println("Query " + record.getQueryID() + " The number of answers: " + answers.size()); | ||
| 150 | System.out.println("Query " + record.getQueryID() + " Total time: " + t.duration()); | ||
| 151 | } | ||
| 152 | else { | ||
| 153 | System.out.println("Query " + record.getQueryID() + " The number of answers: Query cannot be processsed."); | ||
| 154 | System.out.println("Query " + record.getQueryID() + " Total time: Query cannot be processsed."); | ||
| 155 | } | ||
| 156 | return false; | ||
| 157 | } | ||
| 158 | |||
| 159 | OWLClassExpression exp = null; | ||
| 160 | |||
| 161 | try { | ||
| 162 | exp = roller.rollUp(record.getClause(), record.getAnswerVariables()[0]); | ||
| 163 | } catch (Exception e) { | ||
| 164 | System.out.println("Query " + record.getQueryID() + " The number of answers: Query cannot be processsed."); | ||
| 165 | System.out.println("Query " + record.getQueryID() + " Total time: Query cannot be processsed."); | ||
| 166 | return false; | ||
| 167 | } | ||
| 168 | System.out.println(exp); | ||
| 169 | for (Node<OWLNamedIndividual> node: hermit.getInstances(exp, false)) { | ||
| 170 | for (OWLIndividual ind: node.getEntities()) { | ||
| 171 | answers.add(ind.toStringID()); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | System.out.println("Query " + record.getQueryID() + " The number of answers: " + answers.size()); | ||
| 175 | System.out.println("Query " + record.getQueryID() + " Total time: " + t.duration()); | ||
| 176 | return true; | ||
| 177 | } | ||
| 178 | |||
| 179 | private void dealWithAtomicBinaryQuery(Atom bodyAtom, Set<String> answers) { | ||
| 180 | StringBuilder sb = new StringBuilder(); | ||
| 181 | OWLDataFactory f = onto.getOWLOntologyManager().getOWLDataFactory(); | ||
| 182 | OWLObjectProperty p = f.getOWLObjectProperty(IRI.create(((AtomicRole) bodyAtom.getDLPredicate()).getIRI())); | ||
| 183 | for (Node<OWLNamedIndividual> sub: hermit.getInstances(f.getOWLObjectMinCardinality(1, p), false)) { | ||
| 184 | for (Node<OWLNamedIndividual> obj: hermit.getObjectPropertyValues(sub.getRepresentativeElement(), p)) { | ||
| 185 | for (OWLNamedIndividual subInd: sub.getEntities()) { | ||
| 186 | sb.setLength(0); | ||
| 187 | sb.append(subInd.toString()).append(" "); | ||
| 188 | int len = sb.length(); | ||
| 189 | for (OWLNamedIndividual objInd: obj.getEntities()) { | ||
| 190 | sb.setLength(len); | ||
| 191 | sb.append(objInd.toString()); | ||
| 192 | answers.add(sb.toString()); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | } | ||
| 200 | |||
diff --git a/src/test/java/uk/ac/ox/cs/hermit/HermitTester.java b/src/test/java/uk/ac/ox/cs/hermit/HermitTester.java new file mode 100644 index 0000000..dc70284 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/hermit/HermitTester.java | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | package uk.ac.ox.cs.hermit; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.Configuration; | ||
| 4 | import org.semanticweb.HermiT.Reasoner; | ||
| 5 | import org.semanticweb.HermiT.model.Atom; | ||
| 6 | import org.semanticweb.HermiT.model.DLClause; | ||
| 7 | import org.semanticweb.HermiT.model.DLOntology; | ||
| 8 | import org.semanticweb.HermiT.structural.OWLClausification; | ||
| 9 | import org.semanticweb.owlapi.model.IRI; | ||
| 10 | import org.semanticweb.owlapi.model.OWLAxiom; | ||
| 11 | import org.semanticweb.owlapi.model.OWLClass; | ||
| 12 | import org.semanticweb.owlapi.model.OWLDataFactory; | ||
| 13 | import org.semanticweb.owlapi.model.OWLNamedIndividual; | ||
| 14 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 15 | import org.semanticweb.owlapi.reasoner.Node; | ||
| 16 | |||
| 17 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 18 | |||
| 19 | public class HermitTester { | ||
| 20 | |||
| 21 | public static void main(String[] args) { | ||
| 22 | OWLOntology onto = OWLHelper.loadOntology("imported.owl"); | ||
| 23 | Reasoner hermit = new Reasoner(onto); | ||
| 24 | OWLDataFactory f = onto.getOWLOntologyManager().getOWLDataFactory(); | ||
| 25 | OWLClass concept = f.getOWLClass(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#Query12")); | ||
| 26 | |||
| 27 | for (OWLOntology o: onto.getImportsClosure()) { | ||
| 28 | System.out.println(o.containsEntityInSignature(concept)); | ||
| 29 | for (OWLAxiom axiom: o.getAxioms()) | ||
| 30 | if (axiom.getClassesInSignature().contains(concept)) | ||
| 31 | System.out.println(axiom); | ||
| 32 | } | ||
| 33 | |||
| 34 | for (Node<OWLNamedIndividual> node : hermit.getInstances(concept, false)) | ||
| 35 | for (OWLNamedIndividual i: node.getEntities()) { | ||
| 36 | System.out.println(i.toStringID()); | ||
| 37 | } | ||
| 38 | |||
| 39 | // clausifierTest(); | ||
| 40 | } | ||
| 41 | |||
| 42 | @SuppressWarnings("unused") | ||
| 43 | private static void clausifierTest() { | ||
| 44 | OWLOntology onto = OWLHelper.loadOntology("/users/yzhou/ontologies/travel.owl"); | ||
| 45 | OWLClausification clausifier = new OWLClausification(new Configuration()); | ||
| 46 | DLOntology dlOntology = (DLOntology)clausifier.preprocessAndClausify(onto, null)[1]; | ||
| 47 | |||
| 48 | for (DLClause clause: dlOntology.getDLClauses()) | ||
| 49 | System.out.println(clause); | ||
| 50 | for (Atom atom : dlOntology.getPositiveFacts()) | ||
| 51 | System.out.println(atom); | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 55 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/hermit/JAIR_HermiT.java b/src/test/java/uk/ac/ox/cs/hermit/JAIR_HermiT.java new file mode 100644 index 0000000..72e7af8 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/hermit/JAIR_HermiT.java | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | package uk.ac.ox.cs.hermit; | ||
| 2 | |||
| 3 | import org.junit.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 5 | |||
| 6 | public class JAIR_HermiT { | ||
| 7 | |||
| 8 | @Test | ||
| 9 | public void lubm1() throws Exception { | ||
| 10 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 11 | String[] args = new String[] { | ||
| 12 | TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), | ||
| 13 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), | ||
| 14 | TestUtil.combinePaths(ontoDir, "lubm/queries/answersCorrectness.sparql") | ||
| 15 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit" | ||
| 16 | }; | ||
| 17 | HermitQueryReasoner.main(args); | ||
| 18 | } | ||
| 19 | |||
| 20 | @Test | ||
| 21 | public void lubm1_rolledUp() throws Exception { | ||
| 22 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 23 | String[] args = new String[] { | ||
| 24 | "/home/yzhou/backup/20141212/univ-bench-queries.owl", | ||
| 25 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), | ||
| 26 | TestUtil.combinePaths(ontoDir, "lubm/queries/atomic_lubm.sparql") | ||
| 27 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit_rolledUp" | ||
| 28 | }; | ||
| 29 | HermitQueryReasoner.main(args); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Test | ||
| 33 | public void uobm1() throws Exception { | ||
| 34 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 35 | String[] args = new String[] { | ||
| 36 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 37 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), | ||
| 38 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") | ||
| 39 | // , "hermit_uobm1.out" | ||
| 40 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit" | ||
| 41 | }; | ||
| 42 | HermitQueryReasoner.main(args); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Test | ||
| 46 | public void uobm1_rolledUp() throws Exception { | ||
| 47 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 48 | String[] args = new String[] { | ||
| 49 | "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl", | ||
| 50 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), | ||
| 51 | TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") | ||
| 52 | , "hermit_uobm1_rolledUp.out" | ||
| 53 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit_rolledUp" | ||
| 54 | }; | ||
| 55 | HermitQueryReasoner.main(args); | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test | ||
| 59 | public void fly_rolledUp() throws Exception { | ||
| 60 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 61 | HermitQueryReasoner.main( | ||
| 62 | TestUtil.combinePaths(ontoDir, "fly/fly-all-in-one_rolledUp.owl"), | ||
| 63 | // TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", | ||
| 64 | null, | ||
| 65 | TestUtil.combinePaths(ontoDir, "fly/queries/fly_atomic.sparql") | ||
| 66 | , "hermit_fly.out" | ||
| 67 | ); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Test | ||
| 71 | public void npd() throws Exception { | ||
| 72 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 73 | HermitQueryReasoner.main( | ||
| 74 | TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), | ||
| 75 | TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), | ||
| 76 | TestUtil.combinePaths(ontoDir, "npd/queries/atomic_ground.sparql") | ||
| 77 | , "hermit_npd.out" | ||
| 78 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/npd/hermit" | ||
| 79 | ); | ||
| 80 | } | ||
| 81 | |||
| 82 | @Test | ||
| 83 | public void dbpedia() throws Exception { | ||
| 84 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 85 | HermitQueryReasoner.main( | ||
| 86 | TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), | ||
| 87 | TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), | ||
| 88 | TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql") | ||
| 89 | , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/dbpedia/hermit" | ||
| 90 | ); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Test | ||
| 94 | public void reactome() throws Exception { | ||
| 95 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 96 | HermitQueryReasoner.main( | ||
| 97 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), | ||
| 98 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl"), | ||
| 99 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/atomic_ground.sparql") | ||
| 100 | , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/hermit_10p" | ||
| 101 | ); | ||
| 102 | } | ||
| 103 | |||
| 104 | @Test | ||
| 105 | public void chembl() throws Exception { | ||
| 106 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 107 | HermitQueryReasoner.main( | ||
| 108 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), | ||
| 109 | // null, | ||
| 110 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/graph sampling/sample_1.nt"), | ||
| 111 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") | ||
| 112 | , "hermit_chembl.out" | ||
| 113 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/hermit_1p" | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | |||
| 117 | @Test | ||
| 118 | public void uniprot() throws Exception { | ||
| 119 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 120 | HermitQueryReasoner.main( | ||
| 121 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat.owl"), | ||
| 122 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/graph sampling/sample_1.nt"), | ||
| 123 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") | ||
| 124 | , "hermit_uniprot.out" | ||
| 125 | // , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/hermit_1p" | ||
| 126 | ); | ||
| 127 | } | ||
| 128 | |||
| 129 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/jrdfox/Tester.java b/src/test/java/uk/ac/ox/cs/jrdfox/Tester.java new file mode 100644 index 0000000..94f5401 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/jrdfox/Tester.java | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | package uk.ac.ox.cs.jrdfox; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | |||
| 5 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 6 | |||
| 7 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 8 | import uk.ac.ox.cs.JRDFox.Prefixes; | ||
| 9 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 10 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 11 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 12 | import uk.ac.ox.cs.JRDFox.store.TripleStatus; | ||
| 13 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 14 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 15 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 16 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxQueryEngine; | ||
| 17 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 18 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 19 | |||
| 20 | public class Tester { | ||
| 21 | |||
| 22 | public static void main(String[] args) throws JRDFStoreException { | ||
| 23 | Tester tester = new Tester(); | ||
| 24 | tester.testCrash(); | ||
| 25 | } | ||
| 26 | |||
| 27 | private void evaluate_againstIDs(String queryText) throws JRDFStoreException { | ||
| 28 | int number = 0; | ||
| 29 | Timer t = new Timer(); | ||
| 30 | TupleIterator iter = null; | ||
| 31 | try { | ||
| 32 | iter = store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); | ||
| 33 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) | ||
| 34 | ++number; | ||
| 35 | } finally { | ||
| 36 | if (iter != null) iter.dispose(); | ||
| 37 | } | ||
| 38 | System.out.println(number); | ||
| 39 | System.out.println(t.duration()); | ||
| 40 | |||
| 41 | } | ||
| 42 | |||
| 43 | DataStore store; | ||
| 44 | Prefixes prefixes = new Prefixes(); | ||
| 45 | Parameters parameters; | ||
| 46 | |||
| 47 | public Tester() { | ||
| 48 | try { | ||
| 49 | store = new DataStore(StoreType.NarrowParallelHead); | ||
| 50 | store.setNumberOfThreads(RDFoxQueryEngine.matNoOfThreads); | ||
| 51 | store.initialize(); | ||
| 52 | System.out.println("data store created."); | ||
| 53 | } catch (JRDFStoreException e) { | ||
| 54 | e.printStackTrace(); | ||
| 55 | } | ||
| 56 | parameters = new Parameters(); | ||
| 57 | parameters.m_allAnswersInRoot = true; | ||
| 58 | parameters.m_useBushy = true; | ||
| 59 | } | ||
| 60 | |||
| 61 | public Tester(String path) { | ||
| 62 | try { | ||
| 63 | store = new DataStore(new File(path)); | ||
| 64 | } catch (JRDFStoreException e) { | ||
| 65 | e.printStackTrace(); | ||
| 66 | } | ||
| 67 | parameters = new Parameters(); | ||
| 68 | // parameters.m_allAnswersInRoot = true; | ||
| 69 | // parameters.m_useBushy = true; | ||
| 70 | } | ||
| 71 | |||
| 72 | public void applyReasoning(boolean incremental) { | ||
| 73 | Timer t = new Timer(); | ||
| 74 | try { | ||
| 75 | store.applyReasoning(incremental); | ||
| 76 | } catch (JRDFStoreException e) { | ||
| 77 | e.printStackTrace(); | ||
| 78 | } | ||
| 79 | System.out.println("reasoning done: " + t.duration()); | ||
| 80 | } | ||
| 81 | |||
| 82 | public void dispose() { | ||
| 83 | store.dispose(); | ||
| 84 | } | ||
| 85 | |||
| 86 | public void testCrash() throws JRDFStoreException { | ||
| 87 | // DataStore lowerStore = new DataStore(StoreType.NarrowParallelHead); | ||
| 88 | // lowerStore.setNumberOfThreads(RDFoxQueryEngine.matNoOfThreads); | ||
| 89 | // lowerStore.initialize(); | ||
| 90 | // System.out.println("lower data store created."); | ||
| 91 | OWLOntology ontology = OWLHelper.loadOntology("data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"); | ||
| 92 | System.out.println("ontology loaded ... " + ontology.getAxiomCount()); | ||
| 93 | |||
| 94 | store.importTurtleFile(new File("testcase/fly.ttl")); | ||
| 95 | System.out.println("data loaded. " + store.getTriplesCount()); | ||
| 96 | |||
| 97 | store.importRules(new File[] {new File("testcase/lower.dlog")}); | ||
| 98 | System.out.println("rules loaded. " + store.getTriplesCount()); | ||
| 99 | |||
| 100 | store.applyReasoning(); | ||
| 101 | System.out.println("materialised. " + store.getTriplesCount()); | ||
| 102 | |||
| 103 | store.clearRulesAndMakeFactsExplicit(); | ||
| 104 | |||
| 105 | store.importRules(new File[] {new File("testcase/multi.dlog")}); | ||
| 106 | System.out.println("rules loaded. " + store.getTriplesCount()); | ||
| 107 | |||
| 108 | store.applyReasoning(); | ||
| 109 | System.out.println("materialised. " + store.getTriplesCount()); | ||
| 110 | |||
| 111 | store.makeFactsExplicit(); | ||
| 112 | |||
| 113 | store.importTurtleFiles(new File[] {new File("testcase/first.ttl")}, UpdateType.ScheduleForAddition); | ||
| 114 | System.out.println("first data loaded. " + store.getTriplesCount()); | ||
| 115 | |||
| 116 | store.applyReasoning(true); | ||
| 117 | System.out.println("incremental reasoning done. " + store.getTriplesCount()); | ||
| 118 | |||
| 119 | store.clearRulesAndMakeFactsExplicit(); | ||
| 120 | |||
| 121 | store.importTurtleFiles(new File[] {new File("testcase/second.ttl")}, UpdateType.ScheduleForAddition); | ||
| 122 | store.importRules(new File[] {new File("testcase/tracking.dlog")}, UpdateType.ScheduleForAddition); | ||
| 123 | store.applyReasoning(true); | ||
| 124 | System.out.println("incremental reasoning done. " + store.getTriplesCount()); | ||
| 125 | |||
| 126 | evaluate_againstIDs("select distinct ?z where { ?x <" + Namespace.RDF_TYPE + "> ?z . }"); | ||
| 127 | System.out.println("done."); | ||
| 128 | // tester.applyReasoning(true); | ||
| 129 | // tester.evaluate_againstIDs("select distinct ?z where { ?x <" + Namespace.RDF_TYPE + "> ?z . }"); | ||
| 130 | // System.out.println("done."); | ||
| 131 | |||
| 132 | store.dispose(); | ||
| 133 | // lowerStore.dispose(); | ||
| 134 | } | ||
| 135 | |||
| 136 | public void test() throws JRDFStoreException { | ||
| 137 | evaluate("PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> " | ||
| 138 | + "SELECT distinct ?x WHERE { " | ||
| 139 | + "?x a benchmark:Person . " | ||
| 140 | + "?x benchmark:like ?y . " | ||
| 141 | + "?z a benchmark:Chair . " | ||
| 142 | + "?z benchmark:isHeadOf <http://www.Department0.University0.edu> . " | ||
| 143 | + "?z benchmark:like ?y . " | ||
| 144 | + "?x a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . " | ||
| 145 | + "?z a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . " | ||
| 146 | + "?y a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> }"); | ||
| 147 | |||
| 148 | evaluate("PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> " | ||
| 149 | + "SELECT distinct ?x WHERE { " | ||
| 150 | + "?x a benchmark:Person . " | ||
| 151 | + "?x benchmark:like ?y . " | ||
| 152 | + "?z a benchmark:Chair . " | ||
| 153 | + "?z benchmark:isHeadOf <http://www.Department0.University0.edu> . " | ||
| 154 | + "?z benchmark:like ?y . " | ||
| 155 | + "?z a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . " | ||
| 156 | + "?y a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> ." | ||
| 157 | + "?x a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> }"); | ||
| 158 | |||
| 159 | evaluate("PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> " | ||
| 160 | + "SELECT distinct ?x WHERE { " | ||
| 161 | + "?x a benchmark:Person . " | ||
| 162 | + "?x benchmark:like ?y . " | ||
| 163 | + "?z a benchmark:Chair . " | ||
| 164 | + "?z benchmark:isHeadOf <http://www.Department0.University0.edu> . " | ||
| 165 | + "?z benchmark:like ?y . " | ||
| 166 | + "?y a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . " | ||
| 167 | + "?x a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . " | ||
| 168 | + "?z a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> }"); | ||
| 169 | |||
| 170 | evaluate("PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> " | ||
| 171 | + "SELECT distinct ?x WHERE { " | ||
| 172 | + "?x a benchmark:Person . " | ||
| 173 | + "?x benchmark:like ?y . " | ||
| 174 | + "?z a benchmark:Chair . " | ||
| 175 | + "?z benchmark:isHeadOf <http://www.Department0.University0.edu> . " | ||
| 176 | + "?z benchmark:like ?y . " | ||
| 177 | + "?y a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> }"); | ||
| 178 | } | ||
| 179 | |||
| 180 | public void evaluate(String query) throws JRDFStoreException { | ||
| 181 | int number = 0; | ||
| 182 | Timer t = new Timer(); | ||
| 183 | TupleIterator iter = null; | ||
| 184 | try { | ||
| 185 | iter = store.compileQuery(query, prefixes, parameters); | ||
| 186 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) | ||
| 187 | ++number; | ||
| 188 | } finally { | ||
| 189 | if (iter != null) iter.dispose(); | ||
| 190 | } | ||
| 191 | System.out.println(number); | ||
| 192 | System.out.println(t.duration()); | ||
| 193 | } | ||
| 194 | |||
| 195 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/approx/ApproxTester.java b/src/test/java/uk/ac/ox/cs/pagoda/approx/ApproxTester.java new file mode 100644 index 0000000..63fe7b7 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/approx/ApproxTester.java | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.approx; | ||
| 2 | |||
| 3 | import java.io.IOException; | ||
| 4 | |||
| 5 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 6 | |||
| 7 | import uk.ac.ox.cs.pagoda.approx.KnowledgeBase; | ||
| 8 | import uk.ac.ox.cs.pagoda.approx.RLOntology; | ||
| 9 | import uk.ac.ox.cs.pagoda.approx.RLPlusOntology; | ||
| 10 | import uk.ac.ox.cs.pagoda.constraints.NullaryBottom; | ||
| 11 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 12 | import uk.ac.ox.cs.pagoda.rules.DisjunctiveProgram; | ||
| 13 | import uk.ac.ox.cs.pagoda.rules.ExistentialProgram; | ||
| 14 | import uk.ac.ox.cs.pagoda.rules.ExistentialToDisjunctive; | ||
| 15 | import uk.ac.ox.cs.pagoda.rules.GeneralProgram; | ||
| 16 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; | ||
| 17 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | ||
| 18 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 19 | |||
| 20 | public class ApproxTester { | ||
| 21 | |||
| 22 | private static ApproxType description = ApproxType.DATALOGPMOR; | ||
| 23 | |||
| 24 | private static String ontoFile = null; | ||
| 25 | |||
| 26 | public static void main(String[] args) throws IOException | ||
| 27 | { | ||
| 28 | args = new String[] { | ||
| 29 | "-tbox", | ||
| 30 | // "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-noDPR.ttl", | ||
| 31 | // "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/reactome/biopax-level3-processed.owl", | ||
| 32 | // "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/atlas/gxaterms.owl", | ||
| 33 | // "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/core-sat-processed.owl", | ||
| 34 | // PagodaTester.npd_tbox, | ||
| 35 | // "/users/yzhou/temp/ontologies/core.RLor.rdf", | ||
| 36 | "datatype.owl", | ||
| 37 | "-dest", ApproxType.DATALOGPMOR.toString() | ||
| 38 | }; | ||
| 39 | |||
| 40 | long startTime = System.currentTimeMillis(); | ||
| 41 | |||
| 42 | if (args.length > 0) { | ||
| 43 | if (args.length % 2 != 0) { | ||
| 44 | System.out.println("arguments error..."); | ||
| 45 | return ; | ||
| 46 | } | ||
| 47 | for (int i = 0; i < args.length ; i = i + 2) | ||
| 48 | if (!setArgument(args[i], args[i + 1])) { | ||
| 49 | System.out.println("arguments error..."); | ||
| 50 | return ; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | // Utility.redirectSystemOut(); | ||
| 55 | |||
| 56 | System.setProperty("entityExpansionLimit", String.valueOf(Integer.MAX_VALUE)); | ||
| 57 | |||
| 58 | String directory = ontoFile.substring(0, ontoFile.lastIndexOf(Utility.FILE_SEPARATOR) + 1); | ||
| 59 | |||
| 60 | KnowledgeBase program = null; | ||
| 61 | switch (description) { | ||
| 62 | case OWL2RLPLUS: program = new RLPlusOntology(); break; | ||
| 63 | case OWL2RL: program = new RLOntology(); break; | ||
| 64 | case DATALOG_UPPER: program = new UpperDatalogProgram(); break; | ||
| 65 | case DATALOG_LOWER: program = new LowerDatalogProgram(); break; | ||
| 66 | case EXISTENTIAL: program = new ExistentialProgram(); break; | ||
| 67 | case DISJUNCTIVE: program = new DisjunctiveProgram(); break; | ||
| 68 | case DATALOGPMOR: program = new GeneralProgram(); break; | ||
| 69 | case EXIST2DISJ: program = new ExistentialToDisjunctive(); break; | ||
| 70 | default: | ||
| 71 | System.exit(0); | ||
| 72 | } | ||
| 73 | |||
| 74 | if (program instanceof RLPlusOntology) | ||
| 75 | ((RLPlusOntology) program).setCorrespondenceFileLoc(directory + "correspondence"); | ||
| 76 | OWLOntology ontology = OWLHelper.loadOntology(ontoFile); | ||
| 77 | program.load(ontology, new NullaryBottom()); | ||
| 78 | |||
| 79 | program.transform(); | ||
| 80 | |||
| 81 | program.save(); | ||
| 82 | |||
| 83 | System.out.println("Time to transform the rules: " + (System.currentTimeMillis() - startTime) / 1000.); | ||
| 84 | |||
| 85 | Utility.closeCurrentOut(); | ||
| 86 | } | ||
| 87 | |||
| 88 | private static boolean setArgument(String key, String value) { | ||
| 89 | if (key.equalsIgnoreCase("-dest")) | ||
| 90 | if (value.equalsIgnoreCase("OWL2RL+")) description = ApproxType.OWL2RLPLUS; | ||
| 91 | else if (value.equalsIgnoreCase("OWL2RL")) description = ApproxType.OWL2RL; | ||
| 92 | else if (value.equalsIgnoreCase("UPPERDATALOG")) description = ApproxType.DATALOG_UPPER; | ||
| 93 | else if (value.equalsIgnoreCase("LOWERDATALOG")) description = ApproxType.DATALOG_LOWER; | ||
| 94 | else if (value.equalsIgnoreCase("DATALOGPMOR")) description = ApproxType.DATALOGPMOR; | ||
| 95 | else if (value.equalsIgnoreCase("EXISTENTIALRULES")) description = ApproxType.EXISTENTIAL; | ||
| 96 | else if (value.equalsIgnoreCase("DISJUNCTIVE")) description = ApproxType.DISJUNCTIVE; | ||
| 97 | else if (value.equalsIgnoreCase("EXIST2DISJ")) description = ApproxType.EXIST2DISJ; | ||
| 98 | else { | ||
| 99 | System.out.println("illegal destination argument..."); | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | else if (key.equalsIgnoreCase("-tbox")) | ||
| 103 | ontoFile = value; | ||
| 104 | else { | ||
| 105 | System.out.println("unrecognisable type of argument..."); | ||
| 106 | return false; | ||
| 107 | } | ||
| 108 | |||
| 109 | return true; | ||
| 110 | } | ||
| 111 | |||
| 112 | public enum ApproxType { | ||
| 113 | /** | ||
| 114 | * approx to (RL + self + top being the subClassExp) | ||
| 115 | */ | ||
| 116 | OWL2RLPLUS, | ||
| 117 | |||
| 118 | /** | ||
| 119 | * approx to RL | ||
| 120 | */ | ||
| 121 | OWL2RL, | ||
| 122 | |||
| 123 | /** | ||
| 124 | * approx to datalog by replacing existential quantified variables | ||
| 125 | * by fresh constants and replacing disjunctions by conjunctions | ||
| 126 | */ | ||
| 127 | DATALOG_UPPER, | ||
| 128 | |||
| 129 | /** | ||
| 130 | * approx to datalog by ignoring existential and disjunctive axiom | ||
| 131 | */ | ||
| 132 | DATALOG_LOWER, | ||
| 133 | |||
| 134 | /** | ||
| 135 | * approx to existential rules by replacing disjunctions by | ||
| 136 | * conjunctions | ||
| 137 | */ | ||
| 138 | EXISTENTIAL, | ||
| 139 | |||
| 140 | /** | ||
| 141 | * approx to disjunctive datalog program by replacing existential | ||
| 142 | * quantified variables by fresh constants (DNF) | ||
| 143 | */ | ||
| 144 | DISJUNCTIVE, | ||
| 145 | |||
| 146 | /** | ||
| 147 | * transform into rules, no approximation at all | ||
| 148 | */ | ||
| 149 | DATALOGPMOR, | ||
| 150 | |||
| 151 | /** | ||
| 152 | * approx existential quantifiers by disjunctions | ||
| 153 | */ | ||
| 154 | EXIST2DISJ | ||
| 155 | |||
| 156 | }; | ||
| 157 | |||
| 158 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/approx/ClauseTester.java b/src/test/java/uk/ac/ox/cs/pagoda/approx/ClauseTester.java new file mode 100644 index 0000000..cff1d1c --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/approx/ClauseTester.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.approx; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.model.DLClause; | ||
| 4 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 5 | |||
| 6 | import uk.ac.ox.cs.pagoda.constraints.NullaryBottom; | ||
| 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 8 | import uk.ac.ox.cs.pagoda.rules.GeneralProgram; | ||
| 9 | |||
| 10 | public class ClauseTester { | ||
| 11 | |||
| 12 | public static void main(String... args) { | ||
| 13 | args = new String[] { | ||
| 14 | // "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-noDPR.ttl", | ||
| 15 | "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/reactome/biopax-level3-processed.owl", | ||
| 16 | // "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/atlas/gxaterms.owl", | ||
| 17 | // "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/core-sat-processed.owl", | ||
| 18 | // PagodaTester.npd_tbox, | ||
| 19 | // "/users/yzhou/temp/ontologies/core.RLor.rdf", | ||
| 20 | // "datatype.owl" | ||
| 21 | }; | ||
| 22 | |||
| 23 | String ontoFile = args[0]; | ||
| 24 | OWLOntology ontology = OWLHelper.loadOntology(ontoFile); | ||
| 25 | GeneralProgram program = new GeneralProgram();; | ||
| 26 | program.load(ontology, new NullaryBottom()); | ||
| 27 | program.transform(); | ||
| 28 | program.save(); | ||
| 29 | if (program instanceof GeneralProgram) { | ||
| 30 | GeneralProgram gp = ((GeneralProgram) program); | ||
| 31 | for (DLClause clause: gp.getClauses()) { | ||
| 32 | System.out.println(clause); | ||
| 33 | System.out.println(OWLHelper.getOWLAxiom(ontology, clause)); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java b/src/test/java/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java new file mode 100644 index 0000000..a4579a3 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.endomorph; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 4 | import org.semanticweb.owlapi.model.*; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; | ||
| 8 | import uk.ac.ox.cs.JRDFox.model.Individual; | ||
| 9 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 10 | import uk.ac.ox.cs.pagoda.summary.Graph; | ||
| 11 | import uk.ac.ox.cs.pagoda.summary.NodeTuple; | ||
| 12 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 13 | |||
| 14 | import java.util.HashSet; | ||
| 15 | |||
| 16 | import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; | ||
| 17 | |||
| 18 | public class DependencyGraphTest { | ||
| 19 | |||
| 20 | private OWLOntology getOntology() throws OWLOntologyCreationException { | ||
| 21 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 22 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 23 | OWLOntology ontology = manager.createOntology(); | ||
| 24 | |||
| 25 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 26 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 27 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 28 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 29 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); | ||
| 30 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 31 | |||
| 32 | // Class assertions | ||
| 33 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, a)); // HardWorkingStudent(a) | ||
| 34 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, b)); // HardWorkingStudent(b) | ||
| 35 | |||
| 36 | // Minimum cardinality axiom | ||
| 37 | manager.addAxiom(ontology, | ||
| 38 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 39 | factory.getOWLObjectMinCardinality(3, | ||
| 40 | takesCourse))); | ||
| 41 | return ontology; | ||
| 42 | } | ||
| 43 | |||
| 44 | @Test | ||
| 45 | public void test() throws OWLOntologyCreationException { | ||
| 46 | OWLOntology ontology = getOntology(); | ||
| 47 | Graph graph = new Graph(ontology); | ||
| 48 | DependencyGraph dependencyGraph = new DependencyGraph(graph); | ||
| 49 | |||
| 50 | HashSet<NodeTuple> tuples = new HashSet<>(); | ||
| 51 | tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "a")), Individual.create(String.format(TestUtil.NS, "a"))}))); | ||
| 52 | tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "a")), Individual.create(String.format(TestUtil.NS, "b"))}))); | ||
| 53 | tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "b")), Individual.create(String.format(TestUtil.NS, "a"))}))); | ||
| 54 | tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "b")), Individual.create(String.format(TestUtil.NS, "b"))}))); | ||
| 55 | |||
| 56 | dependencyGraph.build(tuples); | ||
| 57 | |||
| 58 | Assert.assertTrue(dependencyGraph.getTopologicalOrder().size() >= 2); | ||
| 59 | } | ||
| 60 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/BugTests.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/BugTests.java new file mode 100644 index 0000000..3f14ec7 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | |||
| @@ -0,0 +1,240 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 4 | import org.semanticweb.owlapi.model.*; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.nio.file.Files; | ||
| 15 | import java.nio.file.Paths; | ||
| 16 | |||
| 17 | import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; | ||
| 18 | |||
| 19 | public class BugTests { | ||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | @Test | ||
| 24 | public void minimumCardinalityAxiom2() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Build test ontology | ||
| 28 | * */ | ||
| 29 | |||
| 30 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 31 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 32 | OWLOntology ontology = manager.createOntology(); | ||
| 33 | |||
| 34 | // OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 35 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 36 | // OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 37 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 38 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 40 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 41 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 42 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); | ||
| 43 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 44 | |||
| 45 | // Class assertions | ||
| 46 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, a)); // HardWorkingStudent(a) | ||
| 47 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, b)); // HardWorkingStudent(b) | ||
| 48 | |||
| 49 | // Minimum cardinality axiom | ||
| 50 | manager.addAxiom(ontology, | ||
| 51 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 52 | factory.getOWLObjectMinCardinality(3, | ||
| 53 | takesCourse))); | ||
| 54 | |||
| 55 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 56 | |||
| 57 | /* | ||
| 58 | * Test one query | ||
| 59 | * */ | ||
| 60 | |||
| 61 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 62 | pagoda.loadOntology(ontology); | ||
| 63 | if (pagoda.preprocess()) { | ||
| 64 | String query = "select distinct ?x ?y " + | ||
| 65 | " where { " | ||
| 66 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 67 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 68 | " }"; | ||
| 69 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 70 | int count = 0; | ||
| 71 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 72 | ans = answers.getTuple(); | ||
| 73 | TestUtil.logInfo(ans); | ||
| 74 | count++; | ||
| 75 | } | ||
| 76 | Assert.assertEquals(count, 2); | ||
| 77 | } | ||
| 78 | pagoda.dispose(); | ||
| 79 | } | ||
| 80 | |||
| 81 | // @Test | ||
| 82 | public void minimumCardinalityAxiom() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Build test ontology | ||
| 86 | * */ | ||
| 87 | |||
| 88 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 89 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 90 | OWLOntology ontology = manager.createOntology(); | ||
| 91 | |||
| 92 | OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 93 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 94 | OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 95 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 96 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 97 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 98 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 99 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 100 | OWLNamedIndividual c1 = factory.getOWLNamedIndividual(getEntityIRI("c1")); | ||
| 101 | OWLNamedIndividual c2 = factory.getOWLNamedIndividual(getEntityIRI("c2")); | ||
| 102 | OWLNamedIndividual c3 = factory.getOWLNamedIndividual(getEntityIRI("c3")); | ||
| 103 | OWLNamedIndividual d1 = factory.getOWLNamedIndividual(getEntityIRI("d1")); | ||
| 104 | OWLNamedIndividual d2 = factory.getOWLNamedIndividual(getEntityIRI("d2")); | ||
| 105 | OWLNamedIndividual d3 = factory.getOWLNamedIndividual(getEntityIRI("d3")); | ||
| 106 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); | ||
| 107 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 108 | |||
| 109 | // Class assertions | ||
| 110 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, a)); // Student(a) | ||
| 111 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, b)); // Student(b) | ||
| 112 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c1)); // Course(c1) | ||
| 113 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c2)); // Course(c2) | ||
| 114 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c3)); // Course(c3) | ||
| 115 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d1)); // Course(d1) | ||
| 116 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d2)); // Course(d2) | ||
| 117 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d3)); // Course(d3) | ||
| 118 | |||
| 119 | // Role assertions | ||
| 120 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c1)); // takesCourse(a,c1) | ||
| 121 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c2)); // takesCourse(a,c2) | ||
| 122 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c3)); // takesCourse(a,c3) | ||
| 123 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d1)); // takesCourse(b,d1) | ||
| 124 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d2)); // takesCourse(b,d2) | ||
| 125 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d3)); // takesCourse(b,d3) | ||
| 126 | |||
| 127 | // Minimum cardinality axiom | ||
| 128 | manager.addAxiom(ontology, | ||
| 129 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 130 | factory.getOWLObjectMinCardinality(3, | ||
| 131 | takesCourse))); | ||
| 132 | |||
| 133 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 134 | |||
| 135 | /* | ||
| 136 | * Test one query | ||
| 137 | * */ | ||
| 138 | |||
| 139 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 140 | pagoda.loadOntology(ontology); | ||
| 141 | if (pagoda.preprocess()) { | ||
| 142 | String query = "select distinct ?x ?y " + | ||
| 143 | " where { " | ||
| 144 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 145 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 146 | " }"; | ||
| 147 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 148 | int count = 0; | ||
| 149 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 150 | ans = answers.getTuple(); | ||
| 151 | TestUtil.logInfo(ans); | ||
| 152 | count++; | ||
| 153 | } | ||
| 154 | Assert.assertEquals(count, 2); | ||
| 155 | } | ||
| 156 | pagoda.dispose(); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Bug: the relevant ontology is not a subset of the original one. | ||
| 161 | * | ||
| 162 | * @throws OWLOntologyCreationException | ||
| 163 | * @throws IOException | ||
| 164 | * @throws OWLOntologyStorageException | ||
| 165 | */ | ||
| 166 | // @Test | ||
| 167 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 168 | |||
| 169 | /* | ||
| 170 | * Build test ontology | ||
| 171 | * */ | ||
| 172 | |||
| 173 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 174 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 175 | OWLOntology ontology = manager.createOntology(); | ||
| 176 | |||
| 177 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 178 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 179 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 180 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 181 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 182 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 183 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 184 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "R"))); | ||
| 185 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 186 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "P"))); | ||
| 187 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 188 | |||
| 189 | // Class assertions | ||
| 190 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, a)); // A(a) | ||
| 191 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, b)); // A(b) | ||
| 192 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, c, a)); // P(c,a) | ||
| 193 | |||
| 194 | // Axioms | ||
| 195 | // subsetOf(A someValuesFrom(R owl:Thing)) | ||
| 196 | manager.addAxiom(ontology, | ||
| 197 | factory.getOWLSubClassOfAxiom(classA, | ||
| 198 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 199 | factory.getOWLThing()))); | ||
| 200 | |||
| 201 | // inverseFunctional(R) | ||
| 202 | manager.addAxiom(ontology, | ||
| 203 | factory.getOWLInverseFunctionalObjectPropertyAxiom(roleR)); | ||
| 204 | |||
| 205 | // subsetOf(someValuesFrom(inverseOf(P) owl:thing) B) | ||
| 206 | manager.addAxiom(ontology, | ||
| 207 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 208 | factory.getOWLThing()), | ||
| 209 | classB)); | ||
| 210 | /* | ||
| 211 | * Save the ontology | ||
| 212 | * */ | ||
| 213 | |||
| 214 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 215 | |||
| 216 | /* | ||
| 217 | * Test one query | ||
| 218 | * */ | ||
| 219 | |||
| 220 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 221 | pagoda.loadOntology(ontology); | ||
| 222 | if(pagoda.preprocess()) { | ||
| 223 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 224 | "select distinct ?x" + | ||
| 225 | " where { " | ||
| 226 | + " ?x rdf:type " + classB + | ||
| 227 | " }"; | ||
| 228 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 229 | System.out.println(queryRecord); | ||
| 230 | pagoda.evaluate(queryRecord); | ||
| 231 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 232 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 233 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 234 | ans = answers.getTuple(); | ||
| 235 | TestUtil.logInfo(ans); | ||
| 236 | } | ||
| 237 | } | ||
| 238 | pagoda.dispose(); | ||
| 239 | } | ||
| 240 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/CostEvaluation.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/CostEvaluation.java new file mode 100644 index 0000000..01e8203 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/CostEvaluation.java | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 4 | import org.testng.annotations.Test; | ||
| 5 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 6 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 7 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner.Type; | ||
| 8 | import uk.ac.ox.cs.pagoda.tester.PagodaTester; | ||
| 9 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 12 | |||
| 13 | public class CostEvaluation { | ||
| 14 | |||
| 15 | @Test | ||
| 16 | public void lubm100() { | ||
| 17 | int number = 1; | ||
| 18 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 19 | PagodaTester.main( | ||
| 20 | TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), | ||
| 21 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), | ||
| 22 | TestUtil.combinePaths(ontoDir, "lubm/queries/test_all_pagoda.sparql") | ||
| 23 | ); | ||
| 24 | // AllTests.copy("output/log4j.log", "results-backup/jair/lubm" + number + ".out"); | ||
| 25 | } | ||
| 26 | |||
| 27 | public void lubm1000() { | ||
| 28 | int number = 1000; | ||
| 29 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 30 | String[] args = new String[] { | ||
| 31 | TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), | ||
| 32 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm" + number + ".ttl"), | ||
| 33 | TestUtil.combinePaths(ontoDir, "lubm/queries/test_all_pagoda.sparql") | ||
| 34 | }; | ||
| 35 | OWLOntology ontology = OWLHelper.loadOntology(args[0]); | ||
| 36 | QueryReasoner reasoner = QueryReasoner.getInstance(Type.ELHOU, ontology, true, true); | ||
| 37 | Timer t = new Timer(); | ||
| 38 | reasoner.loadOntology(ontology); | ||
| 39 | reasoner.importData(args[1]); | ||
| 40 | if (!reasoner.preprocess()) | ||
| 41 | return ; | ||
| 42 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | ||
| 43 | |||
| 44 | reasoner.evaluate(reasoner.getQueryManager().collectQueryRecords(args[2])); | ||
| 45 | // AllTests.copy("output/log4j.log", "results-backup/jair/lubm" + number + ".out"); | ||
| 46 | } | ||
| 47 | |||
| 48 | @Test | ||
| 49 | public void uobm5() { | ||
| 50 | int number = 1; | ||
| 51 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 52 | String[] args = new String[] { | ||
| 53 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 54 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), | ||
| 55 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard_all_pagoda.sparql") | ||
| 56 | }; | ||
| 57 | PagodaTester.main(args); | ||
| 58 | // AllTests.copy("output/log4j.log", "results-backup/jair/uobm" + number + ".out"); | ||
| 59 | } | ||
| 60 | |||
| 61 | public void uobm100() { | ||
| 62 | int number = 200; | ||
| 63 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 64 | String[] args = new String[] { | ||
| 65 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 66 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), | ||
| 67 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard_group3_all.sparql") | ||
| 68 | }; | ||
| 69 | PagodaTester.main(args); | ||
| 70 | // AllTests.copy("output/log4j.log", "results-backup/jair/uobm" + number + ".out"); | ||
| 71 | } | ||
| 72 | |||
| 73 | public void uobm500() { | ||
| 74 | int number = 500; | ||
| 75 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 76 | String[] args = new String[] { | ||
| 77 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 78 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm" + number + ".ttl"), | ||
| 79 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard_all_pagoda.sparql") | ||
| 80 | }; | ||
| 81 | |||
| 82 | OWLOntology ontology = OWLHelper.loadOntology(args[0]); | ||
| 83 | QueryReasoner reasoner = QueryReasoner.getInstance(Type.ELHOU, ontology, true, true); | ||
| 84 | Timer t = new Timer(); | ||
| 85 | reasoner.loadOntology(ontology); | ||
| 86 | reasoner.importData(args[1]); | ||
| 87 | if (!reasoner.preprocess()) | ||
| 88 | return ; | ||
| 89 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | ||
| 90 | |||
| 91 | reasoner.evaluate(reasoner.getQueryManager().collectQueryRecords(args[2])); | ||
| 92 | // AllTests.copy("output/log4j.log", "results-backup/jair/uobm" + number + ".out"); | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | public static void main(String... args) { | ||
| 97 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 98 | args = new String[] { | ||
| 99 | TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), | ||
| 100 | TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), | ||
| 101 | TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql") | ||
| 102 | }; | ||
| 103 | |||
| 104 | OWLOntology ontology = OWLHelper.loadOntology(args[0]); | ||
| 105 | QueryReasoner reasoner = QueryReasoner.getInstance(Type.ELHOU, ontology, true, true); | ||
| 106 | Timer t = new Timer(); | ||
| 107 | reasoner.loadOntology(ontology); | ||
| 108 | reasoner.importData(args[1]); | ||
| 109 | if (!reasoner.preprocess()) | ||
| 110 | return ; | ||
| 111 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | ||
| 112 | |||
| 113 | reasoner.evaluate(reasoner.getQueryManager().collectQueryRecords(args[2])); | ||
| 114 | } | ||
| 115 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java new file mode 100644 index 0000000..18f6cf9 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_PAGOdA.java | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.tester.PagodaTester; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 6 | |||
| 7 | import java.io.IOException; | ||
| 8 | |||
| 9 | public class JAIR_PAGOdA { | ||
| 10 | |||
| 11 | public static void main(String... args) { | ||
| 12 | try { | ||
| 13 | new JAIR_PAGOdA().lubm1(); | ||
| 14 | } catch(IOException e) { | ||
| 15 | e.printStackTrace(); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | @Test | ||
| 20 | public void lubm1() throws IOException { | ||
| 21 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 22 | String[] args = new String[] { | ||
| 23 | TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), | ||
| 24 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), | ||
| 25 | TestUtil.combinePaths(ontoDir, "lubm/queries/answersCorrectness.sparql") | ||
| 26 | }; | ||
| 27 | PagodaTester.main(args); | ||
| 28 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda"); | ||
| 29 | } | ||
| 30 | |||
| 31 | @Test | ||
| 32 | public void lubm1_conj() throws IOException { | ||
| 33 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 34 | String[] args = new String[] { | ||
| 35 | TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), | ||
| 36 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), | ||
| 37 | TestUtil.combinePaths(ontoDir, "lubm/queries/test_pellet.sparql") | ||
| 38 | }; | ||
| 39 | PagodaTester.main(args); | ||
| 40 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda_conj"); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Test | ||
| 44 | public void lubm1_rolledUp() throws IOException { | ||
| 45 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 46 | PagodaTester.main( | ||
| 47 | "/home/yzhou/backup/20141212/univ-bench-queries.owl", | ||
| 48 | TestUtil.combinePaths(ontoDir, "lubm/data/lubm1.ttl"), | ||
| 49 | TestUtil.combinePaths(ontoDir, "lubm/queries/atomic_lubm.sparql") | ||
| 50 | ); | ||
| 51 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/pagoda_rolledUp"); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test | ||
| 55 | public void uobm1() throws IOException { | ||
| 56 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 57 | String[] args = new String[] { | ||
| 58 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 59 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), | ||
| 60 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") | ||
| 61 | }; | ||
| 62 | PagodaTester.main(args); | ||
| 63 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda"); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Test | ||
| 67 | public void uobm1_conj() throws IOException { | ||
| 68 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 69 | String[] args = new String[] { | ||
| 70 | TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), | ||
| 71 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), | ||
| 72 | TestUtil.combinePaths(ontoDir, "uobm/queries/standard_pellet.sparql") | ||
| 73 | }; | ||
| 74 | PagodaTester.main(args); | ||
| 75 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda_conj"); | ||
| 76 | } | ||
| 77 | |||
| 78 | @Test | ||
| 79 | public void uobm1_rolledUp() { | ||
| 80 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 81 | String[] args = new String[] { | ||
| 82 | "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl", | ||
| 83 | TestUtil.combinePaths(ontoDir, "uobm/data/uobm1.ttl"), | ||
| 84 | TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") | ||
| 85 | }; | ||
| 86 | PagodaTester.main(args); | ||
| 87 | // TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/pagoda_rolledUp"); | ||
| 88 | } | ||
| 89 | |||
| 90 | @Test | ||
| 91 | public void fly() { | ||
| 92 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 93 | String[] args = new String[] { | ||
| 94 | TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), | ||
| 95 | null, | ||
| 96 | TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") | ||
| 97 | }; | ||
| 98 | PagodaTester.main(args); | ||
| 99 | // TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda"); | ||
| 100 | } | ||
| 101 | |||
| 102 | @Test | ||
| 103 | public void fly_conj() throws IOException { | ||
| 104 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 105 | String[] args = new String[] { | ||
| 106 | TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl"), | ||
| 107 | null, | ||
| 108 | TestUtil.combinePaths(ontoDir, "fly/queries/fly_pellet.sparql") | ||
| 109 | }; | ||
| 110 | PagodaTester.main(args); | ||
| 111 | TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda_conj"); | ||
| 112 | } | ||
| 113 | |||
| 114 | public void fly_rolledUp() { | ||
| 115 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 116 | PagodaTester.main( | ||
| 117 | // TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", | ||
| 118 | TestUtil.combinePaths(ontoDir, "fly/fly-all-in-one_rolledUp.owl"), | ||
| 119 | null, | ||
| 120 | TestUtil.combinePaths(ontoDir, "fly/queries/fly_atomic.sparql") | ||
| 121 | ); | ||
| 122 | // TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/fly/pagoda_rolledUp"); | ||
| 123 | } | ||
| 124 | |||
| 125 | public void dbpedia() { | ||
| 126 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 127 | PagodaTester.main( | ||
| 128 | TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), | ||
| 129 | TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), | ||
| 130 | TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql"), | ||
| 131 | "dbpedia.ans" | ||
| 132 | ); | ||
| 133 | |||
| 134 | // TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/dbpedia/pagoda"); | ||
| 135 | } | ||
| 136 | |||
| 137 | public void npd() { | ||
| 138 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 139 | PagodaTester.main( | ||
| 140 | TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), | ||
| 141 | TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), | ||
| 142 | TestUtil.combinePaths(ontoDir, "npd/queries/atomic_ground.sparql") | ||
| 143 | , "npd.ans" | ||
| 144 | ); | ||
| 145 | |||
| 146 | // TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/npd/pagoda"); | ||
| 147 | } | ||
| 148 | |||
| 149 | public void reactome() throws IOException { | ||
| 150 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 151 | PagodaTester.main( | ||
| 152 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), | ||
| 153 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl"), | ||
| 154 | // null, | ||
| 155 | // TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/atomic_ground.sparql") | ||
| 156 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/example.sparql") | ||
| 157 | , "pagoda_reactome.ans" | ||
| 158 | ); | ||
| 159 | TestUtil.copyFile("log4j.log", "output/jair/pagoda_reactome.example"); | ||
| 160 | |||
| 161 | // TestUtil.copyFile(("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/pagoda_10p"); | ||
| 162 | } | ||
| 163 | |||
| 164 | public void chembl() throws IOException { | ||
| 165 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 166 | PagodaTester.main( | ||
| 167 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), | ||
| 168 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/graph sampling/sample_1.nt"), | ||
| 169 | // TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") | ||
| 170 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/example.sparql") | ||
| 171 | , "pagoda_chembl.ans" | ||
| 172 | ); | ||
| 173 | TestUtil.copyFile("log4j.log", "output/jair/pagoda_chembl.example"); | ||
| 174 | // TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/pagoda_1p"); | ||
| 175 | } | ||
| 176 | |||
| 177 | public void uniprot() throws IOException { | ||
| 178 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 179 | PagodaTester.main( | ||
| 180 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat-processed.owl"), | ||
| 181 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/graph sampling/sample_1.nt"), | ||
| 182 | // null, | ||
| 183 | // TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") | ||
| 184 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/example.sparql") | ||
| 185 | , "pagoda_uniprot.ans" | ||
| 186 | ); | ||
| 187 | TestUtil.copyFile("log4j.log", "output/jair/pagoda_uniprot.example"); | ||
| 188 | // TestUtil.copyFile("output/log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/pagoda_1p"); | ||
| 189 | } | ||
| 190 | |||
| 191 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java new file mode 100644 index 0000000..01f3568 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/JAIR_Scalability.java | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.tester.PagodaTester; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 7 | |||
| 8 | import java.io.IOException; | ||
| 9 | |||
| 10 | public class JAIR_Scalability { | ||
| 11 | |||
| 12 | private static final String date = "_0123"; | ||
| 13 | |||
| 14 | public static void main(String... args) throws IOException { | ||
| 15 | PagodaProperties.shellModeDefault = true; | ||
| 16 | new JAIR_Scalability().testUniProt(50, false); | ||
| 17 | } | ||
| 18 | |||
| 19 | @Test | ||
| 20 | public void reactome() throws IOException { | ||
| 21 | testReactome(10, false); | ||
| 22 | } | ||
| 23 | |||
| 24 | @Test | ||
| 25 | public void chembl() throws IOException { | ||
| 26 | testChEMBL(1, false); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Test | ||
| 30 | public void uniprot() throws IOException { | ||
| 31 | testUniProt(1, false); | ||
| 32 | } | ||
| 33 | |||
| 34 | public void testReactome(int percentage, boolean save) throws IOException { | ||
| 35 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 36 | String[] args = new String[] { | ||
| 37 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), | ||
| 38 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/simplifed_sample_" + percentage + ".ttl"), | ||
| 39 | TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/answersCorrectness.sparql") | ||
| 40 | , "reactome.ans" | ||
| 41 | }; | ||
| 42 | if (percentage == 10) | ||
| 43 | args[1] = args[1].replace("simplifed", "reactome"); | ||
| 44 | |||
| 45 | PagodaTester.main(args); | ||
| 46 | if (save) | ||
| 47 | TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/pagoda_" + percentage + "p" + date); | ||
| 48 | } | ||
| 49 | |||
| 50 | public void testChEMBL(int percentage, boolean save) throws IOException { | ||
| 51 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 52 | String[] args = new String[] { | ||
| 53 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), | ||
| 54 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/sample_" + percentage + ".nt"), | ||
| 55 | // TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") | ||
| 56 | TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/answersCorrectness.sparql") | ||
| 57 | , "chembl.ans" | ||
| 58 | }; | ||
| 59 | if (percentage == 1 || percentage == 10 || percentage == 50) | ||
| 60 | args[1] = args[1].replace("chembl", "chembl/graph sampling"); | ||
| 61 | else | ||
| 62 | if (percentage == 100) | ||
| 63 | args[1] = "/home/yzhou/RDFData/ChEMBL/facts/ChEMBL.ttl"; | ||
| 64 | |||
| 65 | PagodaTester.main(args); | ||
| 66 | if (save) | ||
| 67 | TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/pagoda_" + percentage + "p" + date); | ||
| 68 | } | ||
| 69 | |||
| 70 | public void testUniProt(int percentage, boolean save) throws IOException { | ||
| 71 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 72 | String[] args = new String[] { | ||
| 73 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat-processed.owl"), | ||
| 74 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/sample_" + percentage + ".nt"), | ||
| 75 | // TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") | ||
| 76 | TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/answersCorrectness.sparql") | ||
| 77 | , "uniprot.ans" | ||
| 78 | }; | ||
| 79 | |||
| 80 | if (percentage == 1 || percentage == 10 || percentage == 50) | ||
| 81 | args[1] = args[1].replace("uniprot", "uniprot/graph sampling"); | ||
| 82 | else | ||
| 83 | if (percentage == 100) | ||
| 84 | args[1] = "/home/yzhou/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/data/uniprot_cleaned.nt"; | ||
| 85 | |||
| 86 | PagodaTester.main(args); | ||
| 87 | if (save) | ||
| 88 | TestUtil.copyFile("log4j.log", "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/pagoda_" + percentage + "p" + date); | ||
| 89 | } | ||
| 90 | |||
| 91 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java new file mode 100644 index 0000000..3551b9b --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/LightEvaluation.java | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | |||
| 5 | import java.io.IOException; | ||
| 6 | |||
| 7 | @Deprecated | ||
| 8 | public class LightEvaluation { | ||
| 9 | |||
| 10 | @Test | ||
| 11 | public void evaluation() throws IOException { | ||
| 12 | new TestPagodaUOBM().answersCorrectness(1); | ||
| 13 | new TestPagodaLUBM().answersCorrectness(100); | ||
| 14 | // new TestPagodaFLY().answersCorrectness(); | ||
| 15 | new TestPagodaDBPedia().answersCorrectness(); | ||
| 16 | new TestPagodaNPD().testNPDwithoutDataType(); | ||
| 17 | } | ||
| 18 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/MadeUpCases.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/MadeUpCases.java new file mode 100644 index 0000000..3d154cb --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/MadeUpCases.java | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 4 | import org.semanticweb.owlapi.model.*; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 11 | |||
| 12 | import java.io.IOException; | ||
| 13 | |||
| 14 | import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; | ||
| 15 | |||
| 16 | public class MadeUpCases { | ||
| 17 | |||
| 18 | @Test(groups = {"existential"}) | ||
| 19 | public void someTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Build test ontology | ||
| 23 | * */ | ||
| 24 | |||
| 25 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 26 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 27 | OWLOntology ontology = manager.createOntology(); | ||
| 28 | |||
| 29 | OWLClass A1 = factory.getOWLClass(getEntityIRI("A1")); | ||
| 30 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A1)); | ||
| 31 | OWLClass A2 = factory.getOWLClass(getEntityIRI("A2")); | ||
| 32 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A2)); | ||
| 33 | OWLClass A3 = factory.getOWLClass(getEntityIRI("A3")); | ||
| 34 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A3)); | ||
| 35 | OWLClass A4 = factory.getOWLClass(getEntityIRI("A4")); | ||
| 36 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A4)); | ||
| 37 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 38 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 39 | OWLObjectProperty R = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "R"))); | ||
| 40 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(R)); | ||
| 41 | |||
| 42 | // Class assertions | ||
| 43 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A1, a)); | ||
| 44 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A1, b)); | ||
| 45 | |||
| 46 | // Minimum cardinality axiom | ||
| 47 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A1, factory.getOWLObjectSomeValuesFrom(R, A2))); | ||
| 48 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A2, factory.getOWLObjectSomeValuesFrom(R, A3))); | ||
| 49 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A3, factory.getOWLObjectSomeValuesFrom(R, A4))); | ||
| 50 | manager.addAxiom(ontology, factory.getOWLTransitiveObjectPropertyAxiom(R)); | ||
| 51 | |||
| 52 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 53 | |||
| 54 | /* | ||
| 55 | * Test one query | ||
| 56 | * */ | ||
| 57 | |||
| 58 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 59 | pagoda.loadOntology(ontology); | ||
| 60 | if (pagoda.preprocess()) { | ||
| 61 | String query = "select distinct ?x ?y " + | ||
| 62 | " where { " | ||
| 63 | + " ?x <" + R.toStringID() + "> _:z . " | ||
| 64 | + " ?y <" + R.toStringID() + "> _:z " + | ||
| 65 | " }"; | ||
| 66 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 67 | int count = 0; | ||
| 68 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 69 | ans = answers.getTuple(); | ||
| 70 | TestUtil.logInfo(ans); | ||
| 71 | count++; | ||
| 72 | } | ||
| 73 | Assert.assertEquals(count, 2); | ||
| 74 | } | ||
| 75 | pagoda.dispose(); | ||
| 76 | } | ||
| 77 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java new file mode 100644 index 0000000..2fc682b --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java | |||
| @@ -0,0 +1,269 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 4 | import org.semanticweb.owlapi.model.*; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.nio.file.Files; | ||
| 15 | import java.nio.file.Paths; | ||
| 16 | |||
| 17 | public class SkolemisationTests { | ||
| 18 | |||
| 19 | public static final String NS = "http://example.org/test#%s"; | ||
| 20 | |||
| 21 | private IRI getEntityIRI(String name) { | ||
| 22 | return IRI.create(String.format(NS, name)); | ||
| 23 | } | ||
| 24 | |||
| 25 | // @Test | ||
| 26 | public void commonSuccessorTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Build test ontology | ||
| 30 | * */ | ||
| 31 | |||
| 32 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 33 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 34 | OWLOntology ontology = manager.createOntology(); | ||
| 35 | |||
| 36 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 37 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 38 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 40 | OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 41 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 42 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 43 | OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 44 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 45 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 46 | |||
| 47 | // Class assertions | ||
| 48 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, c)); // A(c) | ||
| 49 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, d)); // A(d) | ||
| 50 | |||
| 51 | // Minimum cardinality axiom | ||
| 52 | manager.addAxiom(ontology, | ||
| 53 | factory.getOWLSubClassOfAxiom(classA, | ||
| 54 | factory.getOWLObjectUnionOf( | ||
| 55 | factory.getOWLObjectSomeValuesFrom(roleR, classB), | ||
| 56 | factory.getOWLObjectSomeValuesFrom(roleR, classC)))); | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Save the ontology | ||
| 60 | * */ | ||
| 61 | |||
| 62 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Test one query | ||
| 66 | * */ | ||
| 67 | |||
| 68 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 69 | pagoda.loadOntology(ontology); | ||
| 70 | if(pagoda.preprocess()) { | ||
| 71 | String queryStr = "select distinct ?x ?y " + | ||
| 72 | " where { " | ||
| 73 | + " ?x <" + roleR.toStringID() + "> _:z . " | ||
| 74 | + " ?y <" + roleR.toStringID() + "> _:z " + | ||
| 75 | " }"; | ||
| 76 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 77 | pagoda.evaluate(queryRecord); | ||
| 78 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 79 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 80 | int count = 0; | ||
| 81 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 82 | ans = answers.getTuple(); | ||
| 83 | TestUtil.logInfo(ans); | ||
| 84 | count++; | ||
| 85 | } | ||
| 86 | Assert.assertEquals(count, 2); | ||
| 87 | } | ||
| 88 | pagoda.dispose(); | ||
| 89 | } | ||
| 90 | |||
| 91 | // @Test | ||
| 92 | public void yTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 93 | |||
| 94 | /* | ||
| 95 | * Build test ontology | ||
| 96 | * */ | ||
| 97 | |||
| 98 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 99 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 100 | OWLOntology ontology = manager.createOntology(); | ||
| 101 | |||
| 102 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 103 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 104 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 105 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 106 | OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 107 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 108 | OWLClass classD = factory.getOWLClass(getEntityIRI("D")); | ||
| 109 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classD)); | ||
| 110 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 111 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 112 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 113 | OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 114 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 115 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 116 | OWLObjectProperty roleS = factory.getOWLObjectProperty(IRI.create(String.format(NS, "S"))); | ||
| 117 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleS)); | ||
| 118 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); | ||
| 119 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 120 | |||
| 121 | // Class assertions | ||
| 122 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classD, a)); // D(a) | ||
| 123 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classD, b)); // D(b) | ||
| 124 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleS, c, a)); // S(c,a) | ||
| 125 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, d, b)); // P(d,b) | ||
| 126 | |||
| 127 | // Axioms | ||
| 128 | // subsetOf(D someValuesFrom(R owl:Thing)) | ||
| 129 | manager.addAxiom(ontology, | ||
| 130 | factory.getOWLSubClassOfAxiom(classD, | ||
| 131 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 132 | factory.getOWLThing()))); | ||
| 133 | // subsetOf(someValuesFrom(inverseOf(S) owl:Thing) allValuesFrom(R A)) | ||
| 134 | manager.addAxiom(ontology, | ||
| 135 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleS.getInverseProperty(), | ||
| 136 | factory.getOWLThing()), | ||
| 137 | factory.getOWLObjectAllValuesFrom(roleR, classA))); | ||
| 138 | // subsetOf(someValuesFrom(inverseOf(P) owl:Thing) B) | ||
| 139 | manager.addAxiom(ontology, | ||
| 140 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 141 | factory.getOWLThing()), | ||
| 142 | classB)); | ||
| 143 | // subsetOf(someValuesFrom(R A) C) | ||
| 144 | manager.addAxiom(ontology, | ||
| 145 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleR, classA), classC)); | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Save the ontology | ||
| 149 | * */ | ||
| 150 | |||
| 151 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 152 | |||
| 153 | /* | ||
| 154 | * Test one query | ||
| 155 | * */ | ||
| 156 | |||
| 157 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 158 | pagoda.loadOntology(ontology); | ||
| 159 | if(pagoda.preprocess()) { | ||
| 160 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 161 | "select distinct ?x" + | ||
| 162 | " where { " | ||
| 163 | // + " ?x rdf:type " + classB + " ." | ||
| 164 | // + " ?x " + roleR + " "+ "_:y . " | ||
| 165 | + " ?x rdf:type " + classC + | ||
| 166 | " }"; | ||
| 167 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 168 | System.out.println(queryRecord); | ||
| 169 | pagoda.evaluate(queryRecord); | ||
| 170 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 171 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 172 | int count = 0; | ||
| 173 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 174 | ans = answers.getTuple(); | ||
| 175 | TestUtil.logInfo(ans); | ||
| 176 | count++; | ||
| 177 | } | ||
| 178 | // Assert.assertEquals(count, 1); | ||
| 179 | } | ||
| 180 | pagoda.dispose(); | ||
| 181 | } | ||
| 182 | |||
| 183 | @Test | ||
| 184 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 185 | |||
| 186 | /* | ||
| 187 | * Build test ontology | ||
| 188 | * */ | ||
| 189 | |||
| 190 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 191 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 192 | OWLOntology ontology = manager.createOntology(); | ||
| 193 | |||
| 194 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 195 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 196 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 197 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 198 | // OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 199 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 200 | // OWLClass classD = factory.getOWLClass(getEntityIRI("D")); | ||
| 201 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classD)); | ||
| 202 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 203 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 204 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 205 | // OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 206 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 207 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 208 | // OWLObjectProperty roleF = factory.getOWLObjectProperty(IRI.create(String.format(NS, "F"))); | ||
| 209 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleF)); | ||
| 210 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); | ||
| 211 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 212 | // OWLObjectProperty roleL = factory.getOWLObjectProperty(IRI.create(String.format(NS, "L"))); | ||
| 213 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleL)); | ||
| 214 | |||
| 215 | // Class assertions | ||
| 216 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, a)); // A(a) | ||
| 217 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, b)); // A(b) | ||
| 218 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, c, a)); // P(c,a) | ||
| 219 | |||
| 220 | // Axioms | ||
| 221 | // subsetOf(A someValuesFrom(R owl:Thing)) | ||
| 222 | manager.addAxiom(ontology, | ||
| 223 | factory.getOWLSubClassOfAxiom(classA, | ||
| 224 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 225 | factory.getOWLThing()))); | ||
| 226 | |||
| 227 | // inverseFunctional(R) | ||
| 228 | manager.addAxiom(ontology, | ||
| 229 | factory.getOWLInverseFunctionalObjectPropertyAxiom(roleR)); | ||
| 230 | |||
| 231 | // subsetOf(someValuesFrom(inverseOf(P) owl:thing) B) | ||
| 232 | manager.addAxiom(ontology, | ||
| 233 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 234 | factory.getOWLThing()), | ||
| 235 | classB)); | ||
| 236 | /* | ||
| 237 | * Save the ontology | ||
| 238 | * */ | ||
| 239 | |||
| 240 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 241 | |||
| 242 | /* | ||
| 243 | * Test one query | ||
| 244 | * */ | ||
| 245 | |||
| 246 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 247 | pagoda.loadOntology(ontology); | ||
| 248 | if(pagoda.preprocess()) { | ||
| 249 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 250 | "select distinct ?x" + | ||
| 251 | " where { " | ||
| 252 | + " ?x rdf:type " + classB + | ||
| 253 | " }"; | ||
| 254 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 255 | System.out.println(queryRecord); | ||
| 256 | pagoda.evaluate(queryRecord); | ||
| 257 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 258 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 259 | int count = 0; | ||
| 260 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 261 | ans = answers.getTuple(); | ||
| 262 | TestUtil.logInfo(ans); | ||
| 263 | count++; | ||
| 264 | } | ||
| 265 | // Assert.assertEquals(count, 1); | ||
| 266 | } | ||
| 267 | pagoda.dispose(); | ||
| 268 | } | ||
| 269 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java new file mode 100644 index 0000000..4b1ec6d --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import junit.framework.Assert; | ||
| 4 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 5 | import org.semanticweb.owlapi.model.*; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 11 | |||
| 12 | public class TestGapMappedToLower { | ||
| 13 | |||
| 14 | public static final String ns = "http://example.org/test#%s"; | ||
| 15 | |||
| 16 | public IRI getEntityIRI(String name) { | ||
| 17 | return IRI.create(String.format(ns, name)); | ||
| 18 | } | ||
| 19 | |||
| 20 | @Test | ||
| 21 | public void test() throws OWLOntologyCreationException { | ||
| 22 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 23 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 24 | OWLOntology ontology = manager.createOntology(); | ||
| 25 | OWLClass A = factory.getOWLClass(getEntityIRI("A")); | ||
| 26 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A)); | ||
| 27 | OWLClass B = factory.getOWLClass(getEntityIRI("B")); | ||
| 28 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(B)); | ||
| 29 | OWLClass C = factory.getOWLClass(getEntityIRI("C")); | ||
| 30 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(C)); | ||
| 31 | OWLClass A1 = factory.getOWLClass(getEntityIRI("A1")); | ||
| 32 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A1)); | ||
| 33 | OWLClass A2 = factory.getOWLClass(getEntityIRI("A2")); | ||
| 34 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A2)); | ||
| 35 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 36 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 37 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 38 | OWLObjectProperty r = factory.getOWLObjectProperty(IRI.create(String.format(ns, "r"))); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(r)); | ||
| 40 | |||
| 41 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A, a)); // A(a) | ||
| 42 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(B, b)); // B(b) | ||
| 43 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(C, c)); // C(c) | ||
| 44 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, b)); // r(a,b) | ||
| 45 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, c)); // r(a,c) | ||
| 46 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A, factory.getOWLObjectUnionOf(A1, A2))); // A \sqsubseteq A1 \sqcup A2 | ||
| 47 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A1, factory.getOWLObjectMaxCardinality(1, r))); // A1 \sqsubseteq \leq 1 r.\top | ||
| 48 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A2, factory.getOWLObjectMaxCardinality(1, r))); // A2 \sqsubseteq \leq 1 r.\top | ||
| 49 | |||
| 50 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 51 | pagoda.loadOntology(ontology); | ||
| 52 | if (pagoda.preprocess()) { | ||
| 53 | String sparql = "select ?x where { " | ||
| 54 | + "?x <" + r.toStringID() + "> ?y . " | ||
| 55 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + B.toStringID() + "> . " | ||
| 56 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + C.toStringID() + "> . } "; | ||
| 57 | AnswerTuples rs = pagoda.evaluate(sparql); | ||
| 58 | int count = 0; | ||
| 59 | for (AnswerTuple ans; rs.isValid(); rs.moveNext()) { | ||
| 60 | ans = rs.getTuple(); | ||
| 61 | System.out.println(ans.getGroundTerm(0)); | ||
| 62 | ++count; | ||
| 63 | } | ||
| 64 | Assert.assertEquals(1, count); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaDBPedia.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaDBPedia.java new file mode 100644 index 0000000..3642147 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaDBPedia.java | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 6 | |||
| 7 | import java.io.IOException; | ||
| 8 | import java.nio.file.Paths; | ||
| 9 | |||
| 10 | public class TestPagodaDBPedia { | ||
| 11 | |||
| 12 | public static final String ANSWER_PATH = "~/TestPagodaDEBPedia.json"; | ||
| 13 | |||
| 14 | @Test | ||
| 15 | public void just_execute() throws IOException { | ||
| 16 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 17 | Pagoda pagoda = Pagoda.builder() | ||
| 18 | .ontology(Paths.get(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl")) | ||
| 19 | .data(Paths.get(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl")) | ||
| 20 | .query(Paths.get(ontoDir, "dbpedia/atomic.sparql")) | ||
| 21 | .answer(ANSWER_PATH) | ||
| 22 | .classify(true) | ||
| 23 | .hermit(true) | ||
| 24 | .build(); | ||
| 25 | pagoda.run(); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void answersCorrectness() { | ||
| 30 | // TODO implement | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java new file mode 100644 index 0000000..3eb956f --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 5 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 8 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 9 | |||
| 10 | import java.io.File; | ||
| 11 | import java.io.IOException; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.nio.file.Paths; | ||
| 14 | |||
| 15 | public class TestPagodaFLY { | ||
| 16 | |||
| 17 | // @Test(groups = {"light"}) | ||
| 18 | public void answersCorrectness_withGJFC() throws IOException { | ||
| 19 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 20 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 21 | new File(answers.toString()).deleteOnExit(); | ||
| 22 | Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-fly-with-GJ-FC-individuals.json"); | ||
| 23 | |||
| 24 | Pagoda pagoda = Pagoda.builder() | ||
| 25 | .ontology(Paths.get(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl")) | ||
| 26 | .query(Paths.get(ontoDir, "fly/queries/fly.sparql")) | ||
| 27 | .answer(answers) | ||
| 28 | .classify(false) | ||
| 29 | .build(); | ||
| 30 | |||
| 31 | pagoda.run(); | ||
| 32 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 33 | } | ||
| 34 | |||
| 35 | @Test(groups = {"light", "correctness"}) | ||
| 36 | public void answersCorrectness_rolledUp() throws IOException { | ||
| 37 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 38 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 39 | new File(answers.toString()).deleteOnExit(); | ||
| 40 | Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-fly-rolledup.json"); | ||
| 41 | |||
| 42 | Pagoda pagoda = Pagoda.builder() | ||
| 43 | .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) | ||
| 44 | .query(Paths.get(ontoDir, "fly/queries/fly_rolledUp.sparql")) | ||
| 45 | .answer(answers) | ||
| 46 | // .answer(Paths.get("/home/alessandro/Desktop/answers.json")) | ||
| 47 | .classify(false) | ||
| 48 | .build(); | ||
| 49 | |||
| 50 | pagoda.run(); | ||
| 51 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test(groups = {"light", "justExecute", "nonOriginal", "existential"}) | ||
| 55 | public void justExecute_newQueries() throws IOException { | ||
| 56 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 57 | |||
| 58 | Pagoda.builder() | ||
| 59 | // .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) | ||
| 60 | .ontology(Paths.get(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl")) | ||
| 61 | // .query(Paths.get(ontoDir, "fly/queries/fly_rolledUp.sparql")) | ||
| 62 | // .query(Paths.get(ontoDir, "fly/queries/new_queries.sparql")) | ||
| 63 | .query("/home/alessandro/Desktop/query-8.sparql") | ||
| 64 | // .answer(Paths.get("/home/alessandro/Desktop/answers.json")) | ||
| 65 | .classify(false) | ||
| 66 | .hermit(true) | ||
| 67 | .skolemDepth(3) | ||
| 68 | .skolem(PagodaProperties.SkolemUpperBoundOptions.BEFORE_SUMMARISATION) | ||
| 69 | .build() | ||
| 70 | .run(); | ||
| 71 | } | ||
| 72 | |||
| 73 | @Test(groups = {"comparison"}) | ||
| 74 | public void compare_newQueries() throws IOException { | ||
| 75 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 76 | |||
| 77 | Timer timer = new Timer(); | ||
| 78 | Pagoda.builder() | ||
| 79 | .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) | ||
| 80 | .query(Paths.get(ontoDir, "fly/queries/new_queries.sparql")) | ||
| 81 | .classify(false) | ||
| 82 | .hermit(true) | ||
| 83 | .skolem(PagodaProperties.SkolemUpperBoundOptions.AFTER_SUMMARISATION) // <----<< Skolem upper bound is ENABLED <<< | ||
| 84 | .build() | ||
| 85 | .run(); | ||
| 86 | double t1 = timer.duration(); | ||
| 87 | |||
| 88 | timer.reset(); | ||
| 89 | |||
| 90 | Pagoda.builder() | ||
| 91 | .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) | ||
| 92 | .query(Paths.get(ontoDir, "fly/queries/new_queries.sparql")) | ||
| 93 | .classify(false) | ||
| 94 | .hermit(true) | ||
| 95 | .skolem(PagodaProperties.SkolemUpperBoundOptions.DISABLED) // <----<< Skolem upper bound is DISABLED <<< | ||
| 96 | .build() | ||
| 97 | .run(); | ||
| 98 | double t2 = timer.duration(); | ||
| 99 | |||
| 100 | if(t1 < t2) | ||
| 101 | TestUtil.logInfo( | ||
| 102 | "Overall reasoning with Skolem upper bound was " + (int) (t2 / t1 * 100 - 100) + "x faster!"); | ||
| 103 | else | ||
| 104 | TestUtil.logInfo( | ||
| 105 | "Overall reasoning with Skolem upper bound was " + (int) (t1 / t2 * 100 - 100) + "x slower..."); | ||
| 106 | } | ||
| 107 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java new file mode 100644 index 0000000..019fafa --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 5 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 7 | |||
| 8 | import java.io.File; | ||
| 9 | import java.io.IOException; | ||
| 10 | import java.nio.file.Path; | ||
| 11 | import java.nio.file.Paths; | ||
| 12 | |||
| 13 | public class TestPagodaLUBM { | ||
| 14 | |||
| 15 | public void answersCorrectness(int number) throws IOException { | ||
| 16 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 17 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 18 | new File(answers.toString()).deleteOnExit(); | ||
| 19 | Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-lubm" + number + ".json"); | ||
| 20 | |||
| 21 | Pagoda pagoda = Pagoda.builder() | ||
| 22 | .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) | ||
| 23 | .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) | ||
| 24 | .query(Paths.get(ontoDir, "lubm/queries/test.sparql")) | ||
| 25 | .answer(answers) | ||
| 26 | .build(); | ||
| 27 | |||
| 28 | pagoda.run(); | ||
| 29 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Test(groups = {"light", "correctness"}) | ||
| 33 | public void answersCorrectness_1() throws IOException { | ||
| 34 | answersCorrectness(1); | ||
| 35 | } | ||
| 36 | |||
| 37 | public void justExecute_sygenia(int number) throws IOException { | ||
| 38 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 39 | // Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 40 | // new File(answers.toString()).deleteOnExit(); | ||
| 41 | // Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-lubm" + number + ".json"); | ||
| 42 | |||
| 43 | Pagoda pagoda = Pagoda.builder() | ||
| 44 | .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) | ||
| 45 | .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) | ||
| 46 | .query(Paths.get(ontoDir, "lubm/queries/lubm_sygenia.sparql")) | ||
| 47 | // .answer(answers) | ||
| 48 | .build(); | ||
| 49 | |||
| 50 | pagoda.run(); | ||
| 51 | // CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test(groups = {"sygenia"}) | ||
| 55 | public void justExecute_sygenia_1() throws IOException { | ||
| 56 | justExecute_sygenia(1); | ||
| 57 | } | ||
| 58 | |||
| 59 | public void justExecute_sygenia_allBlanks(int number) throws IOException { | ||
| 60 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 61 | // Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 62 | // new File(answers.toString()).deleteOnExit(); | ||
| 63 | // Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-lubm" + number + ".json"); | ||
| 64 | |||
| 65 | Pagoda pagoda = Pagoda.builder() | ||
| 66 | .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) | ||
| 67 | .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) | ||
| 68 | .query(Paths.get(ontoDir, "lubm/queries/lubm_sygenia_all-blanks.sparql")) | ||
| 69 | // .answer(answers) | ||
| 70 | .build(); | ||
| 71 | |||
| 72 | pagoda.run(); | ||
| 73 | // CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 74 | } | ||
| 75 | |||
| 76 | @Test(groups = {"sygenia"}) | ||
| 77 | public void justExecute_sygenia_1_allBlanks() throws IOException { | ||
| 78 | justExecute_sygenia_allBlanks(1); | ||
| 79 | } | ||
| 80 | |||
| 81 | @Test(groups = {"existential"}) | ||
| 82 | public void justExecute_feier() throws IOException { | ||
| 83 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 84 | |||
| 85 | Pagoda.builder() | ||
| 86 | .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) | ||
| 87 | .data(Paths.get(ontoDir, "lubm/data/lubm1.ttl")) | ||
| 88 | .query(Paths.get(ontoDir, "lubm/queries/queries_from_rules.sparql")) | ||
| 89 | .build() | ||
| 90 | .run(); | ||
| 91 | } | ||
| 92 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaNPD.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaNPD.java new file mode 100644 index 0000000..939ee6e --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaNPD.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 6 | |||
| 7 | import java.io.IOException; | ||
| 8 | import java.nio.file.Paths; | ||
| 9 | |||
| 10 | public class TestPagodaNPD { | ||
| 11 | |||
| 12 | public static final String ANSWER_PATH = "~/PagodaNPDWithoutDatatype.json"; | ||
| 13 | |||
| 14 | @Test | ||
| 15 | public void justExecuteNPDWithoutDataType() { | ||
| 16 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 17 | Pagoda pagoda = Pagoda.builder() | ||
| 18 | .ontology(Paths.get(ontoDir, "npd/npd-all-minus-datatype.owl")) | ||
| 19 | .data(Paths.get(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl")) | ||
| 20 | .query(Paths.get(ontoDir, "npd/queries/atomic.sparql")) | ||
| 21 | .answer(ANSWER_PATH) | ||
| 22 | .classify(true) | ||
| 23 | .hermit(true) | ||
| 24 | .build(); | ||
| 25 | pagoda.run(); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void testNPDwithoutDataType() throws IOException { | ||
| 30 | // TODO implement | ||
| 31 | } | ||
| 32 | |||
| 33 | @Test | ||
| 34 | public void testNPD() throws IOException { | ||
| 35 | // TODO implement | ||
| 36 | } | ||
| 37 | |||
| 38 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java new file mode 100644 index 0000000..8a8a596 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 6 | |||
| 7 | import java.io.IOException; | ||
| 8 | import java.nio.file.Paths; | ||
| 9 | |||
| 10 | public class TestPagodaReactome { | ||
| 11 | |||
| 12 | @Test(groups = {"justExecute"}) | ||
| 13 | public void justExecute() throws IOException { | ||
| 14 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 15 | |||
| 16 | Pagoda.builder() | ||
| 17 | .ontology(Paths.get(ontoDir, "reactome/biopax-level3-processed.owl")) | ||
| 18 | .data(Paths.get(ontoDir, "reactome/data/sample_10.ttl")) | ||
| 19 | .query(Paths.get(ontoDir, "reactome/test.sparql")) | ||
| 20 | .classify(true) | ||
| 21 | .hermit(true) | ||
| 22 | .build() | ||
| 23 | .run(); | ||
| 24 | } | ||
| 25 | |||
| 26 | @Test(groups = {"sygenia"}) | ||
| 27 | public void justExecute_sygenia() throws IOException { | ||
| 28 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 29 | |||
| 30 | Pagoda.builder() | ||
| 31 | .ontology(Paths.get(ontoDir, "reactome/biopax-level3-processed.owl")) | ||
| 32 | .data(Paths.get(ontoDir, "reactome/data/sample_10.ttl")) | ||
| 33 | .query(Paths.get(ontoDir, "reactome/reactome_sygenia_queries.sparql")) | ||
| 34 | .classify(true) | ||
| 35 | .hermit(true) | ||
| 36 | .build() | ||
| 37 | .run(); | ||
| 38 | } | ||
| 39 | |||
| 40 | @Test(groups = {"existential"}) | ||
| 41 | public void justExecute_existential() throws IOException { | ||
| 42 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 43 | |||
| 44 | Pagoda.builder() | ||
| 45 | .ontology(Paths.get(ontoDir, "reactome/biopax-level3-processed.owl")) | ||
| 46 | .data(Paths.get(ontoDir, "reactome/data/sample_10.ttl")) | ||
| 47 | .query(Paths.get(ontoDir, "reactome/existential_queries.sparql")) | ||
| 48 | // .query(Paths.get(ontoDir, "reactome/Queries_by_Feier-et-al.sparql")) | ||
| 49 | .build() | ||
| 50 | .run(); | ||
| 51 | } | ||
| 52 | |||
| 53 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java new file mode 100644 index 0000000..4dae223 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.testng.annotations.DataProvider; | ||
| 4 | import org.testng.annotations.Test; | ||
| 5 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 6 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 8 | |||
| 9 | import java.io.File; | ||
| 10 | import java.io.IOException; | ||
| 11 | import java.nio.file.Path; | ||
| 12 | import java.nio.file.Paths; | ||
| 13 | |||
| 14 | public class TestPagodaUOBM { | ||
| 15 | |||
| 16 | private static final int N_1 = 1; | ||
| 17 | private static final int N_2 = 4; | ||
| 18 | |||
| 19 | @DataProvider(name = "UOBMNumbers") | ||
| 20 | private static Object[][] UOBMNumbers() { | ||
| 21 | Integer[][] integers = new Integer[N_2 - N_1 + 1][1]; | ||
| 22 | for(int i = 0; i < N_2 - N_1 + 1; i++) | ||
| 23 | integers[i][0] = N_1 + i; | ||
| 24 | return integers; | ||
| 25 | } | ||
| 26 | |||
| 27 | @Test(groups = {"light", "correctness"}) | ||
| 28 | public void answersCorrectness_1() throws IOException { | ||
| 29 | answersCorrectness(1); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Test(groups = {"heavy", "correctness"}, dataProvider = "UOBMNumbers") | ||
| 33 | public void answersCorrectness(int number) throws IOException { | ||
| 34 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 35 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 36 | new File(answers.toString()).deleteOnExit(); | ||
| 37 | Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-uobm" + number + ".json"); | ||
| 38 | |||
| 39 | Pagoda pagoda = Pagoda.builder() | ||
| 40 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | ||
| 41 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) | ||
| 42 | .query(Paths.get(ontoDir, "uobm/queries/test.sparql")) | ||
| 43 | .answer(answers) | ||
| 44 | .build(); | ||
| 45 | |||
| 46 | pagoda.run(); | ||
| 47 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test(groups = {"sygenia"}) | ||
| 51 | public void answersCorrectness_sygenia_1() throws IOException { | ||
| 52 | answersCorrectness_sygenia(1); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Test(groups = {"heavy",}, dataProvider = "UOBMNumbers") | ||
| 56 | public void answersCorrectness_sygenia(int number) throws IOException { | ||
| 57 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 58 | // Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 59 | // new File(answers.toString()).deleteOnExit(); | ||
| 60 | // Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-uobm" + number + ".json"); | ||
| 61 | |||
| 62 | Pagoda pagoda = Pagoda.builder() | ||
| 63 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | ||
| 64 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) | ||
| 65 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia.sparql")) | ||
| 66 | .build(); | ||
| 67 | |||
| 68 | pagoda.run(); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test(groups = {"sygenia"}) | ||
| 72 | public void answersCorrectness_sygenia_allBlanks_1() throws IOException { | ||
| 73 | answersCorrectness_sygenia(1); | ||
| 74 | } | ||
| 75 | |||
| 76 | @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") | ||
| 77 | public void answersCorrectness_sygenia_allBlanks(int number) throws IOException { | ||
| 78 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 79 | |||
| 80 | Pagoda.builder() | ||
| 81 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | ||
| 82 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) | ||
| 83 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql")) | ||
| 84 | .build() | ||
| 85 | .run(); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test(groups = {"justExecute", "heavy", "nonOriginal", "existential"}) | ||
| 89 | public void justExecute_modifiedUOBM() throws IOException { | ||
| 90 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 91 | |||
| 92 | Pagoda.builder() | ||
| 93 | .ontology(Paths.get(ontoDir, "uobm_modified/univ-bench-dl-modified.owl")) | ||
| 94 | .data(Paths.get(ontoDir, "uobm_modified/data/uobm1.ttl")) | ||
| 95 | .query(Paths.get(ontoDir, "uobm_modified/queries/additional_queries.sparql")) | ||
| 96 | .build() | ||
| 97 | .run(); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test(groups = {"justExecute"}) | ||
| 101 | public void justExecute_additionalQueries() throws IOException { | ||
| 102 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 103 | |||
| 104 | Pagoda.builder() | ||
| 105 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | ||
| 106 | .data(Paths.get(ontoDir, "uobm/data/uobm1.ttl")) | ||
| 107 | .query(Paths.get(ontoDir, "uobm/queries/additional_queries.sparql")) | ||
| 108 | .build() | ||
| 109 | .run(); | ||
| 110 | } | ||
| 111 | |||
| 112 | @Test(groups = {"justExecute", "UOBM50"}) | ||
| 113 | public void justExecuteUOBM_50() throws IOException { | ||
| 114 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 115 | Pagoda.builder() | ||
| 116 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | ||
| 117 | .data(Paths.get(ontoDir, "uobm/data/uobm50.ttl")) | ||
| 118 | .query(Paths.get(ontoDir, "uobm/queries/test.sparql")) | ||
| 119 | .build() | ||
| 120 | .run(); | ||
| 121 | } | ||
| 122 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/hermit/TestRuleHelper.java b/src/test/java/uk/ac/ox/cs/pagoda/hermit/TestRuleHelper.java new file mode 100644 index 0000000..3a2cad8 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/hermit/TestRuleHelper.java | |||
| @@ -0,0 +1,319 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.hermit; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | import uk.ac.ox.cs.pagoda.MyPrefixes; | ||
| 5 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 6 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | ||
| 7 | |||
| 8 | import java.io.ByteArrayInputStream; | ||
| 9 | import java.io.InputStream; | ||
| 10 | import java.nio.charset.Charset; | ||
| 11 | |||
| 12 | public class TestRuleHelper { | ||
| 13 | |||
| 14 | @Test | ||
| 15 | public static void someTest() { | ||
| 16 | String prefixes = "PREFIX anony: <http://www.cs.ox.ac.uk/PAGOdA/skolemised#>\n" + | ||
| 17 | "PREFIX aux: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#>\n" + | ||
| 18 | "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" + | ||
| 19 | "PREFIX prefix0: <http://semantics.crl.ibm.com/univ-bench-dl.owl#>\n" + | ||
| 20 | "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + | ||
| 21 | "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + | ||
| 22 | "PREFIX ruleml: <http://www.w3.org/2003/11/ruleml#>\n" + | ||
| 23 | "PREFIX swrl: <http://www.w3.org/2003/11/swrl#>\n" + | ||
| 24 | "PREFIX swrlb: <http://www.w3.org/2003/11/swrlb#>\n" + | ||
| 25 | "PREFIX swrlx: <http://www.w3.org/2003/11/swrlx#>\n" + | ||
| 26 | "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"; | ||
| 27 | String rule = "owl:Nothing(?X) :- owl:Nothing2(?X).\n" + | ||
| 28 | "prefix0:WomanCollege(?X) :- prefix0:College(?X).\n" + | ||
| 29 | "owl:Nothing5(?X) :- prefix0:WomanCollege(?X), prefix0:hasStudent(?X,?Y), prefix0:Man(?Y).\n" + | ||
| 30 | "prefix0:SportsFan(?X) :- prefix0:Person(?X), prefix0:isCrazyAbout(?X,?Y), prefix0:Sports(?Y).\n" + | ||
| 31 | "prefix0:Organization(?X) :- prefix0:isAffiliateOf(?X,?Y).\n" + | ||
| 32 | "prefix0:Person(?X) :- prefix0:lastName(?X,?Y).\n" + | ||
| 33 | "owl:sameAs(?Y1,?Y2) :- prefix0:isHeadOf(?Y1,?X), prefix0:isHeadOf(?Y2,?X).\n" + | ||
| 34 | "prefix0:isMemberOf(?Y,?X) :- prefix0:hasMember(?X,?Y).\n" + | ||
| 35 | "prefix0:Person(?X) :- prefix0:hasMasterDegreeFrom(?X,?Y).\n" + | ||
| 36 | "prefix0:Person(?X) :- prefix0:TeachingAssistant(?X).\n" + | ||
| 37 | "prefix0:Employee(?X) :- prefix0:Person(?X), prefix0:worksFor(?X,?Y), prefix0:Organization(?Y).\n" + | ||
| 38 | "prefix0:FineArts(?X) :- prefix0:Media_Arts_And_ciencesClass(?X).\n" + | ||
| 39 | "prefix0:FineArts(?X) :- prefix0:Medieval_ArtsClass(?X).\n" + | ||
| 40 | "prefix0:Professor(?X) :- prefix0:Chair(?X).\n" + | ||
| 41 | "prefix0:Faculty(?Y) :- prefix0:isTaughtBy(?X,?Y).\n" + | ||
| 42 | "prefix0:worksFor(?X,anony:individual25) :- prefix0:Employee(?X).\n" + | ||
| 43 | "prefix0:Engineering(?X) :- prefix0:Chemical_EngineeringClass(?X).\n" + | ||
| 44 | "prefix0:BaseballClass(anony:individual1) :- prefix0:BaseballLover(?X).\n" + | ||
| 45 | "prefix0:Course(?Y) :- prefix0:listedCourse(?X,?Y).\n" + | ||
| 46 | "prefix0:worksFor(?X,?Y) :- prefix0:isHeadOf(?X,?Y).\n" + | ||
| 47 | "prefix0:Faculty(?X) :- prefix0:teacherOf(?X,?Y).\n" + | ||
| 48 | "prefix0:Course(?Y) :- prefix0:teachingAssistantOf(?X,?Y).\n" + | ||
| 49 | "owl:Nothing(?X) :- owl:Nothing1(?X).\n" + | ||
| 50 | "prefix0:Person(?X) :- prefix0:Student(?X).\n" + | ||
| 51 | "prefix0:isFriendOf(?Y,?X) :- prefix0:isFriendOf(?X,?Y).\n" + | ||
| 52 | "prefix0:Student(?X) :- prefix0:UndergraduateStudent(?X).\n" + | ||
| 53 | "prefix0:Person(?X) :- prefix0:BasketBallLover(?X).\n" + | ||
| 54 | "prefix0:Person(?Y) :- prefix0:hasSameHomeTownWith(?X,?Y).\n" + | ||
| 55 | "prefix0:Employee(?X) :- prefix0:Faculty(?X).\n" + | ||
| 56 | "prefix0:Insterest(?X) :- prefix0:Music(?X).\n" + | ||
| 57 | "owl:Nothing1(?X) :- prefix0:NonScienceStudent(?X), prefix0:hasMajor(?X,?Y), prefix0:Science(?Y).\n" + | ||
| 58 | "owl:sameAs(?Y1,?Y2) :- prefix0:isTaughtBy(?X,?Y1), prefix0:isTaughtBy(?X,?Y2).\n" + | ||
| 59 | "prefix0:hasStudent(?Y,?X) :- prefix0:isStudentOf(?X,?Y).\n" + | ||
| 60 | "prefix0:Student(?X) :- prefix0:ScienceStudent(?X).\n" + | ||
| 61 | "prefix0:like(?X,anony:individual7) :- prefix0:PeopleWithHobby(?X).\n" + | ||
| 62 | "prefix0:Publication(?X) :- prefix0:Article(?X).\n" + | ||
| 63 | "prefix0:isTaughtBy(?Y,?X) :- prefix0:teacherOf(?X,?Y).\n" + | ||
| 64 | "prefix0:isCrazyAbout(?X,anony:individual19) :- prefix0:TennisFan(?X).\n" + | ||
| 65 | "prefix0:Science(?X) :- prefix0:Marine_ScienceClass(?X).\n" + | ||
| 66 | "prefix0:SupportingStaff(?X) :- prefix0:SystemsStaff(?X).\n" + | ||
| 67 | "prefix0:hasStudent(?X,anony:individual10) :- prefix0:College(?X).\n" + | ||
| 68 | "prefix0:FineArts(?X) :- prefix0:Theatre_and_DanceClass(?X).\n" + | ||
| 69 | "prefix0:Organization(?Y) :- prefix0:subOrganizationOf(?X,?Y).\n" + | ||
| 70 | "prefix0:Engineering(?X) :- prefix0:Materical_Science_EngineeringClass(?X).\n" + | ||
| 71 | "prefix0:hasMember(?Y,?X) :- prefix0:isMemberOf(?X,?Y).\n" + | ||
| 72 | "prefix0:Student(?Y) :- prefix0:hasStudent(?X,?Y).\n" + | ||
| 73 | "owl:Nothing(?X) :- owl:Nothing5(?X).\n" + | ||
| 74 | "prefix0:isCrazyAbout(?X,anony:individual18) :- prefix0:SwimmingFan(?X).\n" + | ||
| 75 | "prefix0:Publication(?Y) :- prefix0:orgPublication(?X,?Y).\n" + | ||
| 76 | "prefix0:Chair(?X) :- prefix0:Person(?X), prefix0:isHeadOf(?X,?Y), prefix0:Department(?Y).\n" + | ||
| 77 | "prefix0:isStudentOf(?Y,?X) :- prefix0:hasStudent(?X,?Y).\n" + | ||
| 78 | "prefix0:Person(?X) :- prefix0:isAdvisedBy(?X,?Y).\n" + | ||
| 79 | "prefix0:hasMajor(?X,anony:individual2) :- prefix0:Student(?X).\n" + | ||
| 80 | "prefix0:Publication(?X) :- prefix0:publicationDate(?X,?Y).\n" + | ||
| 81 | "owl:Nothing(?X) :- owl:Nothing6(?X).\n" + | ||
| 82 | "prefix0:Director(?X) :- prefix0:Person(?X), prefix0:isHeadOf(?X,?Y), prefix0:Program(?Y).\n" + | ||
| 83 | "prefix0:Professor(?X) :- prefix0:AssociateProfessor(?X).\n" + | ||
| 84 | "prefix0:TeachingAssistant(?X) :- prefix0:Person(?X), prefix0:teachingAssistantOf(?X,?Y), prefix0:Course(?Y).\n" + | ||
| 85 | "prefix0:Research(?Y) :- prefix0:researchProject(?X,?Y).\n" + | ||
| 86 | "prefix0:TeachingAssistant(?X) :- prefix0:teachingAssistantOf(?X,?Y).\n" + | ||
| 87 | "prefix0:University(?X) :- prefix0:hasAlumnus(?X,?Y).\n" + | ||
| 88 | "prefix0:Faculty(?X) :- prefix0:Lecturer(?X).\n" + | ||
| 89 | "prefix0:isHeadOf(?X,anony:individual21) :- prefix0:Dean(?X).\n" + | ||
| 90 | "prefix0:like(?X,?Y) :- prefix0:isCrazyAbout(?X,?Y).\n" + | ||
| 91 | "prefix0:Person(?X) :- prefix0:hasSameHomeTownWith(?X,?Y).\n" + | ||
| 92 | "prefix0:Organization(?X) :- prefix0:orgPublication(?X,?Y).\n" + | ||
| 93 | "prefix0:Person(?Y) :- prefix0:hasMember(?X,?Y).\n" + | ||
| 94 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:LinguisticsClass(?X).\n" + | ||
| 95 | "prefix0:Engineering(?X) :- prefix0:Aeronautical_EngineeringClass(?X).\n" + | ||
| 96 | "owl:Nothing(?X) :- owl:Nothing3(?X).\n" + | ||
| 97 | "prefix0:isHeadOf(?X,anony:individual12) :- prefix0:Director(?X).\n" + | ||
| 98 | "prefix0:Publication(?X) :- prefix0:publicationAuthor(?X,?Y).\n" + | ||
| 99 | "prefix0:Organization(?X) :- prefix0:College(?X).\n" + | ||
| 100 | "prefix0:isCrazyAbout(?X,anony:individual24) :- prefix0:BaseballFan(?X).\n" + | ||
| 101 | "prefix0:FineArts(?X) :- prefix0:Performing_ArtsClass(?X).\n" + | ||
| 102 | "prefix0:Sports(?X) :- prefix0:BasketBallClass(?X).\n" + | ||
| 103 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:PsychologyClass(?X).\n" + | ||
| 104 | "prefix0:Person(?X) :- prefix0:Employee(?X).\n" + | ||
| 105 | "prefix0:FineArts(?X) :- prefix0:DramaClass(?X).\n" + | ||
| 106 | "prefix0:Faculty(?X) :- prefix0:PostDoc(?X).\n" + | ||
| 107 | "prefix0:University(?Y) :- prefix0:hasDoctoralDegreeFrom(?X,?Y).\n" + | ||
| 108 | "prefix0:Sports(anony:individual0) :- prefix0:SportsLover(?X).\n" + | ||
| 109 | "prefix0:Person(?Y) :- prefix0:hasAlumnus(?X,?Y).\n" + | ||
| 110 | "prefix0:FineArts(?X) :- prefix0:Modern_ArtsClass(?X).\n" + | ||
| 111 | "prefix0:hasMember(?X,?Y) :- prefix0:hasStudent(?X,?Y).\n" + | ||
| 112 | "prefix0:Course(?X) :- prefix0:isTaughtBy(?X,?Y).\n" + | ||
| 113 | "prefix0:NonScienceStudent(?X) :- prefix0:Student(?X).\n" + | ||
| 114 | "prefix0:BasketBallLover(?X) :- prefix0:Person(?X), prefix0:like(?X,?Y), prefix0:BasketBallClass(?Y).\n" + | ||
| 115 | "prefix0:Professor(?X) :- prefix0:VisitingProfessor(?X).\n" + | ||
| 116 | "prefix0:GraduateCourse(?Y) :- prefix0:GraduateStudent(?X), prefix0:takesCourse(?X,?Y).\n" + | ||
| 117 | "prefix0:TennisClass(anony:individual19) :- prefix0:TennisFan(?X).\n" + | ||
| 118 | "prefix0:Work(?X) :- prefix0:Research(?X).\n" + | ||
| 119 | "prefix0:TennisFan(?X) :- prefix0:Person(?X), prefix0:isCrazyAbout(?X,?Y), prefix0:TennisClass(?Y).\n" + | ||
| 120 | "prefix0:ScienceStudent(?X) :- prefix0:Student(?X), prefix0:hasMajor(?X,?Y), prefix0:Science(?Y).\n" + | ||
| 121 | "prefix0:Person(?X) :- prefix0:Woman(?X).\n" + | ||
| 122 | "prefix0:Man(?X) :- prefix0:Person(?X).\n" + | ||
| 123 | "prefix0:Person(?X) :- prefix0:hasUndergraduateDegreeFrom(?X,?Y).\n" + | ||
| 124 | "prefix0:ResearchGroup(?X) :- prefix0:researchProject(?X,?Y).\n" + | ||
| 125 | "prefix0:hasSameHomeTownWith(?X,?Z) :- prefix0:hasSameHomeTownWith(?X,?Y), prefix0:hasSameHomeTownWith(?Y,?Z).\n" + | ||
| 126 | "prefix0:Person(?X) :- prefix0:isFriendOf(?X,?Y).\n" + | ||
| 127 | "prefix0:Person(?Y) :- prefix0:publicationAuthor(?X,?Y).\n" + | ||
| 128 | "prefix0:Person(?X) :- prefix0:Chair(?X).\n" + | ||
| 129 | "prefix0:Publication(?X) :- prefix0:Manual(?X).\n" + | ||
| 130 | "prefix0:Publication(?X) :- prefix0:UnofficialPublication(?X).\n" + | ||
| 131 | "prefix0:Engineering(?X) :- prefix0:Industry_EngineeringClass(?X).\n" + | ||
| 132 | "prefix0:Science(?X) :- prefix0:StatisticsClass(?X).\n" + | ||
| 133 | "prefix0:Organization(?Y) :- prefix0:isStudentOf(?X,?Y).\n" + | ||
| 134 | "prefix0:SwimmingFan(?X) :- prefix0:Person(?X), prefix0:isCrazyAbout(?X,?Y), prefix0:SwimmingClass(?Y).\n" + | ||
| 135 | "prefix0:Person(?X) :- prefix0:emailAddress(?X,?Y).\n" + | ||
| 136 | "prefix0:FineArts(?X) :- prefix0:Latin_ArtsClass(?X).\n" + | ||
| 137 | "prefix0:Organization(?X) :- prefix0:ResearchGroup(?X).\n" + | ||
| 138 | "prefix0:AcademicSubject(?X) :- prefix0:HumanitiesAndSocial(?X).\n" + | ||
| 139 | "prefix0:Professor(?X) :- prefix0:Dean(?X).\n" + | ||
| 140 | "prefix0:SwimmingClass(anony:individual8) :- prefix0:SwimmingLover(?X).\n" + | ||
| 141 | "prefix0:University(?Y) :- prefix0:hasMasterDegreeFrom(?X,?Y).\n" + | ||
| 142 | "prefix0:Article(?X) :- prefix0:ConferencePaper(?X).\n" + | ||
| 143 | "prefix0:Person(?X) :- prefix0:BasketBallFan(?X).\n" + | ||
| 144 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:ReligionsClass(?X).\n" + | ||
| 145 | "prefix0:Science(?X) :- prefix0:PhysicsClass(?X).\n" + | ||
| 146 | "prefix0:Dean(?X) :- prefix0:isHeadOf(?X,?Y), prefix0:College(?Y).\n" + | ||
| 147 | "prefix0:University(?Y) :- prefix0:hasDegreeFrom(?X,?Y).\n" + | ||
| 148 | "prefix0:Organization(?X) :- prefix0:hasMember(?X,?Y).\n" + | ||
| 149 | "prefix0:Engineering(?X) :- prefix0:Computer_EngineeringClass(?X).\n" + | ||
| 150 | "prefix0:Publication(?X) :- prefix0:Software(?X).\n" + | ||
| 151 | "prefix0:Science(?X) :- prefix0:GeosciencesClass(?X).\n" + | ||
| 152 | "prefix0:hasMajor(?X,anony:individual9) :- prefix0:ScienceStudent(?X).\n" + | ||
| 153 | "prefix0:hasDegreeFrom(?Y,?X) :- prefix0:hasAlumnus(?X,?Y).\n" + | ||
| 154 | "prefix0:Software(?X) :- prefix0:softwareDocumentation(?X,?Y).\n" + | ||
| 155 | "prefix0:isMemberOf(?X,?Y) :- prefix0:isStudentOf(?X,?Y).\n" + | ||
| 156 | "prefix0:Organization(?X) :- prefix0:hasStudent(?X,?Y).\n" + | ||
| 157 | "owl:Nothing2(?X) :- prefix0:GraduateCourse(?X), prefix0:GraduateCourse_neg(?X).\n" + | ||
| 158 | "prefix0:BaseballFan(?X) :- prefix0:Person(?X), prefix0:isCrazyAbout(?X,?Y), prefix0:BaseballClass(?Y).\n" + | ||
| 159 | "prefix0:Publication(?X) :- prefix0:publicationResearch(?X,?Y).\n" + | ||
| 160 | "prefix0:like(?X,anony:individual14) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 161 | "prefix0:SportsLover(?X) :- prefix0:Person(?X), prefix0:like(?X,?Y), prefix0:Sports(?Y).\n" + | ||
| 162 | "prefix0:Organization(?X) :- prefix0:University(?X).\n" + | ||
| 163 | "prefix0:hasAlumnus(?Y,?X) :- prefix0:hasDegreeFrom(?X,?Y).\n" + | ||
| 164 | "prefix0:Science(?X) :- prefix0:Materials_ScienceClass(?X).\n" + | ||
| 165 | "prefix0:Professor(?X) :- prefix0:tenured(?X,?Y).\n" + | ||
| 166 | "prefix0:Faculty(?X) :- prefix0:Professor(?X).\n" + | ||
| 167 | "prefix0:Student(?X) :- prefix0:NonScienceStudent(?X).\n" + | ||
| 168 | "prefix0:Person(?X) :- prefix0:telephone(?X,?Y).\n" + | ||
| 169 | "prefix0:FineArts(?X) :- prefix0:ArchitectureClass(?X).\n" + | ||
| 170 | "prefix0:University(?Y) :- prefix0:hasUndergraduateDegreeFrom(?X,?Y).\n" + | ||
| 171 | "prefix0:Man(anony:individual10) :- prefix0:College(?X).\n" + | ||
| 172 | "prefix0:Person(?X) :- prefix0:Man(?X).\n" + | ||
| 173 | "prefix0:Person(?X) :- prefix0:title(?X,?Y).\n" + | ||
| 174 | "prefix0:subOrganizationOf(?X,?Z) :- prefix0:subOrganizationOf(?X,?Y), prefix0:subOrganizationOf(?Y,?Z).\n" + | ||
| 175 | "owl:sameAs(?Y1,?Y2) :- prefix0:like(?X,?Y1), prefix0:like(?X,?Y2).\n" + | ||
| 176 | "prefix0:takesCourse(?X,anony:individual4) :- prefix0:GraduateStudent(?X).\n" + | ||
| 177 | "prefix0:Sports(?X) :- prefix0:TennisClass(?X).\n" + | ||
| 178 | "prefix0:Engineering(?X) :- prefix0:Petroleuml_EngineeringClass(?X).\n" + | ||
| 179 | "prefix0:Organization(?X) :- prefix0:Institute(?X).\n" + | ||
| 180 | "prefix0:isCrazyAbout(?X,anony:individual16) :- prefix0:BasketBallFan(?X).\n" + | ||
| 181 | "prefix0:Science(?X) :- prefix0:BiologyClass(?X).\n" + | ||
| 182 | "prefix0:Person(?X) :- prefix0:SportsFan(?X).\n" + | ||
| 183 | "prefix0:Course(?X) :- prefix0:GraduateCourse(?X).\n" + | ||
| 184 | "prefix0:Person(?X) :- prefix0:Director(?X).\n" + | ||
| 185 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:EconomicsClass(?X).\n" + | ||
| 186 | "prefix0:Person(?X) :- prefix0:BaseballLover(?X).\n" + | ||
| 187 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:HistoryClass(?X).\n" + | ||
| 188 | "prefix0:FineArts(?X) :- prefix0:Asian_ArtsClass(?X).\n" + | ||
| 189 | "prefix0:isStudentOf(?X,?Y) :- prefix0:enrollIn(?X,?Y).\n" + | ||
| 190 | "prefix0:isHeadOf(?X,anony:individual20) :- prefix0:Chair(?X).\n" + | ||
| 191 | "prefix0:Person(?X) :- prefix0:PeopleWithHobby(?X).\n" + | ||
| 192 | "prefix0:Sports(anony:individual5) :- prefix0:SportsFan(?X).\n" + | ||
| 193 | "prefix0:Science(anony:individual9) :- prefix0:ScienceStudent(?X).\n" + | ||
| 194 | "prefix0:Engineering(?X) :- prefix0:Biomedical_EngineeringClass(?X).\n" + | ||
| 195 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:Modern_LanguagesClass(?X).\n" + | ||
| 196 | "prefix0:like(?X,?Y) :- prefix0:love(?X,?Y).\n" + | ||
| 197 | "prefix0:hasStudent(?X,anony:individual11) :- prefix0:College(?X).\n" + | ||
| 198 | "prefix0:Science(?X) :- prefix0:ChemistryClass(?X).\n" + | ||
| 199 | "prefix0:Student(?X) :- prefix0:takesCourse(?X,?Y).\n" + | ||
| 200 | "prefix0:teacherOf(?Y,?X) :- prefix0:isTaughtBy(?X,?Y).\n" + | ||
| 201 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:AnthropologyClass(?X).\n" + | ||
| 202 | "prefix0:Person(?X) :- prefix0:hasDegreeFrom(?X,?Y).\n" + | ||
| 203 | "prefix0:Person(?X) :- prefix0:hasDoctoralDegreeFrom(?X,?Y).\n" + | ||
| 204 | "prefix0:Engineering(?X) :- prefix0:Electrical_EngineeringClass(?X).\n" + | ||
| 205 | "owl:differentFrom(anony:individual13,anony:individual14) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 206 | "prefix0:Person(?X) :- prefix0:SportsLover(?X).\n" + | ||
| 207 | "prefix0:Organization(?X) :- prefix0:subOrganizationOf(?X,?Y).\n" + | ||
| 208 | "prefix0:SwimmingLover(?X) :- prefix0:Person(?X), prefix0:like(?X,?Y), prefix0:SwimmingClass(?Y).\n" + | ||
| 209 | "prefix0:BaseballLover(?X) :- prefix0:Person(?X), prefix0:like(?X,?Y), prefix0:BaseballClass(?Y).\n" + | ||
| 210 | "prefix0:Science(?X) :- prefix0:Computer_ScienceClass(?X).\n" + | ||
| 211 | "prefix0:Sports(?X) :- prefix0:SwimmingClass(?X).\n" + | ||
| 212 | "prefix0:Science(?X) :- prefix0:AstronomyClass(?X).\n" + | ||
| 213 | "prefix0:Work(?X) :- prefix0:Course(?X).\n" + | ||
| 214 | "prefix0:Science(?X) :- prefix0:MathematicsClass(?X).\n" + | ||
| 215 | "prefix0:AcademicSubject(?X) :- prefix0:Engineering(?X).\n" + | ||
| 216 | "prefix0:hasDegreeFrom(?X,?Y) :- prefix0:hasUndergraduateDegreeFrom(?X,?Y).\n" + | ||
| 217 | "prefix0:like(?X,anony:individual15) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 218 | "prefix0:Sports(?X) :- prefix0:BaseballClass(?X).\n" + | ||
| 219 | "prefix0:Student(?X) :- prefix0:isStudentOf(?X,?Y).\n" + | ||
| 220 | "prefix0:Professor(?Y) :- prefix0:isAdvisedBy(?X,?Y).\n" + | ||
| 221 | "prefix0:SwimmingClass(anony:individual18) :- prefix0:SwimmingFan(?X).\n" + | ||
| 222 | "prefix0:like(?X,anony:individual22) :- prefix0:BasketBallLover(?X).\n" + | ||
| 223 | "prefix0:like(?X,anony:individual1) :- prefix0:BaseballLover(?X).\n" + | ||
| 224 | "prefix0:Schedule(?X) :- prefix0:listedCourse(?X,?Y).\n" + | ||
| 225 | "owl:Nothing6(?X) :- owl:differentFrom(?X,?X).\n" + | ||
| 226 | "prefix0:PeopleWithManyHobbies(?X) :- prefix0:like(?X,?Y3).\n" + | ||
| 227 | "prefix0:Course(anony:individual23) :- prefix0:TeachingAssistant(?X).\n" + | ||
| 228 | "prefix0:takesCourse(?X,anony:individual3) :- prefix0:takesCourse(?X,?Y).\n" + | ||
| 229 | "prefix0:love(?X,?Y) :- prefix0:like(?X,?Y).\n" + | ||
| 230 | "prefix0:AcademicSubject(?X) :- prefix0:Science(?X).\n" + | ||
| 231 | "prefix0:Person(?X) :- prefix0:ResearchAssistant(?X).\n" + | ||
| 232 | "prefix0:Insterest(?X) :- prefix0:Sports(?X).\n" + | ||
| 233 | "prefix0:Article(?X) :- prefix0:TechnicalReport(?X).\n" + | ||
| 234 | "prefix0:UndergraduateStudent(?Y) :- prefix0:WomanCollege(?X), prefix0:hasStudent(?X,?Y).\n" + | ||
| 235 | "prefix0:Department(anony:individual20) :- prefix0:Chair(?X).\n" + | ||
| 236 | "prefix0:Woman(?X) :- prefix0:Person(?X).\n" + | ||
| 237 | "owl:Nothing4(?X) :- prefix0:UndergraduateStudent(?X), prefix0:UndergraduateStudent_neg(?X).\n" + | ||
| 238 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:HumanitiesClass(?X).\n" + | ||
| 239 | "prefix0:GraduateCourse_neg(anony:individual3) :- prefix0:takesCourse(?X,?Y).\n" + | ||
| 240 | "prefix0:Organization(?Y) :- prefix0:isAffiliatedOrganizationOf(?X,?Y).\n" + | ||
| 241 | "owl:Nothing(?X) :- owl:Nothing4(?X).\n" + | ||
| 242 | "prefix0:like(?X,anony:individual0) :- prefix0:SportsLover(?X).\n" + | ||
| 243 | "prefix0:Research(?Y) :- prefix0:publicationResearch(?X,?Y).\n" + | ||
| 244 | "prefix0:Professor(?X) :- prefix0:AssistantProfessor(?X).\n" + | ||
| 245 | "prefix0:Program(anony:individual12) :- prefix0:Director(?X).\n" + | ||
| 246 | "prefix0:isMemberOf(?X,?Y) :- prefix0:worksFor(?X,?Y).\n" + | ||
| 247 | "prefix0:Organization(anony:individual25) :- prefix0:Employee(?X).\n" + | ||
| 248 | "prefix0:hasDegreeFrom(?X,?Y) :- prefix0:hasDoctoralDegreeFrom(?X,?Y).\n" + | ||
| 249 | "prefix0:Person(?Y) :- prefix0:isAffiliateOf(?X,?Y).\n" + | ||
| 250 | "prefix0:Student(?X) :- prefix0:Person(?X), prefix0:isStudentOf(?X,?Y), prefix0:Organization(?Y).\n" + | ||
| 251 | "prefix0:PeopleWithHobby(?X) :- prefix0:Person(?X), prefix0:like(?X,?Y).\n" + | ||
| 252 | "prefix0:Organization(anony:individual17) :- prefix0:Student(?X).\n" + | ||
| 253 | "prefix0:Engineering(?X) :- prefix0:Mechanical_EngineeringClass(?X).\n" + | ||
| 254 | "prefix0:Employee(?X) :- prefix0:SupportingStaff(?X).\n" + | ||
| 255 | "prefix0:Organization(?X) :- prefix0:Department(?X).\n" + | ||
| 256 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:PhilosophyClass(?X).\n" + | ||
| 257 | "prefix0:College(anony:individual21) :- prefix0:Dean(?X).\n" + | ||
| 258 | "prefix0:UndergraduateStudent_neg(anony:individual11) :- prefix0:College(?X).\n" + | ||
| 259 | "owl:Nothing3(?X) :- prefix0:Man(?X), prefix0:Woman(?X).\n" + | ||
| 260 | "owl:sameAs(?Y1,?Y2) :- prefix0:takesCourse(?X,?Y1), prefix0:LeisureStudent(?X), prefix0:takesCourse(?X,?Y2).\n" + | ||
| 261 | "prefix0:Organization(?X) :- prefix0:isAffiliatedOrganizationOf(?X,?Y).\n" + | ||
| 262 | "prefix0:isCrazyAbout(?X,anony:individual5) :- prefix0:SportsFan(?X).\n" + | ||
| 263 | "prefix0:Software(?X) :- prefix0:softwareVersion(?X,?Y).\n" + | ||
| 264 | "prefix0:Science(anony:individual2) :- prefix0:Student(?X).\n" + | ||
| 265 | "prefix0:SupportingStaff(?X) :- prefix0:ClericalStaff(?X).\n" + | ||
| 266 | "prefix0:Person(?X) :- prefix0:SwimmingLover(?X).\n" + | ||
| 267 | "prefix0:Person(?X) :- prefix0:age(?X,?Y).\n" + | ||
| 268 | "prefix0:BasketBallClass(anony:individual22) :- prefix0:BasketBallLover(?X).\n" + | ||
| 269 | "prefix0:like(?X,anony:individual8) :- prefix0:SwimmingLover(?X).\n" + | ||
| 270 | "prefix0:Person(?X) :- prefix0:firstName(?X,?Y).\n" + | ||
| 271 | "prefix0:Department(?Y) :- prefix0:enrollIn(?X,?Y).\n" + | ||
| 272 | "prefix0:Publication(?Y) :- prefix0:softwareDocumentation(?X,?Y).\n" + | ||
| 273 | "prefix0:hasDegreeFrom(?X,?Y) :- prefix0:hasMasterDegreeFrom(?X,?Y).\n" + | ||
| 274 | "prefix0:AcademicSubject(?Y) :- prefix0:hasMajor(?X,?Y).\n" + | ||
| 275 | "prefix0:Article(?X) :- prefix0:JournalArticle(?X).\n" + | ||
| 276 | "prefix0:Organization(?X) :- prefix0:Program(?X).\n" + | ||
| 277 | "prefix0:Course(?Y) :- prefix0:teacherOf(?X,?Y).\n" + | ||
| 278 | "prefix0:AcademicSubject(?X) :- prefix0:FineArts(?X).\n" + | ||
| 279 | "prefix0:Person(?X) :- prefix0:TennisFan(?X).\n" + | ||
| 280 | "prefix0:GraduateStudent(?X) :- prefix0:takesCourse(?X,?Y).\n" + | ||
| 281 | "prefix0:BasketBallFan(?X) :- prefix0:Person(?X), prefix0:isCrazyAbout(?X,?Y), prefix0:BasketBallClass(?Y).\n" + | ||
| 282 | "prefix0:Publication(?X) :- prefix0:Specification(?X).\n" + | ||
| 283 | "prefix0:worksFor(?X,anony:individual6) :- prefix0:ResearchAssistant(?X).\n" + | ||
| 284 | "prefix0:Person(?X) :- prefix0:SwimmingFan(?X).\n" + | ||
| 285 | "prefix0:BasketBallClass(anony:individual16) :- prefix0:BasketBallFan(?X).\n" + | ||
| 286 | "prefix0:Person(?X) :- prefix0:BaseballFan(?X).\n" + | ||
| 287 | "prefix0:Person(?Y) :- prefix0:isFriendOf(?X,?Y).\n" + | ||
| 288 | "prefix0:like(?X,anony:individual13) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 289 | "owl:differentFrom(anony:individual14,anony:individual15) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 290 | "prefix0:hasSameHomeTownWith(?Y,?X) :- prefix0:hasSameHomeTownWith(?X,?Y).\n" + | ||
| 291 | "prefix0:ResearchGroup(anony:individual6) :- prefix0:ResearchAssistant(?X).\n" + | ||
| 292 | "prefix0:College(?X) :- prefix0:WomanCollege(?X).\n" + | ||
| 293 | "prefix0:BaseballClass(anony:individual24) :- prefix0:BaseballFan(?X).\n" + | ||
| 294 | "owl:differentFrom(anony:individual13,anony:individual15) :- prefix0:PeopleWithManyHobbies(?X).\n" + | ||
| 295 | "prefix0:Publication(?X) :- prefix0:Book(?X).\n" + | ||
| 296 | "prefix0:Professor(?X) :- prefix0:FullProfessor(?X).\n" + | ||
| 297 | "prefix0:Engineering(?X) :- prefix0:Civil_EngineeringClass(?X).\n" + | ||
| 298 | "prefix0:isStudentOf(?X,anony:individual17) :- prefix0:Student(?X).\n" + | ||
| 299 | "prefix0:HumanitiesAndSocial(?X) :- prefix0:EnglishClass(?X).\n" + | ||
| 300 | "prefix0:teachingAssistantOf(?X,anony:individual23) :- prefix0:TeachingAssistant(?X).\n" + | ||
| 301 | "prefix0:woman(?X) | prefix0:man(?X) :- prefix0:human(?X).\n" + | ||
| 302 | "prefix0:FineArts(?X) :- prefix0:MusicsClass(?X).\n"; | ||
| 303 | |||
| 304 | for(String line: prefixes.split("\n")) { | ||
| 305 | String[] split = line.split(" "); | ||
| 306 | MyPrefixes.PAGOdAPrefixes.declarePrefix(split[1], OWLHelper.removeAngles(split[2])); | ||
| 307 | } | ||
| 308 | |||
| 309 | InputStream is = new ByteArrayInputStream(rule.getBytes(Charset.defaultCharset())); | ||
| 310 | DatalogProgram datalogProgram = new DatalogProgram(is); | ||
| 311 | System.out.println(">> General <<"); | ||
| 312 | System.out.println(datalogProgram.getGeneral().toString()); | ||
| 313 | System.out.println(">> Lower <<"); | ||
| 314 | System.out.println(datalogProgram.getLower().toString()); | ||
| 315 | System.out.println(">> Upper <<"); | ||
| 316 | System.out.println(datalogProgram.getUpper().toString()); | ||
| 317 | System.out.flush(); | ||
| 318 | } | ||
| 319 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/junit/ClauseTester.java b/src/test/java/uk/ac/ox/cs/pagoda/junit/ClauseTester.java new file mode 100644 index 0000000..ad4b2de --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/junit/ClauseTester.java | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.junit; | ||
| 2 | |||
| 3 | import org.junit.Test; | ||
| 4 | import org.semanticweb.HermiT.model.*; | ||
| 5 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 6 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 8 | import uk.ac.ox.cs.pagoda.approx.Clause; | ||
| 9 | import uk.ac.ox.cs.pagoda.approx.Clausifier; | ||
| 10 | |||
| 11 | import static org.junit.Assert.fail; | ||
| 12 | |||
| 13 | public class ClauseTester { | ||
| 14 | |||
| 15 | public void test_clause(Atom[] headAtoms, Atom[] bodyAtoms) { | ||
| 16 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 17 | OWLOntology emptyOntology = null; | ||
| 18 | try { | ||
| 19 | emptyOntology = m.createOntology(); | ||
| 20 | } catch(Exception e) { | ||
| 21 | e.printStackTrace(); | ||
| 22 | fail("failed to create a new ontology"); | ||
| 23 | } | ||
| 24 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 25 | System.out.println(c.toString()); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void test_nominal() { | ||
| 30 | Variable x = Variable.create("X"); | ||
| 31 | AtomicRole r = AtomicRole.create("r"); | ||
| 32 | Individual o = Individual.create("o"); | ||
| 33 | Atom[] bodyAtoms = new Atom[]{Atom.create(r, x, o)}; | ||
| 34 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 35 | Atom[] headAtoms = new Atom[]{Atom.create(A, x)}; | ||
| 36 | test_clause(headAtoms, bodyAtoms); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Test | ||
| 40 | public void test_simple() { | ||
| 41 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 42 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 43 | AtomicRole r = AtomicRole.create("r"); | ||
| 44 | Atom[] bodyAtoms = new Atom[] { | ||
| 45 | Atom.create(A, x), | ||
| 46 | Atom.create(r, x, y1), | ||
| 47 | Atom.create(r, x, y2) | ||
| 48 | }; | ||
| 49 | |||
| 50 | Atom[] headAtoms = new Atom[] { | ||
| 51 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 52 | }; | ||
| 53 | |||
| 54 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 55 | OWLOntology emptyOntology = null; | ||
| 56 | try { | ||
| 57 | emptyOntology = m.createOntology(); | ||
| 58 | } catch (Exception e) { | ||
| 59 | e.printStackTrace(); | ||
| 60 | fail("failed to create a new ontology"); | ||
| 61 | } | ||
| 62 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 63 | System.out.println(c.toString()); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Test | ||
| 67 | public void test_more() { | ||
| 68 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"), y3 = Variable.create("y3"); | ||
| 69 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 70 | AtomicRole r = AtomicRole.create("r"); | ||
| 71 | Atom[] bodyAtoms = new Atom[] { | ||
| 72 | Atom.create(A, x), | ||
| 73 | Atom.create(r, x, y1), | ||
| 74 | Atom.create(r, x, y2), | ||
| 75 | Atom.create(r, x, y3), | ||
| 76 | }; | ||
| 77 | |||
| 78 | Atom[] headAtoms = new Atom[] { | ||
| 79 | Atom.create(Equality.INSTANCE, y1, y2), | ||
| 80 | Atom.create(Equality.INSTANCE, y1, y3), | ||
| 81 | Atom.create(Equality.INSTANCE, y2, y3) | ||
| 82 | }; | ||
| 83 | |||
| 84 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 85 | OWLOntology emptyOntology = null; | ||
| 86 | try { | ||
| 87 | emptyOntology = m.createOntology(); | ||
| 88 | } catch (Exception e) { | ||
| 89 | e.printStackTrace(); | ||
| 90 | fail("failed to create a new ontology"); | ||
| 91 | } | ||
| 92 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 93 | System.out.println(c.toString()); | ||
| 94 | } | ||
| 95 | |||
| 96 | @Test | ||
| 97 | public void test_inverse() { | ||
| 98 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 99 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 100 | AtomicRole r = AtomicRole.create("r"); | ||
| 101 | Atom[] bodyAtoms = new Atom[] { | ||
| 102 | Atom.create(A, x), | ||
| 103 | Atom.create(r, y1, x), | ||
| 104 | Atom.create(r, y2, x) | ||
| 105 | }; | ||
| 106 | |||
| 107 | Atom[] headAtoms = new Atom[] { | ||
| 108 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 109 | }; | ||
| 110 | |||
| 111 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 112 | OWLOntology emptyOntology = null; | ||
| 113 | try { | ||
| 114 | emptyOntology = m.createOntology(); | ||
| 115 | } catch (Exception e) { | ||
| 116 | e.printStackTrace(); | ||
| 117 | fail("failed to create a new ontology"); | ||
| 118 | } | ||
| 119 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 120 | System.out.println(c.toString()); | ||
| 121 | } | ||
| 122 | |||
| 123 | @Test | ||
| 124 | public void test_fillter() { | ||
| 125 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 126 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 127 | AtomicConcept B = AtomicConcept.create("B"); | ||
| 128 | AtomicRole r = AtomicRole.create("r"); | ||
| 129 | Atom[] bodyAtoms = new Atom[] { | ||
| 130 | Atom.create(A, x), | ||
| 131 | Atom.create(r, y1, x), | ||
| 132 | Atom.create(r, y2, x), | ||
| 133 | Atom.create(B, y1), | ||
| 134 | Atom.create(B, y2) | ||
| 135 | }; | ||
| 136 | |||
| 137 | Atom[] headAtoms = new Atom[] { | ||
| 138 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 139 | }; | ||
| 140 | |||
| 141 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 142 | OWLOntology emptyOntology = null; | ||
| 143 | try { | ||
| 144 | emptyOntology = m.createOntology(); | ||
| 145 | } catch (Exception e) { | ||
| 146 | e.printStackTrace(); | ||
| 147 | fail("failed to create a new ontology"); | ||
| 148 | } | ||
| 149 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 150 | System.out.println(c.toString()); | ||
| 151 | } | ||
| 152 | |||
| 153 | @Test | ||
| 154 | public void test_negFillter() { | ||
| 155 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 156 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 157 | AtomicConcept B = AtomicConcept.create("B"); | ||
| 158 | AtomicRole r = AtomicRole.create("r"); | ||
| 159 | Atom[] bodyAtoms = new Atom[] { | ||
| 160 | Atom.create(A, x), | ||
| 161 | Atom.create(r, y1, x), | ||
| 162 | Atom.create(r, y2, x) | ||
| 163 | }; | ||
| 164 | |||
| 165 | Atom[] headAtoms = new Atom[] { | ||
| 166 | Atom.create(Equality.INSTANCE, y1, y2), | ||
| 167 | Atom.create(B, y1), | ||
| 168 | Atom.create(B, y2) | ||
| 169 | }; | ||
| 170 | |||
| 171 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 172 | OWLOntology emptyOntology = null; | ||
| 173 | try { | ||
| 174 | emptyOntology = m.createOntology(); | ||
| 175 | } catch (Exception e) { | ||
| 176 | e.printStackTrace(); | ||
| 177 | fail("failed to create a new ontology"); | ||
| 178 | } | ||
| 179 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 180 | System.out.println(c.toString()); | ||
| 181 | } | ||
| 182 | |||
| 183 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/query/CheckAnswers.java b/src/test/java/uk/ac/ox/cs/pagoda/query/CheckAnswers.java new file mode 100644 index 0000000..71730c3 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/query/CheckAnswers.java | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | ||
| 2 | |||
| 3 | import com.google.gson.Gson; | ||
| 4 | import com.google.gson.reflect.TypeToken; | ||
| 5 | import org.testng.Assert; | ||
| 6 | |||
| 7 | import java.io.BufferedReader; | ||
| 8 | import java.io.IOException; | ||
| 9 | import java.lang.reflect.Type; | ||
| 10 | import java.nio.file.Files; | ||
| 11 | import java.nio.file.Path; | ||
| 12 | import java.util.Set; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * It provides auxiliary methods for checking answers. | ||
| 16 | */ | ||
| 17 | public class CheckAnswers { | ||
| 18 | |||
| 19 | private CheckAnswers() { | ||
| 20 | } | ||
| 21 | |||
| 22 | public static void assertSameAnswers(Path computedAnswersFile, Path givenAnswersFile) throws IOException { | ||
| 23 | BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); | ||
| 24 | BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); | ||
| 25 | |||
| 26 | Gson gson = QueryRecord.GsonCreator.getInstance(); | ||
| 27 | |||
| 28 | Type cqType = new TypeToken<Set<QueryRecord>>() {}.getType(); | ||
| 29 | Set<QueryRecord> computedAnswersRecords = gson.fromJson(computedReader, cqType); | ||
| 30 | Set<QueryRecord> givenAnswersRecords = gson.fromJson(givenReader, cqType); | ||
| 31 | |||
| 32 | for(QueryRecord computedAnswersRecord : computedAnswersRecords) { | ||
| 33 | Set<AnswerTuple> givenAnswers = null; | ||
| 34 | for(QueryRecord givenAnswersRecord : givenAnswersRecords) { | ||
| 35 | if(givenAnswersRecord.queryID == computedAnswersRecord.queryID) { | ||
| 36 | givenAnswers = givenAnswersRecord.soundAnswerTuples; | ||
| 37 | break; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | Assert.assertNotNull(givenAnswers, "Missing given answer for query no. " + computedAnswersRecord.queryID); | ||
| 42 | |||
| 43 | Set<AnswerTuple> computedAnswers = computedAnswersRecord.soundAnswerTuples; | ||
| 44 | Assert.assertEquals(computedAnswers.size(), givenAnswers.size(), | ||
| 45 | "Different number of sound answers for query " + computedAnswersRecord.queryID + "!" | ||
| 46 | + "Expected " + givenAnswers.size() + ", got " + computedAnswers.size()); | ||
| 47 | Assert.assertEquals(computedAnswers, givenAnswers, | ||
| 48 | "Different sound answers for query " + computedAnswersRecord.queryID + "!"); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/rules/approximators/TestSkolemTermsManager.java b/src/test/java/uk/ac/ox/cs/pagoda/rules/approximators/TestSkolemTermsManager.java new file mode 100644 index 0000000..6bd8f05 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/rules/approximators/TestSkolemTermsManager.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules.approximators; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * Tests for the class <tt>SkolemTermsManager</tt> | ||
| 7 | */ | ||
| 8 | public class TestSkolemTermsManager { | ||
| 9 | |||
| 10 | @Test | ||
| 11 | public void test() { | ||
| 12 | // TODO some test | ||
| 13 | } | ||
| 14 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/summary/SummaryTester.java b/src/test/java/uk/ac/ox/cs/pagoda/summary/SummaryTester.java new file mode 100644 index 0000000..60c8ed4 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/summary/SummaryTester.java | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.summary; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.io.FileOutputStream; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.util.Scanner; | ||
| 8 | |||
| 9 | import org.semanticweb.HermiT.Reasoner; | ||
| 10 | import org.semanticweb.owlapi.model.AxiomType; | ||
| 11 | import org.semanticweb.owlapi.model.IRI; | ||
| 12 | import org.semanticweb.owlapi.model.OWLClassExpression; | ||
| 13 | import org.semanticweb.owlapi.model.OWLDataFactory; | ||
| 14 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 15 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 16 | import org.semanticweb.owlapi.model.OWLOntologyStorageException; | ||
| 17 | import org.semanticweb.owlapi.model.parameters.Imports; | ||
| 18 | |||
| 19 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | ||
| 20 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 21 | import uk.ac.ox.cs.pagoda.owl.QueryRoller; | ||
| 22 | import uk.ac.ox.cs.pagoda.query.QueryManager; | ||
| 23 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 24 | import uk.ac.ox.cs.pagoda.summary.Summary; | ||
| 25 | |||
| 26 | public class SummaryTester { | ||
| 27 | |||
| 28 | static String FILE_BREAK = System.getProperty("file.separator"); | ||
| 29 | static String LINE_BREAK = System.getProperty("line.separator"); | ||
| 30 | |||
| 31 | public static void main(String[] args) throws Exception { | ||
| 32 | // String arg = "ontologies/claros/all-in-one-manually.owl"; | ||
| 33 | // String arg = "ontologies/claros/Claros.owl ontologies/claros/data"; | ||
| 34 | String arg = "../uobmGenerator/univ-bench-dl.owl " + | ||
| 35 | "../uobmGenerator/uobm1 " + //"a " + | ||
| 36 | "ontologies/uobm/queries/uobm_standard_less.sparql"; | ||
| 37 | |||
| 38 | testSummarisedUpperBound(arg.split("\\ ")); | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * args[0] ontology file location | ||
| 43 | * args[1] data directory | ||
| 44 | * args[2] sparql query file location | ||
| 45 | * | ||
| 46 | * @param args | ||
| 47 | * @throws OWLOntologyCreationException | ||
| 48 | * @throws FileNotFoundException | ||
| 49 | * @throws OWLOntologyStorageException | ||
| 50 | */ | ||
| 51 | public static void testSummarisedUpperBound(String[] args) throws OWLOntologyCreationException, FileNotFoundException, OWLOntologyStorageException { | ||
| 52 | OWLOntology onto = OWLHelper.loadOntology(args[0]); | ||
| 53 | try { | ||
| 54 | onto = OWLHelper.getImportedOntology(onto, args[1]); | ||
| 55 | } catch (IOException e) { | ||
| 56 | e.printStackTrace(); | ||
| 57 | } | ||
| 58 | |||
| 59 | Summary sum = testSummary(onto); | ||
| 60 | System.out.println("Summarisation Done."); | ||
| 61 | |||
| 62 | System.out.println(args[2]); | ||
| 63 | Scanner scanner = new Scanner(new File(args[2])); | ||
| 64 | OWLOntology summary = sum.getSummary(); | ||
| 65 | OWLDataFactory factory = summary.getOWLOntologyManager().getOWLDataFactory(); | ||
| 66 | QueryRoller r = new QueryRoller(factory); | ||
| 67 | OWLClassExpression summarisedQueryExp; | ||
| 68 | Reasoner reasoner = new Reasoner(summary); | ||
| 69 | QueryManager queryManager = new QueryManager(); | ||
| 70 | int upperBoundCounter, queryID = 0; | ||
| 71 | StringBuilder queryText = new StringBuilder(); | ||
| 72 | String[] vars; | ||
| 73 | |||
| 74 | for (String line; ; ) { | ||
| 75 | queryText.setLength(0); | ||
| 76 | while (scanner.hasNextLine() && (line = scanner.nextLine()) != null && !line.startsWith("^[query")); | ||
| 77 | if (!scanner.hasNextLine()) break; | ||
| 78 | |||
| 79 | while (scanner.hasNextLine() && (line = scanner.nextLine()) != null && !line.isEmpty()) | ||
| 80 | queryText.append(line).append(LINE_BREAK); | ||
| 81 | if (!scanner.hasNextLine()) break; | ||
| 82 | |||
| 83 | System.out.println("------------ starting computing for Query " + ++queryID + "------------"); | ||
| 84 | |||
| 85 | System.out.println(queryText); | ||
| 86 | |||
| 87 | QueryRecord record = queryManager.create(queryText.toString(), queryID); | ||
| 88 | vars = record.getAnswerVariables(); | ||
| 89 | if (vars.length > 1) { | ||
| 90 | System.out.println("The query cannot be processed by HermiT ... More than one answer variable"); | ||
| 91 | continue; | ||
| 92 | } | ||
| 93 | |||
| 94 | summarisedQueryExp = r.rollUp(DLClauseHelper.getQuery(sum.getSummary(record), null), vars[0]); | ||
| 95 | |||
| 96 | upperBoundCounter = 0; | ||
| 97 | for (String representative: sum.getRepresentatives()) | ||
| 98 | if (reasoner.isEntailed(factory.getOWLClassAssertionAxiom(summarisedQueryExp, factory.getOWLNamedIndividual(IRI.create(representative))))) { | ||
| 99 | upperBoundCounter += sum.getGroup(representative).size(); | ||
| 100 | } | ||
| 101 | |||
| 102 | System.out.println("There are " + upperBoundCounter + " individual(s) in the upper bound computed by summary."); | ||
| 103 | } | ||
| 104 | scanner.close(); | ||
| 105 | } | ||
| 106 | |||
| 107 | public static Summary testSummary(OWLOntology ontology) throws OWLOntologyCreationException, FileNotFoundException { | ||
| 108 | Summary sum = new Summary(ontology); | ||
| 109 | |||
| 110 | System.out.println("original ontology data: "); | ||
| 111 | outputStatistics(ontology); | ||
| 112 | |||
| 113 | OWLOntology summary = sum.getSummary(); | ||
| 114 | |||
| 115 | System.out.println("summarised ontology data: "); | ||
| 116 | outputStatistics(summary); | ||
| 117 | |||
| 118 | try { | ||
| 119 | FileOutputStream out = new FileOutputStream("summary.owl"); | ||
| 120 | summary.getOWLOntologyManager().saveOntology(summary, out); | ||
| 121 | out.close(); | ||
| 122 | } catch (OWLOntologyStorageException e) { | ||
| 123 | e.printStackTrace(); | ||
| 124 | } catch (IOException e) { | ||
| 125 | // TODO Auto-generated catch block | ||
| 126 | e.printStackTrace(); | ||
| 127 | } | ||
| 128 | |||
| 129 | return sum; | ||
| 130 | } | ||
| 131 | |||
| 132 | private static void outputStatistics(OWLOntology onto) { | ||
| 133 | System.out.println("TBox: " + onto.getTBoxAxioms(Imports.INCLUDED).size() + | ||
| 134 | "\tRBox: " + onto.getRBoxAxioms(Imports.INCLUDED).size() + | ||
| 135 | "\tABox: " + onto.getABoxAxioms(Imports.INCLUDED).size()); | ||
| 136 | System.out.println("Class Assertions: " + onto.getAxiomCount(AxiomType.CLASS_ASSERTION, Imports.INCLUDED) + | ||
| 137 | "\tObject Property Assertions: " + onto.getAxiomCount(AxiomType.OBJECT_PROPERTY_ASSERTION, Imports.INCLUDED)); | ||
| 138 | } | ||
| 139 | |||
| 140 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/tester/OWLTester.java b/src/test/java/uk/ac/ox/cs/pagoda/tester/OWLTester.java new file mode 100644 index 0000000..25162c8 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/tester/OWLTester.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tester; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 4 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 5 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 6 | import org.semanticweb.owlapi.model.parameters.Imports; | ||
| 7 | |||
| 8 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 9 | |||
| 10 | public class OWLTester { | ||
| 11 | |||
| 12 | public static void main(String[] args) throws OWLOntologyCreationException { | ||
| 13 | // OWLOntology onto = OWLHelper.loadOntology("dbpedia_imported.owl"); | ||
| 14 | OWLOntology onto = OWLHelper.loadOntology("reactome_imported.owl"); | ||
| 15 | OWLOntologyManager manager = onto.getOWLOntologyManager(); | ||
| 16 | // OWLOntology data = manager.loadOntology(IRI.create("file:/media/krr-nas-share/Yujiao/ontologies/bio2rdf/reactome/graph\ sampling/sample_1_new.ttl")); | ||
| 17 | // System.out.println("data: " + data.getAxiomCount() + " " + data.getABoxAxioms(true).size()); | ||
| 18 | for (OWLOntology t: manager.getOntologies()) { | ||
| 19 | System.out.println(t.getOntologyID()); | ||
| 20 | System.out.println(t.getAxiomCount() + " " + onto.getABoxAxioms(Imports.INCLUDED).size()); | ||
| 21 | } | ||
| 22 | System.out.println("In closure: " + onto.getImportsClosure().size()); | ||
| 23 | for (OWLOntology t: onto.getImportsClosure()) | ||
| 24 | System.out.println(t.getOntologyID()); | ||
| 25 | |||
| 26 | System.out.println(onto.getAxiomCount() + " " + onto.getABoxAxioms(Imports.INCLUDED).size()); | ||
| 27 | } | ||
| 28 | |||
| 29 | } | ||
| 30 | |||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/tester/PagodaTester.java b/src/test/java/uk/ac/ox/cs/pagoda/tester/PagodaTester.java new file mode 100644 index 0000000..d741d3b --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/tester/PagodaTester.java | |||
| @@ -0,0 +1,318 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tester; | ||
| 2 | |||
| 3 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 4 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 5 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 8 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 9 | |||
| 10 | import java.io.File; | ||
| 11 | import java.io.FileNotFoundException; | ||
| 12 | import java.io.IOException; | ||
| 13 | import java.util.Scanner; | ||
| 14 | |||
| 15 | @Deprecated | ||
| 16 | public class PagodaTester { | ||
| 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 | |||
| 110 | public static void main(String... args) { | ||
| 111 | if(args.length == 0) { | ||
| 112 | // args = new String[] {test_tbox, test_abox, test_query}; | ||
| 113 | // args = new String[] {lubm_tbox, lubm_abox, lubm_query}; | ||
| 114 | // args = new String[] {uobm_tbox, uobm_abox, uobm_query}; | ||
| 115 | // args = new String[] {fly, "null", fly_query}; | ||
| 116 | // args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query}; | ||
| 117 | // args = new String[] {travel_tbox, null, dbpedia_query274}; | ||
| 118 | args = new String[]{fly, fly_query}; | ||
| 119 | // args = new String[] {npd_tbox, npd_abox, npd_query}; | ||
| 120 | // args = new String[] {npd_bench_tbox, npd_bench_abox, npd_bench_query}; | ||
| 121 | // args = new String[] {"../SemFacet/WebContent/WEB-INF/data/dbpedia.owl", "../SemFacet/WebContent/WEB-INF/data/dbpediaA.nt", null}; | ||
| 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 | PagodaProperties properties = new PagodaProperties("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 | |||
| 150 | Utility.logInfo("Ontology file: " + properties.getOntologyPath()); | ||
| 151 | Utility.logInfo("Data files: " + properties.getDataPath()); | ||
| 152 | Utility.logInfo("Query files: " + properties.getQueryPath()); | ||
| 153 | Utility.logInfo("Answer file: " + properties.getAnswerPath()); | ||
| 154 | |||
| 155 | QueryReasoner pagoda = null; | ||
| 156 | |||
| 157 | try { | ||
| 158 | Timer t = new Timer(); | ||
| 159 | pagoda = QueryReasoner.getInstance(properties); | ||
| 160 | if (pagoda == null) return; | ||
| 161 | |||
| 162 | Utility.logInfo("Preprocessing Done in " + t.duration() + " seconds."); | ||
| 163 | |||
| 164 | if (properties.getQueryPath() != null) | ||
| 165 | for (String queryFile: properties.getQueryPath().split(";")) | ||
| 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 | } | ||
| 174 | } finally { | ||
| 175 | if (pagoda != null) pagoda.dispose(); | ||
| 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()); | ||
| 316 | } | ||
| 317 | |||
| 318 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/tester/Statistics.java b/src/test/java/uk/ac/ox/cs/pagoda/tester/Statistics.java new file mode 100644 index 0000000..13d7f90 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/tester/Statistics.java | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tester; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.util.Iterator; | ||
| 6 | import java.util.LinkedList; | ||
| 7 | import java.util.Scanner; | ||
| 8 | |||
| 9 | @Deprecated | ||
| 10 | public class Statistics { | ||
| 11 | |||
| 12 | double satCheckTime; | ||
| 13 | double preprocessTime; | ||
| 14 | LinkedList<Integer> number = new LinkedList<Integer>(); | ||
| 15 | LinkedList<Double> time = new LinkedList<Double>(); | ||
| 16 | |||
| 17 | public Statistics(String file) { | ||
| 18 | Scanner scanner = null; | ||
| 19 | try { | ||
| 20 | scanner = new Scanner(new File(file)); | ||
| 21 | for (String line; scanner.hasNextLine(); ) { | ||
| 22 | line = scanner.nextLine(); | ||
| 23 | if (line.contains("time for satisfiability checking")) | ||
| 24 | satCheckTime = Double.parseDouble(line.substring(line.indexOf(": ") + 2)); | ||
| 25 | else if (line.contains("Preprocessing Done in")) | ||
| 26 | preprocessTime = Double.parseDouble(line.substring(line.indexOf("in ") + 3, line.indexOf(" second"))); | ||
| 27 | else if (line.contains("The number of answer tuples:")) | ||
| 28 | number.add(Integer.parseInt(line.substring(line.indexOf(": ") + 2))); | ||
| 29 | else if (line.contains("Total time to answer this query:")) | ||
| 30 | time.add(Double.parseDouble(line.substring(line.indexOf(": ") + 2))); | ||
| 31 | } | ||
| 32 | } catch (FileNotFoundException e) { | ||
| 33 | e.printStackTrace(); | ||
| 34 | } finally { | ||
| 35 | if (scanner != null) | ||
| 36 | scanner.close(); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | public String diff(String other) { | ||
| 41 | return diff(new Statistics(other)); | ||
| 42 | } | ||
| 43 | |||
| 44 | public String diff(Statistics other) { | ||
| 45 | if (other.number.size() != number.size()) | ||
| 46 | return "The number of query is different! " + this.number.size() + " v.s. " + other.number.size(); | ||
| 47 | int i = 0; | ||
| 48 | Iterator<Integer> iter1 = number.iterator(), iter2 = other.number.iterator(); | ||
| 49 | StringBuilder diff = new StringBuilder(); | ||
| 50 | int a, b; | ||
| 51 | while (iter1.hasNext()) { | ||
| 52 | ++i; | ||
| 53 | if ((a = iter1.next()) != (b = iter2.next())) { | ||
| 54 | diff.append("Query ").append(i).append(": ").append(a).append(", reference ").append(b).append("\n"); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | return diff.toString(); | ||
| 58 | } | ||
| 59 | |||
| 60 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java b/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java new file mode 100644 index 0000000..3de30e4 --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util; | ||
| 2 | |||
| 3 | import org.testng.annotations.Test; | ||
| 4 | |||
| 5 | public class SimpleProgressBarTester { | ||
| 6 | |||
| 7 | @Test | ||
| 8 | public void test() throws InterruptedException { | ||
| 9 | SimpleProgressBar simpleProgressBar = new SimpleProgressBar("TestBar", 1000); | ||
| 10 | for(int i = 0; i < 1000; i++) { | ||
| 11 | simpleProgressBar.update(i); | ||
| 12 | Thread.sleep(10); | ||
| 13 | } | ||
| 14 | simpleProgressBar.dispose(); | ||
| 15 | } | ||
| 16 | } | ||
diff --git a/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java b/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java new file mode 100644 index 0000000..c7f024a --- /dev/null +++ b/src/test/java/uk/ac/ox/cs/pagoda/util/TestUtil.java | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util; | ||
| 2 | |||
| 3 | import org.apache.log4j.Appender; | ||
| 4 | import org.apache.log4j.FileAppender; | ||
| 5 | import org.apache.log4j.Logger; | ||
| 6 | import org.semanticweb.owlapi.model.IRI; | ||
| 7 | |||
| 8 | import java.io.File; | ||
| 9 | import java.io.IOException; | ||
| 10 | import java.io.InputStream; | ||
| 11 | import java.net.URL; | ||
| 12 | import java.nio.file.Files; | ||
| 13 | import java.nio.file.Path; | ||
| 14 | import java.nio.file.Paths; | ||
| 15 | import java.util.Enumeration; | ||
| 16 | import java.util.Properties; | ||
| 17 | |||
| 18 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * A collection of utility methods for testing. | ||
| 22 | */ | ||
| 23 | public class TestUtil { | ||
| 24 | |||
| 25 | public static final String CONFIG_FILE = "test.properties"; | ||
| 26 | private static final Logger LOGGER = Logger.getLogger("Tester"); | ||
| 27 | private static boolean isConfigLoaded = false; | ||
| 28 | private static Properties config; | ||
| 29 | |||
| 30 | public static Properties getConfig() { | ||
| 31 | if(!isConfigLoaded) { | ||
| 32 | try(InputStream in = TestUtil.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) { | ||
| 33 | config = new java.util.Properties(); | ||
| 34 | config.load(in); | ||
| 35 | in.close(); | ||
| 36 | isConfigLoaded = true; | ||
| 37 | } catch (IOException e) { | ||
| 38 | e.printStackTrace(); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return config; | ||
| 42 | } | ||
| 43 | |||
| 44 | public static String combinePaths(String path1, String path2) { | ||
| 45 | File file1 = new File(path1); | ||
| 46 | File file2 = new File(file1, path2); | ||
| 47 | return file2.getPath(); | ||
| 48 | } | ||
| 49 | |||
| 50 | public static void copyFile(String src, String dst) throws IOException { | ||
| 51 | Files.copy(Paths.get(src), Paths.get(dst), REPLACE_EXISTING); | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Get the log file, which is assumed unique. | ||
| 56 | * */ | ||
| 57 | public static String getLogFileName() { | ||
| 58 | Enumeration e = Logger.getRootLogger().getAllAppenders(); | ||
| 59 | while (e.hasMoreElements()){ | ||
| 60 | Appender app = (Appender)e.nextElement(); | ||
| 61 | if (app instanceof FileAppender){ | ||
| 62 | return ((FileAppender)app).getFile(); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | return null; | ||
| 66 | } | ||
| 67 | |||
| 68 | public static Path getAnswersFilePath(String name) { | ||
| 69 | URL givenAnswersURL = TestUtil.class.getClassLoader() | ||
| 70 | .getResource(name); | ||
| 71 | if(givenAnswersURL == null) throw new RuntimeException("Missing answers file:" + name); | ||
| 72 | return Paths.get(givenAnswersURL.getPath()); | ||
| 73 | } | ||
| 74 | |||
| 75 | public static void logInfo(Object msg) { | ||
| 76 | LOGGER.info(msg); | ||
| 77 | } | ||
| 78 | |||
| 79 | public static void logDebug(Object msg) { | ||
| 80 | LOGGER.debug(msg); | ||
| 81 | } | ||
| 82 | |||
| 83 | public static void logError(Object msg) { | ||
| 84 | LOGGER.error(msg); | ||
| 85 | } | ||
| 86 | |||
| 87 | public static void logError(Object msg, Throwable t) { | ||
| 88 | LOGGER.error(msg, t); | ||
| 89 | } | ||
| 90 | |||
| 91 | public static final String NS = "http://example.org/test#%s"; | ||
| 92 | |||
| 93 | public static IRI getEntityIRI(String name) { | ||
| 94 | return IRI.create(String.format(NS, name)); | ||
| 95 | } | ||
| 96 | |||
| 97 | } | ||
