【发布时间】:2014-02-14 05:26:12
【问题描述】:
我正在尝试改编 DBpedia-SpotLight 上报告的示例之一:
DBpediaSpotlightClient.java(必填AnnotationClient.java)
使用此示例,给出描述并查询 Spotlight 服务以检索注释响应:Web Service
好吧,要运行这个程序,需要为输入文件(带描述)和输出文件(带结果)选择一个路径:你可以在源代码的末尾找到这个。
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
再次感谢您!
【问题讨论】:
标签: java semantics jena semantic-web spotlight-dbpedia