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

Commit 0850f22

Browse files
Generalized methods for TC.
1 parent 6aca7a1 commit 0850f22

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

sansa-inference-common/src/main/scala/net/sansa_stack/inference/utils/CollectionUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object CollectionUtils {
1313
* @param tuples the tuples
1414
* @return the multimap
1515
*/
16-
def toMultiMap(tuples: Seq[(String, String)]) = {
16+
def toMultiMap(tuples: Iterable[(String, String)]) = {
1717
tuples.groupBy(e => e._1).mapValues(e => e.map(x => x._2).toSet).map(identity)
1818
}
1919

sansa-inference-spark/src/main/scala/net/sansa_stack/inference/spark/forwardchaining/ForwardRuleReasonerOWLHorst.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class ForwardRuleReasonerOWLHorst(sc: SparkContext, parallelism: Int) extends Fo
3737
val equivPropertyTriples = extractTriples(triplesRDD, OWL2.equivalentProperty.getURI) // owl:equivalentProperty
3838

3939

40-
// 1. we have to process owl:equivalentClass and owl:equivalentProperty before computing the transitive closure
40+
// 1. we have to process owl:equivalentClass (resp. owl:equivalentProperty) before computing the transitive closure
41+
// of rdfs:subClassOf (resp. rdfs:sobPropertyOf)
4142
// rdfp12a: (?C owl:equivalentClass ?D) -> (?C rdfs:subClassOf ?D )
4243
// rdfp12b: (?C owl:equivalentClass ?D) -> (?D rdfs:subClassOf ?C )
4344
subClassOfTriples = sc.union(
@@ -55,14 +56,9 @@ class ForwardRuleReasonerOWLHorst(sc: SparkContext, parallelism: Int) extends Fo
5556
.distinct()
5657

5758
// 2. we compute the transitive closure of rdfs:subPropertyOf and rdfs:subClassOf
58-
// rdfs11: (xxx rdfs:subClassOf yyy), (yyy rdfs:subClassOf zzz) -> (xxx rdfs:subClassOf zzz)
59+
// rdfs11: (xxx rdfs:subClassOf yyy), (yyy rdfs:subClassOf zzz) -> (xxx rdfs:subClassOf zzz)
5960
val subClassOfTriplesTrans = computeTransitiveClosure(subClassOfTriples)
60-
61-
/*
62-
rdfs5 xxx rdfs:subPropertyOf yyy .
63-
yyy rdfs:subPropertyOf zzz . xxx rdfs:subPropertyOf zzz .
64-
*/
65-
61+
// rdfs5: (xxx rdfs:subPropertyOf yyy), (yyy rdfs:subPropertyOf zzz) -> (xxx rdfs:subPropertyOf zzz)
6662
val subPropertyOfTriplesTrans = computeTransitiveClosure(subPropertyOfTriples)
6763

6864

@@ -86,7 +82,6 @@ class ForwardRuleReasonerOWLHorst(sc: SparkContext, parallelism: Int) extends Fo
8682
.filter(t => subClassOfMapBC.value.getOrElse(t.`object`, Set.empty).contains(t.subject))
8783
.map(t => RDFTriple(t.subject, OWL2.equivalentClass.getURI, t.`object`))
8884
)
89-
9085
// rdfp13c: (?C rdfs:subPropertyOf ?D ), (?D rdfs:subPropertyOf ?C ) -> (?C owl:equivalentProperty ?D)
9186
val equivPropTriplesInf = equivPropertyTriples.union(
9287
subPropertyOfTriplesTrans
@@ -169,6 +164,8 @@ class ForwardRuleReasonerOWLHorst(sc: SparkContext, parallelism: Int) extends Fo
169164

170165
// println("input rdf:type triples:\n" + typeTriples.collect().mkString("\n"))
171166

167+
// at this point, we have to perform fix-point iteration, i.e. we process a set of rules until no new data
168+
// has been generated
172169
var newDataInferred = true
173170
var iteration = 0
174171

@@ -270,7 +267,7 @@ class ForwardRuleReasonerOWLHorst(sc: SparkContext, parallelism: Int) extends Fo
270267
RDFTriple(s, p, o)
271268
}
272269
)
273-
println(rdfp14a.collect().mkString("\n"))
270+
// println(rdfp14a.collect().mkString("\n"))
274271

275272
// rdfp8a: (?P owl:inverseOf ?Q), (?X ?P ?Y) -> (?Y ?Q ?X)
276273
val rdfp8a = triplesFiltered

sansa-inference-spark/src/main/scala/net/sansa_stack/inference/spark/forwardchaining/TransitiveReasoner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait TransitiveReasoner extends Profiler{
2828
* @param triples the set of triples
2929
* @return a set containing the transitive closure of the triples
3030
*/
31-
def computeTransitiveClosure(triples: mutable.Set[RDFTriple]): mutable.Set[RDFTriple] = {
31+
def computeTransitiveClosure(triples: Set[RDFTriple]): Set[RDFTriple] = {
3232
val tc = addTransitive(triples)
3333
// recursive call if set changed, otherwise stop and return
3434
if (tc.size == triples.size) triples else computeTransitiveClosure(tc)
@@ -38,7 +38,7 @@ trait TransitiveReasoner extends Profiler{
3838
// s ++ (for ((s1, p1, o1) <- s; (s2, p2, o2) <- s if o1 == s2) yield (s1, p1, o2))
3939
// }
4040

41-
private def addTransitive(triples: mutable.Set[RDFTriple]) = {
41+
private def addTransitive(triples: Set[RDFTriple]): Set[RDFTriple] = {
4242
triples ++ (for (t1 <- triples; t2 <- triples if t1.`object` == t2.subject) yield RDFTriple(t1.subject, t1.predicate, t2.`object`))
4343
}
4444

0 commit comments

Comments
 (0)