在过去的几个月里,我一直在编写大量的Scala + RDF4J。到目前一切尚好。
我今天刚写了这个,应用程序不会终止。它打印出所请求的三个三元组和单词“已完成”,但没有返回到sbt命令提示符(或者,在Eclipse中,停止按钮保持红色,悬停在run按钮上,显示一个“已经在运行的消息”)
我到底做错了什么?我运行它是针对几个不同的端点,包括RDF4J服务器、Virtuoso和Blazegraph。
我的线人
import org.eclipse.rdf4j.query.QueryLanguage
import org.eclipse.rdf4j.repository.sparql.SPARQLRepository
object sharedMain {
def main(args: Array[String]): Unit = {
val sparqlEndpoint = "https://dbpedia.org/sparql"
val SparqlRepo = new SPARQLRepository(sparqlEndpoint)
SparqlRepo.initialize()
var con = SparqlRepo.getConnection()
var queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } limit 3 "
val tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString)
var result = tupleQuery.evaluate()
while (result.hasNext()) { // iterate over the result
val bindingSet = result.next()
val valueOfX = bindingSet.getValue("x")
val valueOfY = bindingSet.getValue("y")
val toPrint = valueOfX + " -> " + valueOfY
println(toPrint)
}
result.close
con.close
println("done")
}
}我的build.sbt
name := "tripleStoreTesting"
version := "0.1"
scalaVersion := "2.12.0"
resolvers += Classpaths.typesafeReleases
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.1.5" % "runtime",
"org.scalactic" %% "scalactic" % "3.0.1",
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.eclipse.rdf4j" % "rdf4j-runtime" % "2.2.2",
"commons-logging" % "commons-logging" % "1.2"
)
mainClass := Some("sharedMain")发布于 2017-07-26 13:53:18
正如AKSW建议的那样,我没有关闭或关闭我打开、启动、初始化等所有内容。
// Scala code snippet,
// starting with my program's last interaction with the triplestore
while (result.hasNext) { // iterate over the result
val bindingSet = result.next
val valueOfX = bindingSet.getValue("x")
val valueOfY = bindingSet.getValue("y")
val toPrint = valueOfX + " -> " + valueOfY
println(toPrint)
}
result.close
con.close
// ADD THIS for proper application termination
SparqlRepo.shutDown除了JavaDocs AKSW发布之外,RDF4J编程教程还很好地强调了许多需要适当关闭的东西。
它只是没有特别提到关闭SPARQLRepository实例。
https://stackoverflow.com/questions/45246857
复制相似问题