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

Commit c0b16d7

Browse files
clean-up in axioms.ForwardRuleReasonerRDFS
1 parent 63f1b89 commit c0b16d7

File tree

1 file changed

+1
-80
lines changed

1 file changed

+1
-80
lines changed

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

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -44,110 +44,49 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
4444
case _ => null
4545
}.filter(_ != null).distinct()
4646

47-
// println("\n\nOWL Classes\n-------\n")
48-
// classes.collect().foreach(println)
49-
50-
// OWLClassAssertionAxiom
5147
val classAsserAxiom = axiomsRDD
5248
.filter(axiom => axiom.getAxiomType.equals(AxiomType.CLASS_ASSERTION))
5349
.asInstanceOf[RDD[OWLClassAssertionAxiom]].cache()
5450

55-
// val cmap: Map[OWLClassExpression, Set[OWLIndividual]] = CollectionUtils
56-
// .toMultiMap(classAsserAxiom.asInstanceOf[RDD[OWLClassAssertionAxiom]]
57-
// .map(a => (a.getClassExpression, a.getIndividual)).collect())
58-
// val c: Broadcast[Map[OWLClassExpression, Set[OWLIndividual]]] = sc.broadcast(cmap)
59-
60-
// val r = new Reasoner(axioms)
61-
// val b: RDD[OWLClassAssertionAxiom] = classAsserAxiom.filter(a => r.isEntailed(a))
62-
// println("\n\nb\n-------\n")
63-
//
64-
// b.take(b.count().toInt).foreach(println(_))
65-
66-
// println("\n\nOWLClassAssertionAxioms\n-------\n")
67-
// classAsserAxiom.collect().foreach(println)
68-
69-
// OWLSubClassofAxiom
7051
val subClassofAxiom: RDD[OWLAxiom] = axiomsRDD
7152
.filter(axiom => axiom.getAxiomType.equals(AxiomType.SUBCLASS_OF))
7253

73-
// println("\n\nOWLSubClassofAxioms\n-------\n")
74-
// subClassofAxiom.collect().foreach(println)
75-
76-
// OWLSubDataPropertyofAxiom
7754
val subDataPropertyofAxiom = axiomsRDD
7855
.filter(axiom => axiom.getAxiomType.equals(AxiomType.SUB_DATA_PROPERTY))
7956

80-
// println("\n\nOWLSubDataPropertyofAxioms\n-------\n")
81-
// subDataPropertyofAxiom.collect().foreach(println)
82-
83-
// OWLSubObjectPropertyofAxiom
8457
val subObjectPropertyofAxiom = axiomsRDD
8558
.filter(axiom => axiom.getAxiomType.equals(AxiomType.SUB_OBJECT_PROPERTY))
8659

87-
// println("\n\nOWLSubObjectPropertyofAxioms\n-------\n")
88-
// subObjectPropertyofAxiom.collect().foreach(println)
89-
90-
// OWLObjectPropertyDomainAxiom
9160
val objectProDomain = axiomsRDD
9261
.filter(axiom => axiom.getAxiomType.equals(AxiomType.OBJECT_PROPERTY_DOMAIN))
9362

94-
// println("\n\nOWLObjectPropertyDomainAxiom\n-------\n")
95-
// objectProDomain.collect().foreach(println)
96-
97-
// OWLDataPropertyDomainAxiom
9863
val dataProDomain = axiomsRDD
9964
.filter(axiom => axiom.getAxiomType.equals(AxiomType.DATA_PROPERTY_DOMAIN))
10065

101-
// println("\n\nOWLDataPropertyDomainAxiom\n-------\n")
102-
// dataProDomain.collect().foreach(println)
103-
104-
// OWLAnnotationPropertyDomainAxiom
10566
val AnnProDomain = axiomsRDD
10667
.filter(axiom => axiom.getAxiomType.equals(AxiomType.ANNOTATION_PROPERTY_DOMAIN))
10768

108-
// OWLDataPropertyRangeAxiom
10969
val dataProRange = axiomsRDD
11070
.filter(axiom => axiom.getAxiomType.equals(AxiomType.DATA_PROPERTY_RANGE))
11171

112-
// println("\n\nOWLDataPropertyRangeAxiom\n-------\n")
113-
// dataProRange.collect().foreach(println)
114-
115-
// OWLObjectPropertyRangeAxiom
11672
val objProRange = axiomsRDD
11773
.filter(axiom => axiom.getAxiomType.equals(AxiomType.OBJECT_PROPERTY_RANGE))
11874

119-
// println("\n\nOWLObjectPropertyRangeAxiom\n-------\n")
120-
// objProRange.collect().foreach(println)
121-
122-
// OWLAnnotationPropertyRangeAxiom
12375
val AnnProRange = axiomsRDD
12476
.filter(axiom => axiom.getAxiomType.equals(AxiomType.ANNOTATION_PROPERTY_RANGE))
12577

126-
// OWLDataPropertyAssertionAxiom
12778
val dataPropAsserAxiom = axiomsRDD
12879
.filter(axiom => axiom.getAxiomType.equals(AxiomType.DATA_PROPERTY_ASSERTION))
12980

130-
// println("\n\nOWLDataPropertyAssertionAxiom\n-------\n")
131-
// dataPropAsserAxiom.collect().foreach(println)
132-
133-
// OWLObjectPropertyAssertionAxiom
13481
val objPropAsserAxiom = axiomsRDD
13582
.filter(axiom => axiom.getAxiomType.equals(AxiomType.OBJECT_PROPERTY_ASSERTION))
13683

137-
// println("\n\nOWLObjectPropertyAssertionAxiom\n-------\n")
138-
// objPropAsserAxiom.collect().foreach(println)
139-
140-
// OWLAnnotationPropertyAssertionAxiom
14184
val AnnAsserAxiom = axiomsRDD
14285
.filter(axiom => axiom.getAxiomType.equals(AxiomType.ANNOTATION_ASSERTION))
14386

144-
// OWLSubAnnotationPropertyAssertionAxiom
14587
val subAnnProp = axiomsRDD
14688
.filter(axiom => axiom.getAxiomType.equals(AxiomType.SUB_ANNOTATION_PROPERTY_OF))
14789

148-
// println("\n\nOWLSubAnnotationPropertyOAxiom\n-------\n")
149-
// subAnnProp.collect().foreach(println)
150-
15190
// start to calculate transitive rules
15291

15392
/** OWL Horst rules:
@@ -161,32 +100,20 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
161100
val subClassOfAxiomsTrans = tr.computeTransitiveClosure(subClassofAxiom, AxiomType.SUBCLASS_OF)
162101
.setName("rdfs11")
163102

164-
// println("\n Transitive subClassOfAxiom closures: \n----------------\n")
165-
// subClassOfAxiomsTrans.collect().foreach(println)
166-
167103
/* rule 2 --> rule 2a, rule 2b
168104
rdfs5 x rdfs:subPropertyOf y .
169105
y rdfs:subPropertyOf z -> x rdfs:subPropertyOf z .
170106
to calculate rdf5 we need to get subDataProperty and subObjectProperty
171107
*/
172108

173-
// val subDataPropertyOfAxiomsTrans = tr.computeSubDataPropertyTransitiveClosure(subDataPropertyofAxiom).setName("rdfs5")
174109
val subDataPropertyOfAxiomsTrans = tr.computeTransitiveClosure(subDataPropertyofAxiom, AxiomType.SUB_DATA_PROPERTY)
175110
.setName("rdfs5a")
176111

177-
// println("\n Transitive subDataPropertyOfAxiom closures: \n----------------\n")
178-
// subDataPropertyOfAxiomsTrans.collect().foreach(println)
179-
180112
val subObjectPropertyOfAxiomsTrans = tr.computeTransitiveClosure(subObjectPropertyofAxiom, AxiomType.SUB_OBJECT_PROPERTY)
181113
.setName("rdfs5b")
182114

183-
// println("\n Transitive subObjectPropertyOfAxiom closures: \n----------------\n")
184-
// subObjectPropertyOfAxiomsTrans.collect().foreach(println)
185-
186115
val subAnnotationPropertyOfAxiomsTrans = tr.computeTransitiveClosure(subAnnProp, AxiomType.SUB_ANNOTATION_PROPERTY_OF)
187116
.setName("rdfs5c")
188-
// println("\n Transitive subAnnotationPropertyOfAxiom closures: \n----------------\n")
189-
// subAnnotationPropertyOfAxiomsTrans.collect().foreach(println)
190117

191118
var allAxioms = axioms.union(subObjectPropertyOfAxiomsTrans)
192119
.union(subDataPropertyOfAxiomsTrans.asInstanceOf[RDD[OWLAxiom]])
@@ -292,17 +219,14 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
292219
dataFactory.getOWLNamedIndividual(a.getSubject.toString)))
293220
.setName("rdfs2c")
294221

295-
// println("\n Annotation domain: \n----------------\n")
296-
// RDFS2c.collect().foreach(println)
297-
298-
299222
/* rule 5: --> rule 5a, rule 5b
300223
301224
rdfs3: a rdfs:range x . y a z --> z rdf:type x .
302225
*/
303226

304227
val dataRangeMap = dataProRange.asInstanceOf[RDD[OWLDataPropertyRangeAxiom]]
305228
.map(a => (a.getProperty, a.getRange)).collect().toMap
229+
306230
val dataRangeMapBC = sc.broadcast(dataRangeMap)
307231

308232
val RDFS3a = dataPropAsserAxiom.asInstanceOf[RDD[OWLDataPropertyAssertionAxiom]]
@@ -374,7 +298,6 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
374298
// val sparkSession = SparkSession.builder
375299
// .master("local[*]")
376300
// .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
377-
// // .config("spark.kryo.registrator", "net.sansa_stack.inference.spark.forwardchaining.axioms.Registrator")
378301
// .appName("OWL Axioms Forward Rule Reasoner")
379302
// .getOrCreate()
380303
//
@@ -383,8 +306,6 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
383306
// // Call the functional syntax OWLAxiom builder
384307
//
385308
// var owlAxiomsRDD = FunctionalSyntaxOWLAxiomsRDDBuilder.build(sparkSession, input)
386-
// // owlAxiomsRDD.collect().foreach(println)
387-
//
388309
// val ruleReasoner = new ForwardRuleReasonerRDFS(sc, 2)
389310
// val res: RDD[OWLAxiom] = ruleReasoner(owlAxiomsRDD)
390311
//

0 commit comments

Comments
 (0)