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

Commit 58a1798

Browse files
Minor clean-ups
1 parent 32ae39a commit 58a1798

2 files changed

Lines changed: 14 additions & 43 deletions

File tree

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

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
5454
private val logger = com.typesafe.scalalogging.Logger(
5555
LoggerFactory.getLogger(this.getClass.getName))
5656

57-
var extractSchemaTriplesInAdvance: Boolean = false
58-
5957
// ------------------ <rule definitions> ------------------------------------
6058
case class Rule(name: String, getInferredTriples: RDD[Triple] => RDD[Triple]) {
6159
private var influencedRules: List[Rule] = List.empty
@@ -284,17 +282,9 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
284282

285283
val startTime = System.currentTimeMillis()
286284

287-
val triplesRDD = graph.triples
285+
var triplesRDD = graph.triples
288286
triplesRDD.cache()
289287

290-
// as an optimization, we can extract all schema triples first which avoids
291-
// to run on the whole dataset for each schema triple later
292-
var schemaTriples = if (extractSchemaTriplesInAdvance) {
293-
new RDFSSchemaExtractor().extract(triplesRDD)
294-
} else {
295-
triplesRDD
296-
}
297-
298288
// TODO: optimze order!
299289
val rulesQueue: mutable.Queue[Rule] =
300290
mutable.Queue(cr1, cr2, cr3, cr4, cr5, cr10, cr11)
@@ -303,30 +293,29 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
303293
var inferredTriples: RDD[Triple] = null
304294
while (rulesQueue.nonEmpty) {
305295
rule = rulesQueue.dequeue()
306-
inferredTriples = rule.getInferredTriples(schemaTriples)
296+
inferredTriples = rule.getInferredTriples(triplesRDD)
307297
logger.info("---- Inferred " + inferredTriples.count() + " triples")
308298

309299
if (!inferredTriples.isEmpty()) {
310300
// Check whether something new was inferred
311-
val oldCount = schemaTriples.count()
312-
schemaTriples = schemaTriples.union(inferredTriples).distinct(parallelism)
313-
val newCount = schemaTriples.count()
301+
val oldCount = triplesRDD.count()
302+
triplesRDD = triplesRDD.union(inferredTriples).distinct(parallelism)
303+
val newCount = triplesRDD.count()
314304
if (newCount > oldCount) {
315305
rule.getInfluencedRules().foreach(rulesQueue.enqueue(_))
316306
}
317307
}
318308
}
319309

320-
RDFGraph(schemaTriples)
310+
RDFGraph(triplesRDD)
321311
}
322312

323313
/**
324314
* Extracts subclass-of relations of atomic classes,
325315
* i.e. SubClass \sqsubseteq SuperClass .
326316
* These relations are returned as pairs (SubClass, SuperClass).
327317
*
328-
* @param triples The RDD with the triples `.apply( )` was called with (or
329-
* just the schema part of it)
318+
* @param triples Input Triple RDD
330319
* @return An RDD of pairs of the shape (SubClass, SuperClass)
331320
*/
332321
private def extractAtomicSubClassOf(triples: RDD[Triple]): RDD[(Node, Node)] = {
@@ -346,8 +335,7 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
346335
* The extistential restrictions are returned as triplets of the form
347336
* (_:1, property, FillerClass).
348337
*
349-
* @param triples The RDD with the triples `.apply( )` was called with (or
350-
* just the schema part of it)
338+
* @param triples Input Triple RDD
351339
* @return An RDD of triplets holding the blank node, the property and the
352340
* filler class
353341
*/
@@ -372,8 +360,7 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
372360
* only be called from within ForwardRuleReasonerEL. Otherwise the caching
373361
* (as it is implemented right) now won't work.
374362
*
375-
* @param triples The RDD with the triples `.apply( )` was called with (or
376-
* just the schema part of it)
363+
* @param triples Input Triple RDD
377364
* @return An RDD of triplets of the shape (Class1, Class2, SuperClass)
378365
*/
379366
private[triples] def extractIntersectionSCORelations(triples: RDD[Triple]): RDD[(Node, Node, Node)] = {
@@ -408,15 +395,10 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
408395
/**
409396
* Extracts subclass-of relations with an existential restrictions as
410397
* subclass, i.e. \exists property.FillerClass \sqsubseteq SuperClass .
411-
* These relarions are returned as triplets
398+
* These relations are returned as triplets
412399
* (property, FillerClass, SuperClass).
413400
*
414-
* This method is not part of the ForwardRuleReasoner interface and should
415-
* only be called from within ForwardRuleReasonerEL. Otherwise the caching
416-
* (as it is implemented right) now won't work.
417-
*
418-
* @param triples The RDD with the triples `.apply( )` was called with (or
419-
* just the schema part of it)
401+
* @param triples Input Triple RDD
420402
* @return An RDD of triplets of the shape (property, FillerClass, SuperClass)
421403
*/
422404
private[triples] def extractExistentialSCORelations(triples: RDD[Triple]): RDD[(Node, Node, Node)] = {
@@ -433,12 +415,7 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
433415
* These relations are returned as triplets
434416
* (SubClass, property, FillerClass).
435417
*
436-
* This method is not part of the ForwardRuleReasoner interface and should
437-
* only be called from within ForwardRuleReasonerEL. Otherwise the caching
438-
* (as it is implemented right) now won't work.
439-
*
440-
* @param triples The RDD with the triples `.apply( )` was called with (or
441-
* just the schema part of it)
418+
* @param triples Input Triple RDD
442419
* @return An RDD of triplets of the shape (SubClass, property, FillerClass)
443420
*/
444421
private[triples] def extractSCOExistentialRelations(triples: RDD[Triple]): RDD[(Node, Node, Node)] = {
@@ -453,11 +430,7 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
453430
* Extracts subproperty-of relations, i.e. subProp \sqsubseteq superProp .
454431
* The relations are returned as pairs (subProp, superProp).
455432
*
456-
* This method is not part of the ForwardRuleReasoner interface and should
457-
* only be called from within ForwardRuleReasonerEL.
458-
*
459-
* @param triples The RDD with the triples `.apply( )` was called with (or
460-
* just the schema part of it)
433+
* @param triples Input Triple RDD
461434
* @return An RDD of pairs of the shape (subProp, superProp)
462435
*/
463436
private[triples] def extractSubPropertyOfRelations(triples: RDD[Triple]): RDD[(Node, Node)] = {
@@ -481,8 +454,7 @@ class ForwardRuleReasonerEL (sc: SparkContext, parallelism: Int = 2) extends Tra
481454
* This method is not part of the ForwardRuleReasoner interface and should
482455
* only be called from within ForwardRuleReasonerEL.
483456
*
484-
* @param triples The RDD with the triples `.apply( )` was called with (or
485-
* just the schema part of it)
457+
* @param triples Input Triple RDD
486458
* @return An RDD of triplets of
487459
*/
488460
private[triples] def extractPropertyChainRelations(triples: RDD[Triple]): RDD[(Node, Node, Node)] = {

sansa-inference-spark/src/test/scala/net/sansa_stack/inference/spark/forwardchaining/triples/ForwardRuleReasonerELTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class ForwardRuleReasonerELTest extends FunSuite with SharedSparkContext {
3737
}
3838

3939
private def uri(uriString: String) = NodeFactory.createURI(uriString)
40-
private def bNode = NodeFactory.createBlankNode()
4140

4241
test("Subclass-of relations with intersections as subclass should be extracted correctly") {
4342
val ttlStr =

0 commit comments

Comments
 (0)