使用 RDF4J 返回错误查询 FactForge Sparql 端点

Querying FactForge Sparql Endpoint with RDF4J returning error

我正在尝试使用 RDF4J 查询 Factforge Sparql 端点,但收到错误消息。

我使用 RDF4J V: 2.3.2 和 Maven。

我在 Java 上设置代理设置:

    System.setProperty("https.proxyHost", PROXY_HOST);
    System.setProperty("https.proxyPort", PROXY_PORT);
    System.setProperty("http.proxyHost", PROXY_HOST);
    System.setProperty("http.proxyPort", PROXY_PORT);

这是我的代码:

SPARQLRepository repo = new SPARQLRepository("http://factforge.net/sparql");
repo.initialize();
try (RepositoryConnection conn = repo.getConnection()) {
            String queryStringA = "SELECT ?s ?p WHERE { ?s ?p ?o } ";

            TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryStringA);
            try (TupleQueryResult result = query.evaluate()) {
                while (result.hasNext()) { // iterate over the result
                    BindingSet bindingSet = result.next();
                    Value valueOfX = bindingSet.getValue("s");
                    Value valueOfY = bindingSet.getValue("p");
                    System.out.println(valueOfX);
                    System.out.println(valueOfY);
                }
            }
}

我收到以下错误:

Exception in thread "main" org.eclipse.rdf4j.query.QueryEvaluationException: Failed to get server protocol; no such resource on this server: http://factforge.net/sparql?query=SELECT+%3Fs+%3Fp+WHERE+%7B+%3Fs+%3Fp+%3Fo+%7D+

非常感谢您的帮助。谢谢。

您使用了错误的端点 URL。根据 Factforge overview,Factforge 的 SPARQL 端点位于 http://factforge.net/repositories/ff-news

除此之外,请注意您正在执行的查询是 "give me ALL your triples"。 Factforge 有很多三元组,所以这个结果会很大,执行它会消耗 Factforge 服务器上的大量资源。您的查询可能会超时,或者 Factforge 可能会拒绝执行它。

如果您的目的只是为了测试 SPARQL 查询是否有效,最好在其中放置类似 LIMIT 约束的内容:

 String queryStringA = "SELECT ?s ?p WHERE { ?s ?p ?o } LIMIT 10";