aboutsummaryrefslogtreecommitdiff
path: root/test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java')
-rw-r--r--test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java158
1 files changed, 158 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java b/test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java
new file mode 100644
index 0000000..63fe7b7
--- /dev/null
+++ b/test/uk/ac/ox/cs/pagoda/approx/ApproxTester.java
@@ -0,0 +1,158 @@
1package uk.ac.ox.cs.pagoda.approx;
2
3import java.io.IOException;
4
5import org.semanticweb.owlapi.model.OWLOntology;
6
7import uk.ac.ox.cs.pagoda.approx.KnowledgeBase;
8import uk.ac.ox.cs.pagoda.approx.RLOntology;
9import uk.ac.ox.cs.pagoda.approx.RLPlusOntology;
10import uk.ac.ox.cs.pagoda.constraints.NullaryBottom;
11import uk.ac.ox.cs.pagoda.owl.OWLHelper;
12import uk.ac.ox.cs.pagoda.rules.DisjunctiveProgram;
13import uk.ac.ox.cs.pagoda.rules.ExistentialProgram;
14import uk.ac.ox.cs.pagoda.rules.ExistentialToDisjunctive;
15import uk.ac.ox.cs.pagoda.rules.GeneralProgram;
16import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram;
17import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram;
18import uk.ac.ox.cs.pagoda.util.Utility;
19
20public 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}