1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
public static String lookupURI_DBpedia(String title){
String uri="";
Parser parser = null;
NodeList root;
URL url;
File file;
Document document;
Element racine;
SAXBuilder sxb;
PrintWriter outc;
int inputLine;
String text="";
BufferedReader br;
String str = title.replace(" ", "%20");
try{
url = new URL("http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString="+str.replace("(", "").replace(")", "")+"&MaxHits=500");
InputStream in = url.openStream();
// while ((inputLine = in.read()) != -1){
// System.out.print((char)inputLine);
// }
sxb = new SAXBuilder();
sxb.setValidation(false);
document = sxb.build(in);
racine = document.getRootElement();
List children = racine.getChildren();
if(children.size()!=0){
for(Object child:children){
Element el = (Element)child;
Element elm = (Element)el.getChildren().get(1);
uri = elm.getTextTrim();
if(uri.substring(uri.lastIndexOf("/")+1).toLowerCase().equals(title.replace(" ", "_").replace("(", "%28").replace(")", "%29"))){
break;
}
}
}
System.out.println("text : " + uri);
}catch(Exception e){
e.printStackTrace();
}
return uri;
} |
Partager