This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
/
package.scala
118 lines (102 loc) · 3.93 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package net.sansa_stack.owl.spark
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
import org.semanticweb.owlapi.model.{AxiomType, OWLAxiom}
import net.sansa_stack.owl.spark.rdd._
/**
* Wrap up implicit classes/methods to read OWL data into either
* [[org.apache.spark.sql.Dataset]] or [[org.apache.spark.rdd.RDD]].
*
* @author Gezim Sejdiu
*/
package object owl {
object Syntax extends Enumeration {
val FUNCTIONAL, MANCHESTER, OWLXML = Value
}
/**
* Adds methods, `owl(syntax: Syntax)`, `functional` and `manchester`, to
* [[org.apache.spark.sql.SparkSession]] that allows to read owl files.
*/
implicit class OWLAxiomReader(spark: SparkSession) {
/**
* Load RDF data into a [[org.apache.spark.rdd.RDD]][OWLAxiom]. Currently,
* only functional, manchester and OWL/XML syntax are supported
* @param syntax of the OWL (functional, manchester or OWL/XML)
* @return a [[net.sansa_stack.owl.spark.rdd.OWLAxiomsRDD]]
*/
def owl(syntax: Syntax.Value): String => OWLAxiomsRDD = syntax match {
case Syntax.FUNCTIONAL => functional
case Syntax.MANCHESTER => manchester
case Syntax.OWLXML => owlXml
case _ => throw new IllegalArgumentException(
s"$syntax syntax not supported yet!")
}
/**
* Load OWL data in Functional syntax into an
* [[org.apache.spark.rdd.RDD]][OWLAxiom].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLAxiomsRDD]]
*/
def functional: String => OWLAxiomsRDD = path => {
FunctionalSyntaxOWLAxiomsRDDBuilder.build(spark, path)
}
/**
* Load OWL data in Manchester syntax into an
* [[org.apache.spark.rdd.RDD]][OWLAxiom].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLAxiomsRDD]]
*/
def manchester: String => OWLAxiomsRDD = path => {
ManchesterSyntaxOWLAxiomsRDDBuilder.build(spark, path)
}
/**
* Load OWL data in OWL/XML syntax into an
* [[org.apache.spark.rdd.RDD]][OWLAxiom].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLAxiomsRDD]]
*/
def owlXml: String => OWLAxiomsRDD = path => {
OWLXMLSyntaxOWLAxiomsRDDBuilder.build(spark, path)
}
}
implicit class OWLExpressionsRDDReader(spark: SparkSession) {
/**
* Load RDF data into an [[org.apache.spark.rdd.RDD]][String]. Currently,
* only functional, manchester and OWL/XML syntax are supported
* @param syntax of the OWL (functional or manchester or OWL/XML)
* @return a [[net.sansa_stack.owl.spark.rdd.OWLExpressionsRDD]]
*/
def owlExpressions(syntax: Syntax.Value): String => OWLExpressionsRDD = syntax match {
case Syntax.FUNCTIONAL => functional
case Syntax.MANCHESTER => manchester
case Syntax.OWLXML => owlXml
case _ => throw new IllegalArgumentException(
s"$syntax syntax not supported yet!")
}
/**
* Load OWL data in Functional syntax into an
* [[org.apache.spark.rdd.RDD]][String].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLExpressionsRDD]]
*/
def functional: String => OWLExpressionsRDD = path => {
FunctionalSyntaxOWLExpressionsRDDBuilder.build(spark, path)
}
/**
* Load OWL data in Manchester syntax into an
* [[org.apache.spark.rdd.RDD]][String].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLExpressionsRDD]]
*/
def manchester: String => OWLExpressionsRDD = path => {
ManchesterSyntaxOWLExpressionsRDDBuilder.build(spark, path)
}
/**
* Load OWL data in OWLXML syntax into an
* [[org.apache.spark.rdd.RDD]][String].
* @return the [[net.sansa_stack.owl.spark.rdd.OWLExpressionsRDD]]
*/
def owlXml: String => OWLExpressionsRDD = path => {
OWLXMLSyntaxOWLExpressionsRDDBuilder.build(spark, path)._3
}
}
}
package object owlAxioms {
def extractAxioms(axioms: RDD[OWLAxiom], T: AxiomType[_]): RDD[OWLAxiom] =
axioms.filter(a => a.getAxiomType.equals(T))
}