문제

할 수 없는 방법을 이해할 수 있으며 dbpedia 쿼리를 사용하여 예나.튜토리얼에서 같은 (Listing4)모델은 초기화는 다음과 같다:

// Open the bloggers RDF graph from the filesystem
InputStream in = new FileInputStream(new File("bloggers.rdf"));

// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();

자의 말을 쓰고 싶어하는 쿼리 목록에서 교회공합니다.에 SPARQL 처럼 보이는 것입니다(에서 가져온 이 메일링리스트 메시지):

PREFIX p: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.georss.org/georss/>

SELECT DISTINCT ?m ?n ?p ?d
WHERE {
 ?m rdfs:label ?n.
 ?m skos:subject ?c.
 ?c skos:broader category:Churches_in_Paris.
 ?m p:abstract ?d.
 ?m geo:point ?p
 FILTER ( lang(?n) = "fr" )
 FILTER ( lang(?d) = "fr" )
 }

어떻게 이 쿼리에서 볼 Java?특히,내가 관심있는 방법에서는 모델 개체가 초기화되지 않습니다.

도움이 되었습니까?

해결책

검색 한 후 톤 톤 페이지의 나이 그 해답을 찾았습니다.아마도 내지 않은 질문을 충분히 명확하게,하지만 어쨌든 아래 코드는 나를 위해 일했습니다.

String queryString=
"PREFIX p: <http://dbpedia.org/property/>"+
"PREFIX dbpedia: <http://dbpedia.org/resource/>"+
"PREFIX category: <http://dbpedia.org/resource/Category:>"+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX skos: <http://www.w3.org/2004/02/skos/core#>"+
"PREFIX geo: <http://www.georss.org/georss/>"+

"SELECT DISTINCT ?m ?n ?p ?d"+
"WHERE {"+
" ?m rdfs:label ?n."+
" ?m skos:subject ?c."+
" ?c skos:broader category:Churches_in_Paris."+
" ?m p:abstract ?d."+
" ?m geo:point ?p"+
" FILTER ( lang(?n) = "fr" )"+
" FILTER ( lang(?d) = "fr" )"+
" }"

// now creating query object
Query query = QueryFactory.create(queryString);
// initializing queryExecution factory with remote service.
// **this actually was the main problem I couldn't figure out.**
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

//after it goes standard query execution and result processing which can
// be found in almost any Jena/SPARQL tutorial.
try {
    ResultSet results = qexec.execSelect();
    for (; results.hasNext();) {

    // Result processing is done here.
    }
}
finally {
   qexec.close();
}

이 대답에서 발견 으며 dbpedia-토론의 www.mail-archive.com 페이지.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top