Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Commit c5a5104

Browse files
Added test for ForwardRuleReasonerOWLHorst O1 rule
1 parent c1e22c4 commit c5a5104

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Prefix(:=<http://ex.com/default#>)
2+
3+
Ontology(<http://ex.com/ont/sample1.owl>
4+
<http://ex.com/ont/release/123/sample1.owl>
5+
6+
Declaration(ObjectProperty(:objProp01))
7+
Declaration(ObjectProperty(:objProp02))
8+
9+
FunctionalObjectProperty(:objProp01)
10+
11+
Declaration(NamedIndividual(:indivA))
12+
Declaration(NamedIndividual(:indivB))
13+
Declaration(NamedIndividual(:indivC))
14+
Declaration(NamedIndividual(:indivD))
15+
Declaration(NamedIndividual(:indivE))
16+
Declaration(NamedIndividual(:indivF))
17+
18+
ObjectPropertyAssertion(:objProp01 :indivA :indivB)
19+
ObjectPropertyAssertion(:objProp01 :indivA :indivC)
20+
ObjectPropertyAssertion(:objProp01 :indivA :indivD)
21+
ObjectPropertyAssertion(:objProp02 :indivE :indivF)
22+
)

sansa-inference-spark/src/test/scala/net/sansa_stack/inference/spark/forwardchaining/axioms/ForwardRuleReasonerOWLHorstTest.scala

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ class ForwardRuleReasonerOWLHorstTest extends FunSuite with SharedSparkContext w
212212
/**
213213
* R5:
214214
* Condition:
215-
* p rdfs:range o , s p v
215+
* p rdfs:range o
216+
* s p v
216217
* Consequence:
217218
* v rdf:type o
218219
*/
@@ -265,4 +266,48 @@ class ForwardRuleReasonerOWLHorstTest extends FunSuite with SharedSparkContext w
265266
assert(inferred.contains(df.getOWLClassAssertionAxiom(cls01, indivA)))
266267
assert(inferred.contains(df.getOWLClassAssertionAxiom(cls01, indivB)))
267268
}
269+
270+
/**
271+
* O1:
272+
* Condition:
273+
* p rdf:type owl:FunctionalProperty
274+
* u p v
275+
* u p w
276+
* Consequence:
277+
* v owl:sameAs w
278+
*/
279+
test("Rule O1 should return correct results") {
280+
val indivB = df.getOWLNamedIndividual(defaultPrefix + "indivB")
281+
val indivC = df.getOWLNamedIndividual(defaultPrefix + "indivC")
282+
val indivD = df.getOWLNamedIndividual(defaultPrefix + "indivD")
283+
284+
val input = getClass.getResource(resourcePath + "test_o1.owl").getPath
285+
286+
val axiomsRDD = spark.owl(Syntax.FUNCTIONAL)(input)
287+
val reasoner = new ForwardRuleReasonerOWLHorst(sc, sc.defaultMinPartitions)
288+
val inferred: Seq[OWLAxiom] = reasoner.apply(axiomsRDD).collect()
289+
290+
// It should be either one axiom inferred:
291+
// SameIndividual(:indivB :indivC :indivD)
292+
// or three pairwise axioms:
293+
// SameIndividual(:indivB :indivC)
294+
// SameIndividual(:indivB :indivD)
295+
// SameIndividual(:indivC :indivD)
296+
// (where the individual operand pairs may be in arbitrary order)
297+
// Permutations are assumed to be handled by the axiom's equals method
298+
inferred.size match {
299+
case 1 => assert(
300+
inferred.contains(
301+
df.getOWLSameIndividualAxiom(Seq(indivB, indivC, indivD).asJava)))
302+
case 3 =>
303+
assert( // B == C
304+
inferred.contains(df.getOWLSameIndividualAxiom(indivB, indivC)))
305+
assert( // B == D
306+
inferred.contains(df.getOWLSameIndividualAxiom(indivB, indivD)))
307+
assert( // C == D
308+
inferred.contains(df.getOWLSameIndividualAxiom(indivC, indivD))
309+
)
310+
case _ => assert(false)
311+
}
312+
}
268313
}

0 commit comments

Comments
 (0)