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

Commit 656b99b

Browse files
clean-up in axioms.ForwardRuleReasonerRDFS
1 parent d13bb5f commit 656b99b

File tree

1 file changed

+1
-84
lines changed

1 file changed

+1
-84
lines changed

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

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -44,110 +44,46 @@ 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
123-
val AnnProRange = axiomsRDD
124-
.filter(axiom => axiom.getAxiomType.equals(AxiomType.ANNOTATION_PROPERTY_RANGE))
125-
126-
// OWLDataPropertyAssertionAxiom
12775
val dataPropAsserAxiom = axiomsRDD
12876
.filter(axiom => axiom.getAxiomType.equals(AxiomType.DATA_PROPERTY_ASSERTION))
12977

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

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

144-
// OWLSubAnnotationPropertyAssertionAxiom
14584
val subAnnProp = axiomsRDD
14685
.filter(axiom => axiom.getAxiomType.equals(AxiomType.SUB_ANNOTATION_PROPERTY_OF))
14786

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

15389
/** OWL Horst rules:
@@ -161,32 +97,20 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
16197
val subClassOfAxiomsTrans = tr.computeTransitiveClosure(subClassofAxiom, AxiomType.SUBCLASS_OF)
16298
.setName("rdfs11")
16399

164-
// println("\n Transitive subClassOfAxiom closures: \n----------------\n")
165-
// subClassOfAxiomsTrans.collect().foreach(println)
166-
167100
/* rule 2 --> rule 2a, rule 2b
168101
rdfs5 x rdfs:subPropertyOf y .
169102
y rdfs:subPropertyOf z -> x rdfs:subPropertyOf z .
170103
to calculate rdf5 we need to get subDataProperty and subObjectProperty
171104
*/
172105

173-
// val subDataPropertyOfAxiomsTrans = tr.computeSubDataPropertyTransitiveClosure(subDataPropertyofAxiom).setName("rdfs5")
174106
val subDataPropertyOfAxiomsTrans = tr.computeTransitiveClosure(subDataPropertyofAxiom, AxiomType.SUB_DATA_PROPERTY)
175107
.setName("rdfs5a")
176108

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

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

191115
var allAxioms = axioms.union(subObjectPropertyOfAxiomsTrans)
192116
.union(subDataPropertyOfAxiomsTrans.asInstanceOf[RDD[OWLAxiom]])
@@ -292,10 +216,6 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
292216
dataFactory.getOWLNamedIndividual(a.getSubject.toString)))
293217
.setName("rdfs2c")
294218

295-
// println("\n Annotation domain: \n----------------\n")
296-
// RDFS2c.collect().foreach(println)
297-
298-
299219
/* rule 5: --> rule 5a, rule 5b
300220
301221
rdfs3: a rdfs:range x . y a z --> z rdf:type x .
@@ -351,7 +271,7 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
351271
val infered = allAxioms.subtract(axioms)
352272
val inferedCount = infered.count()
353273

354-
println("\n Finish with " + inferedCount + " Inferred Axioms")
274+
println("Finish with " + inferedCount + " inferred axioms")
355275
infered
356276

357277
}
@@ -374,7 +294,6 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
374294
// val sparkSession = SparkSession.builder
375295
// .master("local[*]")
376296
// .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
377-
// // .config("spark.kryo.registrator", "net.sansa_stack.inference.spark.forwardchaining.axioms.Registrator")
378297
// .appName("OWL Axioms Forward Rule Reasoner")
379298
// .getOrCreate()
380299
//
@@ -383,8 +302,6 @@ class ForwardRuleReasonerRDFS(sc: SparkContext, parallelism: Int = 2) extends Lo
383302
// // Call the functional syntax OWLAxiom builder
384303
//
385304
// var owlAxiomsRDD = FunctionalSyntaxOWLAxiomsRDDBuilder.build(sparkSession, input)
386-
// // owlAxiomsRDD.collect().foreach(println)
387-
//
388305
// val ruleReasoner = new ForwardRuleReasonerRDFS(sc, 2)
389306
// val res: RDD[OWLAxiom] = ruleReasoner(owlAxiomsRDD)
390307
//

0 commit comments

Comments
 (0)