喜的朋友很抱歉我要問的問題是類似我以前question.I已經在SPARQL網絡服務[http://drugbank.bio2rdf.org/sparql]運行代碼,返回的結果是如下:SPARQL查詢沒有在Java中檢索結果
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX drugbank: <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT distinct ?resource WHERE { ?resource dcterms:identifier "drugbank:DB01051"^^xsd:string}
但是,我試圖在java中得到結果,並且它不返回具有相同查詢的結果。 Java代碼如下:
import java.io.IOException;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.ResultSetFactory;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.query.ResultSetRewindable;
public class DrugbankResourceProperty {
public static void main(String[] args) throws IOException {
ParameterizedSparqlString pss = new ParameterizedSparqlString(""
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "PREFIX dcterms: <http://purl.org/dc/terms/>\n"
+ "PREFIX drugbank: <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/>"
+ "\n"
+ "SELECT distinct ?resource WHERE { ?resource dcterms:identifier \"drugbank:DB01051\"^^xsd:string}");
QueryExecution exec = QueryExecutionFactory.sparqlService("http://drugbank.bio2rdf.org/sparql", pss.asQuery());
ResultSetRewindable results = ResultSetFactory.makeRewindable(exec.execSelect());
while (results.hasNext()) {
System.out.println(ResultSetFormatter.asText(results));
}
}
}
我補充說:「XSD」和第一次運行之後,「drugbank」前綴,並認爲它不會因爲這些失蹤的前綴返回。然而,它並沒有繼續工作,我真的不知道它爲什麼不返回結果。如果可能,你能告訴我我在哪裏犯了一個錯誤嗎?非常感謝您的幫助!
'JenaRuntime.isRdf11 = FALSE ;'會改變舊的行爲 – RobV
是的,我明白了。感謝@AKSW提供了很好的解釋。我記得你也幫我解決了我以前的問題。並感謝RobV幫助配置選項。 –