This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:site:recherche:logiciels:sparqlwithspark:utility [15/09/2016 15:37] hubert |
en:site:recherche:logiciels:sparqlwithspark:utility [16/09/2016 23:05] (current) hubert [Utilities] |
||
---|---|---|---|
Line 6: | Line 6: | ||
=== Data loading utilities=== | === Data loading utilities=== | ||
- | <code> | + | <code scala> |
// TIMER | // TIMER | ||
Line 73: | Line 73: | ||
=== QUERY utilities === | === QUERY utilities === | ||
- | <code> | + | <code scala> |
case class v(n:Int) | case class v(n:Int) | ||
Line 86: | Line 86: | ||
} | } | ||
- | + | // encode properties and literals in a query | |
- | // encode property and literal | + | |
def sparqlEncode(splittedSparql: List[(Any, (String, String), Any)]): List[(Any, Int, Any)] = { | def sparqlEncode(splittedSparql: List[(Any, (String, String), Any)]): List[(Any, Int, Any)] = { | ||
return splittedSparql.map{ case (s,(ns,p),o) => | return splittedSparql.map{ case (s,(ns,p),o) => | ||
val idP = getIdP(ns, p) | val idP = getIdP(ns, p) | ||
- | (s,o) match { | + | (s, o) match { |
- | case(a:v, b:v)=> (a, idP, b) | + | case(v(a), v(b))=> (v(a), idP, v(b)) |
- | case(lit:String, b:v) => { val idLit = getIdSO(lit.split(":")(0), lit.split(":")(1)) | + | case(lit:String, v(b)) => { val idLit = getIdSO(lit.split(":")(0), lit.split(":")(1)) |
- | (idLit, idP, b)} | + | (idLit, idP, v(b))} |
- | case(a:v,lit:String) => { val idLit = getIdSO(lit.split(":")(0), lit.split(":")(1)) | + | case(v(a), lit:String) => { val idLit = getIdSO(lit.split(":")(0), lit.split(":")(1)) |
- | (a, idP, idLit)} | + | (v(a), idP, idLit)} |
}}} | }}} | ||
+ | // generate selection operator for each triple pattern | ||
def tpOperators(encodedQuery: List[(Any, Int, Any)], d: Map[Int, DataFrame]) = | def tpOperators(encodedQuery: List[(Any, Int, Any)], d: Map[Int, DataFrame]) = | ||
encodedQuery.map{ case(v(a), p, v(b))=> ( (v(a), p, v(b)), d(p).withColumnRenamed("o", s"v$b")) | encodedQuery.map{ case(v(a), p, v(b))=> ( (v(a), p, v(b)), d(p).withColumnRenamed("o", s"v$b")) |