0

我正在尝试在 scala 中构建一个 sparql 查询。我在使用适用于 java 的 apache arq 库时遇到问题。依赖项似乎都很好,但 Intellij 无法解析 ParameterizedSparqlString 构造函数并导致 QueryEngineHTTP 构造函数。我正在运行 jdk 1.8。有任何想法吗?赞赏!!

val sparqlentities = namedEntitiesByDocument
  .mapPartitions(iter => {
    val sparqlEndpoint = "localhost:1643";
    iter.map( t => {
      t._1, t._2.map(namedEntity => {
        val sparqlQuery = "" + "SELECT  ?s { \n ?s rdfs:label" + namedEntity.surfaceForm + " . \n }"
        val query = QueryFactory.create(sparqlQuery, Syntax.syntaxARQ)
        // val querySolutionMap = new QuerySolutionMap()
        val parameterizedSparqlString = new ParameterizedSparqlString(query.toString(), new QuerySolutionMap())
        val httpQuery = new QueryEngineHTTP(sparqlEndpoint,parameterizedSparqlString.asQuery())
        val results = httpQuery.execSelect()
        while (results.hasNext()) {
          val solution = results.next()
          val fin_result = solution.get("s").asLiteral().getLexicalForm()
          (namedEntity.surfaceForm, fin_result)
        }
      })
    })
  })
4

2 回答 2

3

(评论不适用于复杂的文本,因此这个答案)

ParameterizedSparqlString如果您自己进行字符串构建,则不需要 a 。创建一个查询字符串,解析它,然后调用.toString有点复杂。QueryFactory然后就可以使用了QueryExecutionFactory

请注意,在

val sparqlQuery = "" + "SELECT ?s { \n ?s rdfs:label" + namedEntity.surfaceForm + " . \n }" namedEntity.surfaceForm必须在 SPARQL 语法中,例如字符串需要 "" 围绕它,否则在 SPARQL 中会出现解析错误 。

于 2016-11-26T18:54:55.543 回答
1

@Becher, per @AKSW's question, we need to know how you're trying to resolve dependencies. IntelliJ gives you a few options -- I use SBT, which I think is pretty common, with Ivy (through the IvyIDEA plug-in.) But, you can use Maven directly or just add jars to a library.

This is a pretty helpful page in any case https://mvnrepository.com/artifact/org.apache.jena/jena-arq/3.1.1

于 2017-02-07T19:50:22.267 回答