28 searchword = GeneralFunctions.encodeURIComponent(searchword);
29 String url_string =
"http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + searchword +
"&MaxHits=" + RetcatResource.getLimit();
30 URL url =
new URL(url_string);
31 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
32 conn.setRequestProperty(
"Accept",
"application/json");
33 BufferedReader br =
new BufferedReader(
new InputStreamReader(conn.getInputStream(),
"UTF-8"));
35 StringBuilder response =
new StringBuilder();
36 while ((inputLine = br.readLine()) !=
null) {
37 response.append(inputLine);
41 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
42 JSONArray resultsArray = (JSONArray) jsonObject.get(
"results");
43 Map<String, SuggestionItem> autosuggests =
new HashMap<String, SuggestionItem>();
44 for (Object element : resultsArray) {
45 JSONObject tmpElement = (JSONObject) element;
46 String uriValue = (String) tmpElement.get(
"uri");
47 autosuggests.put(uriValue,
new SuggestionItem(uriValue));
48 SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
49 String labelValue = (String) tmpElement.get(
"label");
50 tmpAutosuggest.setLabel(labelValue);
51 String descriptionValue = (String) tmpElement.get(
"description");
52 if (descriptionValue !=
null) {
53 tmpAutosuggest.setDescription(descriptionValue);
55 tmpAutosuggest.setSchemeTitle(
"DBpedia");
57 String type =
"dbpedia";
60 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
61 if (item.getType().equals(type)) {
62 quality = item.getQuality();
63 group = item.getGroup();
66 tmpAutosuggest.setType(type);
67 tmpAutosuggest.setQuality(quality);
68 tmpAutosuggest.setGroup(group);