11package net .sansa_stack .inference .rules .minimizer
22import scala .collection .mutable .{ArrayBuffer , Buffer }
3+
34import scalax .collection .Graph
45import scalax .collection .edge .LDiEdge
56import scala .collection .JavaConverters ._
6- import scalax .collection .GraphTraversal . Parameters
7+ import scala .collection .mutable
78
9+ import scalax .collection .GraphTraversal .Parameters
810import org .apache .jena .graph .{Node , NodeFactory }
911import org .apache .jena .reasoner .TriplePattern
1012import org .apache .jena .reasoner .rulesys .Rule
@@ -16,7 +18,6 @@ import net.sansa_stack.inference.rules.RuleDependencyGraphGenerator.{asString, d
1618import net .sansa_stack .inference .utils .{GraphUtils , RuleUtils }
1719import net .sansa_stack .inference .utils .graph .LabeledEdge
1820import net .sansa_stack .inference .utils .RuleUtils ._
19-
2021import scalax .collection .GraphTraversal .Parameters
2122import scalax .collection ._
2223import scalax .collection .edge .Implicits ._
@@ -294,11 +295,13 @@ abstract class RuleDependencyGraphMinimizer extends MinimizationRuleExecutor {
294295// debug(cycles.asScala.mkString(","))
295296
296297 // cycles that contain the current node
297- val cyclesWithNode : Buffer [Buffer [Rule ]] = allCycles.asScala.filter(cycle => cycle.contains(node.value)).map(cycle => cycle.asScala)
298+ val cyclesWithNode : mutable.Buffer [mutable.Buffer [Rule ]] = allCycles.asScala
299+ .filter(cycle => cycle.contains(node.value))
300+ .map(cycle => cycle.asScala)
298301 debug(" Cycles: " + cyclesWithNode.map(c => c.map(r => r.getName)).mkString(" ," ))
299302
300303 // cycles that use the same property
301- val cyclesWithNodeSameProp : Map [Node , scala.List [Buffer [graph.EdgeT ]]] = cyclesWithNode.map(cycle => {
304+ val cyclesWithNodeSameProp : Map [Node , scala.List [mutable. Buffer [graph.EdgeT ]]] = cyclesWithNode.map(cycle => {
302305
303306 debug(" Cycle: " + cycle.map(r => r.getName).mkString(" , " ))
304307
@@ -307,12 +310,12 @@ abstract class RuleDependencyGraphMinimizer extends MinimizationRuleExecutor {
307310 pairsOfRules :+= (cycle.last, cycle(0 ))
308311
309312 // map to list of edges
310- val edges : Buffer [graph.EdgeT ] = pairsOfRules.map (e => {
313+ val edges : mutable. Buffer [graph.EdgeT ] = pairsOfRules.flatMap (e => {
311314 val node1 = graph get e._1
312315 val node2 = graph get e._2
313316
314317 node1.outgoing.filter(_.target == node2)
315- }).flatten
318+ })
316319 debug(" Edges: " + edges.mkString(" , " ))
317320
318321 // map to edge labels, i.e. the predicates
@@ -325,9 +328,14 @@ abstract class RuleDependencyGraphMinimizer extends MinimizationRuleExecutor {
325328 if (samePred) Some (predicates(0 ), edges) else None
326329 }).filter(_.isDefined).map(_.get).groupBy(e => e._1).mapValues(e => e.map(x => x._2).toList)
327330
328- var removedCycles : collection.mutable.Set [Buffer [graph.EdgeT ]] = collection.mutable.Set ()
331+ var removedCycles : collection.mutable.Set [mutable. Buffer [graph.EdgeT ]] = collection.mutable.Set ()
329332
330- val tmp : Map [Node , Map [Int , List [Buffer [graph.EdgeT ]]]] = cyclesWithNodeSameProp.mapValues(value => value.map(cycle => (cycle.size, cycle)).groupBy(_._1).mapValues(e => e.map(x => x._2).toList))
333+ val tmp : Map [Node , Map [Int , List [mutable.Buffer [graph.EdgeT ]]]] =
334+ cyclesWithNodeSameProp
335+ .mapValues(value =>
336+ value.map(cycle => (cycle.size, cycle))
337+ .groupBy(_._1)
338+ .mapValues(e => e.map(x => x._2)))
331339
332340 tmp.foreach(predicate2Cycles => {
333341 debug(" predicate: " + predicate2Cycles._1)
0 commit comments