Hi!
Using the code below, I can get spotlight results as a list of
DBpediaResource. Using the method getFullUri() from the class DBpedia
Resource, I can get the uri of the results. I'd like to get a description
to each result, is it possible in Spotlight?
*The code is below:*
/**
* Simple web service-based annotation client for DBpedia Spotlight.
*
* @author pablomendes, Joachim Daiber
*/
public class EnglishDBpediaSpotlightClient extends AnnotationClient {
private final static String API_URL = "http://spotlight.dbpedia.org/";
//in english
private static final double CONFIDENCE = 0.0;
private static final int SUPPORT = 0;
@Override
public List<DBpediaResource> extract(Text text) throws
AnnotationException {
LOG.info("Querying API.");
String spotlightResponse;
try {
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);
} catch (UnsupportedEncodingException e) {
throw new AnnotationException("Could not encode text.", e);
}
assert spotlightResponse != null;
JSONObject resultJSON = null;
JSONArray entities = null;
try {
resultJSON = new JSONObject(spotlightResponse);
entities = resultJSON.getJSONArray("Resources");
} catch (JSONException e) {
throw new AnnotationException("Received invalid response from
DBpedia Spotlight API.");
}
LinkedList<DBpediaResource> resources = new
LinkedList<DBpediaResource>();
for(int i = 0; i < entities.length(); i++) {
try {
JSONObject entity = entities.getJSONObject(i);
resources.add(
new DBpediaResource(entity.getString("@URI"),
Integer.parseInt(entity.getString("@support"))));
} catch (JSONException e) {
LOG.error("JSON exception "+e);
}
}
return resources;
}
public static void main(String[] args) throws Exception {
EnglishDBpediaSpotlightClient c = new
EnglishDBpediaSpotlightClient();
Text text = new Text("Google Inc. is an American multinational
public corporation " +
"invested in Internet search, cloud computing, and
advertising " +
"technologies. Google hosts and develops a number of
Internet-based " +
"services and products, and generates profit primarily
from advertising " +
"through its AdWords program.");
System.out.println(text.toString());
List<DBpediaResource> response = c.extract(text);
PrintWriter out = new
PrintWriter("AnnotationText-Spotlight.txt.set");
for( DBpediaResource dbResource : response ) {
* System.out.println( dbResource.getFullUri())*;
*//here, I can get the Uri for each result.
*
}
}
}
*Thank you!!!
*
*Luciane.
*
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Dbp-spotlight-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dbp-spotlight-users