我正在尝试改编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);我认为它存储传递给listen spotlight服务的参数。
正如在Web Service中所写的,我还会使用其他选项(例如sparql参数),并使用其他查询方法,如spotting或candidates ("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再次感谢您!
发布于 2014-01-26 01:27:01
为了使用其他方法,您应该更改GetMethod。例如:
// "rest/candidates/?"
GetMethod getMethod = new GetMethod(API_URL + "rest/candidates?" +
"confidence=" + CONFIDENCE
+ "&support=" + SUPPORT
+ "&text=" + URLEncoder.encode(text.text(), "utf-8"));等。
https://stackoverflow.com/questions/21311993
复制相似问题