Java - 耶拿 QueryParseException

Java - Jena QueryParseException

我是 Jena 和 SPARQL 的新手。我正在尝试使用以下请求和代码在 Eclipse 中 运行 Jena。我收到 QueryParseException,我知道其他人对未定义的 rdfs 前缀有同样的问题,但这里不同。

异常:

Exception in thread "main" org.apache.jena.query.QueryParseException: Line 1, column 134: Unresolved prefixed name: http:

查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?subject ?fsn
WHERE {
  ?subject rdfs:label ?fsn.
  ?subject rdfs:subClassOf+ http://snomed.info/id/410607006
}

代码:

import java.util.HashMap;
import org.apache.jena.query.*;

public class SnomedQuery {
  private String serviceURI;
  private String query;

  //Constructor with SPARQL endpoint and query
  public SnomedQuery(String URI, String serviceURI){
    this.serviceURI = serviceURI;
    this.query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
              " SELECT ?subject ?fsn WHERE {?subject rdfs:label ?fsn. ?subject rdfs:subClassOf+ "+URI+"}";
  }

  //return SPARQL endpoint
  public String getServiceURI() {
    return this.serviceURI;
  }

  //return query
  public String getQuery() {
    return this.query;
  }

  /*
  * purpose: This function is used to retrieve all child of a concept and the concept itself
  * @param
  * @return
  *   Hashmap with URI as key and corresponding term as value
  */
  public HashMap<String, String> getFSNChildPlus(){
    HashMap<String, String> output = new HashMap<String, String>();

    QueryExecution q = QueryExecutionFactory.sparqlService(getServiceURI(), getQuery());
    ResultSet results = q.execSelect();

    while (results.hasNext()) {
        QuerySolution answer = results.nextSolution();
        String subject = answer.get("subject").toString();
        String fsn = answer.get("fsn").toString();

        output.put(subject, fsn);
    }
    return null;
  }
}

感谢您的帮助

在 SPARQL 中,需要标记 URI。

所以 http://snomed.info/id/410607006 是错误的,但是 <http://snomed.info/id/410607006> 是可以的。

这是您的查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?subject ?fsn
WHERE {
  ?subject rdfs:label ?fsn.
  ?subject rdfs:subClassOf+ <http://snomed.info/id/410607006>
}