diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-02-04 10:38:33 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-02-04 10:38:33 +0000 |
commit | b9fe66ed1b48d21f3fe6cb960c8fbe8f22f4a39c (patch) | |
tree | 3c696ab6e635383d5277114a591a0d9a02bdecd8 /src/test/scala/uk | |
parent | 26f01c74b83cf79f5af425692421380dd3eb6bea (diff) | |
download | RSAComb-b9fe66ed1b48d21f3fe6cb960c8fbe8f22f4a39c.tar.gz RSAComb-b9fe66ed1b48d21f3fe6cb960c8fbe8f22f4a39c.zip |
Add ontology normalizer
This also allows to define ontology approximations to RSA in a simple
way.
Diffstat (limited to 'src/test/scala/uk')
-rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/converter/NormalizerSpec.scala | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/converter/NormalizerSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/converter/NormalizerSpec.scala new file mode 100644 index 0000000..3a686c0 --- /dev/null +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/converter/NormalizerSpec.scala | |||
@@ -0,0 +1,140 @@ | |||
1 | package uk.ac.ox.cs.rsacomb.converter | ||
2 | |||
3 | import org.scalatest.LoneElement | ||
4 | import org.scalatest.flatspec.AnyFlatSpec | ||
5 | import org.scalatest.matchers.should.Matchers | ||
6 | import org.semanticweb.owlapi.apibinding.OWLManager | ||
7 | import org.semanticweb.owlapi.model.OWLOntologyManager | ||
8 | |||
9 | import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom | ||
10 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} | ||
11 | import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter | ||
12 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} | ||
13 | import uk.ac.ox.cs.rsacomb.converter.{Normalizer, SkolemStrategy, NoSkolem} | ||
14 | |||
15 | object NormalizerSpec { | ||
16 | val manager = OWLManager.createOWLOntologyManager() | ||
17 | val factory = manager.getOWLDataFactory | ||
18 | val normalizer = new Normalizer() | ||
19 | } | ||
20 | |||
21 | class NormalizerSpec extends AnyFlatSpec with Matchers with LoneElement { | ||
22 | |||
23 | import NormalizerSpec._ | ||
24 | |||
25 | "Equivalent classes" should "be split in pairwise subclass axioms" in { | ||
26 | val cls1 = factory.getOWLClass("_:cls1") | ||
27 | val cls2 = factory.getOWLClass("_:cls2") | ||
28 | val cls3 = factory.getOWLClass("_:cls3") | ||
29 | val equivalentClasses = | ||
30 | factory.getOWLEquivalentClassesAxiom(cls1, cls2, cls3) | ||
31 | normalizer.normalize(equivalentClasses) should contain theSameElementsAs | ||
32 | Seq( | ||
33 | factory.getOWLSubClassOfAxiom(cls1, cls2), | ||
34 | factory.getOWLSubClassOfAxiom(cls1, cls3), | ||
35 | factory.getOWLSubClassOfAxiom(cls2, cls1), | ||
36 | factory.getOWLSubClassOfAxiom(cls2, cls3), | ||
37 | factory.getOWLSubClassOfAxiom(cls3, cls1), | ||
38 | factory.getOWLSubClassOfAxiom(cls3, cls2) | ||
39 | ).flatMap(normalizer.normalize) | ||
40 | } | ||
41 | |||
42 | "Equivalent data properties" should "be split in pairwise subclass axioms" in { | ||
43 | val prop1 = factory.getOWLDataProperty("_:prop1") | ||
44 | val prop2 = factory.getOWLDataProperty("_:prop2") | ||
45 | val prop3 = factory.getOWLDataProperty("_:prop3") | ||
46 | val equivalentProps = | ||
47 | factory.getOWLEquivalentDataPropertiesAxiom(prop1, prop2, prop3) | ||
48 | normalizer.normalize(equivalentProps) should contain theSameElementsAs | ||
49 | Seq( | ||
50 | factory.getOWLSubDataPropertyOfAxiom(prop1, prop2), | ||
51 | factory.getOWLSubDataPropertyOfAxiom(prop1, prop3), | ||
52 | factory.getOWLSubDataPropertyOfAxiom(prop2, prop1), | ||
53 | factory.getOWLSubDataPropertyOfAxiom(prop2, prop3), | ||
54 | factory.getOWLSubDataPropertyOfAxiom(prop3, prop1), | ||
55 | factory.getOWLSubDataPropertyOfAxiom(prop3, prop2) | ||
56 | ).flatMap(normalizer.normalize) | ||
57 | } | ||
58 | |||
59 | "Equivalent object properties" should "be split in pairwise subclass axioms" in { | ||
60 | val prop1 = factory.getOWLObjectProperty("_:prop1") | ||
61 | val prop2 = factory.getOWLObjectProperty("_:prop2") | ||
62 | val prop3 = factory.getOWLObjectProperty("_:prop3") | ||
63 | val equivalentProps = | ||
64 | factory.getOWLEquivalentObjectPropertiesAxiom(prop1, prop2, prop3) | ||
65 | normalizer.normalize(equivalentProps) should contain theSameElementsAs | ||
66 | Seq( | ||
67 | factory.getOWLSubObjectPropertyOfAxiom(prop1, prop2), | ||
68 | factory.getOWLSubObjectPropertyOfAxiom(prop1, prop3), | ||
69 | factory.getOWLSubObjectPropertyOfAxiom(prop2, prop1), | ||
70 | factory.getOWLSubObjectPropertyOfAxiom(prop2, prop3), | ||
71 | factory.getOWLSubObjectPropertyOfAxiom(prop3, prop1), | ||
72 | factory.getOWLSubObjectPropertyOfAxiom(prop3, prop2) | ||
73 | ).flatMap(normalizer.normalize) | ||
74 | } | ||
75 | |||
76 | //"A class name" should "be converted into a single atom" in { | ||
77 | // val cls = factory.getOWLClass(iriString0) | ||
78 | // val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0)) | ||
79 | // val (res, ext) = | ||
80 | // convert(cls, term0, List(), NoSkolem, Empty) | ||
81 | // res.loneElement shouldEqual atom | ||
82 | // ext shouldBe empty | ||
83 | //} | ||
84 | |||
85 | //"A intersection of classes" should "be converted into the union of the conversion of the classes" in { | ||
86 | // val cls0 = factory.getOWLClass(iriString0) | ||
87 | // val cls1 = factory.getOWLClass(iriString1) | ||
88 | // val cls2 = factory.getOWLClass(iriString2) | ||
89 | // val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2) | ||
90 | // val (res0, ext0) = | ||
91 | // convert(cls0, term0, List(), NoSkolem, Empty) | ||
92 | // val (res1, ext1) = | ||
93 | // convert(cls1, term0, List(), NoSkolem, Empty) | ||
94 | // val (res2, ext2) = | ||
95 | // convert(cls2, term0, List(), NoSkolem, Empty) | ||
96 | // val (res, ext) = | ||
97 | // convert(conj, term0, List(), NoSkolem, Empty) | ||
98 | // res should contain theSameElementsAs (res0 ::: res1 ::: res2) | ||
99 | // ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2) | ||
100 | //} | ||
101 | |||
102 | //"A singleton intersection" should "correspond to the conversion of the internal class" in { | ||
103 | // val cls0 = factory.getOWLClass(iriString0) | ||
104 | // val conj = factory.getOWLObjectIntersectionOf(cls0) | ||
105 | // val (res0, ext0) = | ||
106 | // convert(cls0, term0, List(), NoSkolem, Empty) | ||
107 | // val (res, ext) = | ||
108 | // convert(conj, term0, List(), NoSkolem, Empty) | ||
109 | // res should contain theSameElementsAs res0 | ||
110 | // ext should contain theSameElementsAs ext0 | ||
111 | //} | ||
112 | |||
113 | //"An object property" should "be converted into an atom with matching predicate" in { | ||
114 | // val prop = factory.getOWLObjectProperty(iriString0) | ||
115 | // for (sx <- suffixes) { | ||
116 | // val atom = | ||
117 | // TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx), term1) | ||
118 | // convert(prop, term0, term1, sx) shouldEqual atom | ||
119 | // } | ||
120 | //} | ||
121 | |||
122 | //"The inverse of an object property" should "be converted into an atom with inverted subject/object" in { | ||
123 | // val prop = factory.getOWLObjectProperty(iriString0) | ||
124 | // val inv = factory.getOWLObjectInverseOf(prop) | ||
125 | // for (sx <- Seq(Empty, Forward, Backward)) { | ||
126 | // val atom = TupleTableAtom.rdf(term1, IRI.create(iriString0 :: sx), term0) | ||
127 | // convert(inv, term0, term1, sx) shouldEqual atom | ||
128 | // } | ||
129 | //} | ||
130 | |||
131 | //"A data property" should "be converted into an atom with matching predicate" in { | ||
132 | // val prop = factory.getOWLDataProperty(iriString0) | ||
133 | // for (suffix <- suffixes) { | ||
134 | // val atom = | ||
135 | // TupleTableAtom.rdf(term0, IRI.create(iriString0 :: suffix), term1) | ||
136 | // convert(prop, term0, term1, suffix) shouldEqual atom | ||
137 | // } | ||
138 | //} | ||
139 | |||
140 | } | ||