그래서 간단한 쿼리를 수행합니다. 내가 원하는 모든 uri/property/특정 dbpedia uri의 개체, 예 : http://dbpedia.org/resource/Roger_Federer. 문제는 결과 집합에서 볼 수 있듯이 단지 속성 만 반환한다는 것입니다.Sparql 쿼리가 uri/object를 반환하지 않습니다.
등급 :
public class SemanticCrawlerImpl implements SemanticCrawler {
public void search(Model graph, String resourceURI) {
graph.read(resourceURI);
// Create a new query
String queryString =
"SELECT ?url ?property ?object" +
"WHERE {" +
" <"+resourceURI+"> ?property ?object ." +
"}";
Query query = QueryFactory.create(queryString);
System.out.println("----------------------");
System.out.println("Query Result Sheet");
System.out.println("----------------------");
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, graph);
com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
}
결과 집합
| url | property | objectWHERE |
=================================================================================
| | <http://dbpedia.org/property/medaltemplatesTitle> | |
| | <http://dbpedia.org/ontology/thumbnail> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://dbpedia.org/property/name> | |
| | <http://dbpedia.org/property/daviscupresult> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://dbpedia.org/property/hopmancupresult> | |
| | <http://dbpedia.org/ontology/wikiPageExternalLink> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://dbpedia.org/ontology/height> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://dbpedia.org/ontology/birthYear> | |
문자열 연결 '? object "+"WHERE'는'select? objectWHERE'를 주며'? objectWHERE' 변수를 사용하지 않습니다. 질의의'where'는 선택 사항입니다 (즉,'? a? b {...}'라고 쓰면 문제를 피할 수 있습니다.)하지만 어쨌든 질의 문자열에 줄 바꾸기를 사용해야합니다. 행 번호에 대한 더 나은 구문 오류 메시지 또한'< "+ resourceURI +">와 같은 문자열 연결은 오류가 발생하기 쉽기 때문에 ParameterizedSparqlString을 대신 사용해야합니다 .. –