/
TestRDFCache.scala
83 lines (74 loc) · 2.37 KB
/
TestRDFCache.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
package deductions.runtime.sparql_cache
import deductions.runtime.jena.{RDFCache, RDFStoreLocalJenaProvider}
import deductions.runtime.utils.{DefaultConfiguration, FileUtils}
import org.scalatest.{BeforeAndAfterAll, FunSuite}
import org.w3.banana.SparqlOpsModule
import org.w3.banana.jena.JenaModule
//@Ignore
class TestRDFCache extends FunSuite with RDFCache
with SparqlOpsModule
with BeforeAndAfterAll
with JenaModule
with RDFStoreLocalJenaProvider
with SitesURLForDownload {
val config = new DefaultConfiguration {
override val useTextQuery = false
}
val uri = "http://jmvanel.free.fr/jmv.rdf#me"
// val uri2 = "http://live.dbpedia.org/page/Taraxacum_japonicum"
// val uri2 = uri
val uri2 = githubcontent + "/jmvanel/rdf-i18n/master/foaf/foaf.fr.ttl"
import ops._
import sparqlOps._
override def afterAll {
// FileUtils.deleteLocalSPARQL()
close()
close(dataset2)
println("afterAll: close TDB & TDB2")
}
test("save to enpoint cache and check with SPARQL that endpoint is populated.") {
val uriNode = makeUri(uri)
println("test 1")
val gr = retrieveURI(uriNode, dataset)
println("test 2")
println(s"rdfStore: $rdfStore")
val r = rdfStore.r(dataset, {
println(s"gr: $gr")
println("graph from " + uri + " size " + gr.getOrElse(emptyGraph).size)
val g = rdfStore.getGraph(dataset, uriNode)
g
})
// println("rdfStore.getGraph( dataset, uriNode).get " + g.get)
checkNamedGraph(uri)
}
test("save to enpoint cache with storeURI() and check with SPARQL.") {
val uriNode = makeUri(uri2)
println(s"test 3 $uriNode")
readStoreUriInNamedGraph(uriNode)
println("test 4")
checkNamedGraph(uri2)
println("In this case only the 2 triples for the timestamp")
}
/** check with SPARQL that endpoint is populated. */
def checkNamedGraph(uri: String) = {
val queryString = s"""
CONSTRUCT {
<$uri> ?P ?V .
<$uri> <is:in> ?G .
}
WHERE {
GRAPH ?G { <$uri> ?P ?V . }
}"""
// println("queryString\n"+ queryString)
rdfStore.r(dataset, {
val result = for {
query <- parseConstruct(queryString)
es <- rdfStore.executeConstruct(dataset, query, Map())
} yield es
val r = result.get
val size = r.size()
println("checkNamedGraph size " + size)
assert(size > 0)
})
}
}