1

我正在尝试改编 DBpedia-SpotLight 上报告的示例之一:

DBpediaSpotlightClient.java(需要AnnotationClient.java

使用此示例,给出描述并查询 Spotlight 服务以检索注释响应:Web 服务

好吧,要运行这个程序,需要为输入文件(带描述)和输出文件(带结果)选择一个路径:你可以在源代码的末尾找到这个。

File input = new File("...");
File output = new File("...");

接下来,它接受的参数在这里报告:

GetMethod getMethod = new GetMethod(API_URL + "rest/annotate/?" +
                "confidence=" + CONFIDENCE
                + "&support=" + SUPPORT
                + "&text=" + URLEncoder.encode(text.text(), "utf-8"));
getMethod.addRequestHeader(new Header("Accept", "application/json"));
spotlightResponse = request(getMethod);

我想它存储传递给监听聚光灯服务的参数。

正如在Web Service中所写的那样,我还将使用其他选项(例如sparql参数)并使用其他查询方法,例如发现或候选("rest/spot/?", "rest/candidates/?"),但我不知道如何继续。

我该如何修改它?是否需要另一个文件?

谢谢!

编辑:

请看一下我正在运行的代码(API_URL 是“ http://spotlight.dbpedia.org/ ”):

        LOG.info("Querying API.");
        String spotlightResponse;
        try {
            GetMethod getMethod = new GetMethod(API_URL + "rest/candidates?" +
                    "confidence=" + CONFIDENCE
                    + "&support=" + SUPPORT
                    + "&text=" + URLEncoder.encode(text.text(), "utf-8"));
            getMethod.addRequestHeader(new Header("Accept", "application/json"));

            spotlightResponse = request(getMethod);
        } catch (UnsupportedEncodingException e) {
            throw new AnnotationException("Could not encode text.", e);
        }

我尝试了您的建议,但对于每个请求,我都会收到这种错误:

INFO 2014-01-28 12:40:41,578 main [DBpediaSpotlightClient] - Querying API.
gen 28, 2014 12:40:54 PM org.apache.commons.httpclient.HttpMethodBase getRespons
eBody
Avvertenza: Going to buffer response body of large or unknown size. Using getRes
ponseBodyAsStream instead is recommended.
ERROR 2014-01-28 12:40:55,089 main [DBpediaSpotlightClient] - org.dbpedia.spotli
ght.exceptions.AnnotationException: Received invalid response from DBpedia Spotl
ight API.
org.dbpedia.spotlight.exceptions.AnnotationException: Received invalid response
from DBpedia Spotlight API.
        at org.dbpedia.spotlight.evaluation.external.DBpediaSpotlightClient.extr
act(DBpediaSpotlightClient.java:74)
        at org.dbpedia.spotlight.evaluation.external.AnnotationClient.saveExtrac
tedEntitiesSet(AnnotationClient.java:138)
        at org.dbpedia.spotlight.evaluation.external.AnnotationClient.evaluateMa
nual(AnnotationClient.java:168)
        at org.dbpedia.spotlight.evaluation.external.AnnotationClient.evaluate(A
nnotationClient.java:164)
        at org.dbpedia.spotlight.evaluation.external.DBpediaSpotlightClient.main
(DBpediaSpotlightClient.java:112)
 INFO 2014-01-28 12:40:55,110 main [DBpediaSpotlightClient] - Extracted entities
 from 5 text items, with 0 successes and 5 errors.
 INFO 2014-01-28 12:40:55,110 main [DBpediaSpotlightClient] - Results saved to:
C:\Users\Alberto\Documents\projects\OmniTourist\apache jena\org\dbpedia\spotligh
t\evaluation\external\output.txt
 INFO 2014-01-28 12:40:55,114 main [DBpediaSpotlightClient] - Average extraction
 time: 0.0 ms

再次感谢你!

4

1 回答 1

0

为了使用其他方法,您应该更改 GetMethod。例如:

// "rest/candidates/?"

GetMethod getMethod = new GetMethod(API_URL + "rest/candidates?" +
                "confidence=" + CONFIDENCE
                + "&support=" + SUPPORT
                + "&text=" + URLEncoder.encode(text.text(), "utf-8"));

等等。

于 2014-01-25T17:27:01.160 回答