【问题标题】:Querying FactForge Sparql Endpoint with RDF4J returning error使用 RDF4J 返回错误查询 FactForge Sparql 端点
【发布时间】:2018-08-27 13:54:41
【问题描述】:

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

我在 Maven 中使用 RDF4J V: 2.3.2。

我在 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);
                }
            }
}

我收到以下错误:

线程“主”org.eclipse.rdf4j.query.QueryEvaluationException 中的异常:获取服务器协议失败;此服务器上没有此类资源:http://factforge.net/sparql?query=SELECT+%3Fs+%3Fp+WHERE+%7B+%3Fs+%3Fp+%3Fo+%7D+

我将不胜感激。谢谢。

【问题讨论】:

    标签: http graphdb rdf4j


    【解决方案1】:

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

    除此之外,请注意您正在执行的查询是“给我所有你的三元组”。 Factforge 有很多三元组,所以这样做的结果将是巨大的,执行它会消耗 Factforge 服务器上的大量资源。您的查询可能会超时,或者 Factforge 可能会拒绝执行它。

    如果您的目标只是测试 SPARQL 查询是否有效,最好在其中放置 LIMIT 约束:

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

    【讨论】:

    • 非常感谢您对我的查询的回答和更新。它就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多