28 searchword = GeneralFunctions.encodeURIComponent(searchword);
29 String url_string =
"http://oek1.fao.org/skosmos/rest/v1/search?query=*" + searchword +
"*&lang=en&type=skos:Concept&fields=narrower%20broader&limit=" + RetcatResource.getLimit();
30 URL url =
new URL(url_string);
31 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
32 BufferedReader br =
new BufferedReader(
new InputStreamReader(conn.getInputStream(),
"UTF-8"));
34 StringBuilder response =
new StringBuilder();
35 while ((inputLine = br.readLine()) !=
null) {
36 response.append(inputLine);
40 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
41 JSONArray resultsArray = (JSONArray) jsonObject.get(
"results");
42 Map<String, SuggestionItem> autosuggests =
new HashMap<String, SuggestionItem>();
43 for (Object element : resultsArray) {
44 JSONObject tmpElement = (JSONObject) element;
45 String uriValue = (String) tmpElement.get(
"uri");
46 autosuggests.put(uriValue,
new SuggestionItem(uriValue));
47 SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
48 String labelValue = (String) tmpElement.get(
"prefLabel");
49 tmpAutosuggest.setLabel(labelValue);
50 String vocabValue = (String) tmpElement.get(
"vocab");
51 tmpAutosuggest.setSchemeTitle(vocabValue);
52 JSONArray boraderArray = (JSONArray) tmpElement.get(
"broader");
53 JSONArray narrowerArray = (JSONArray) tmpElement.get(
"narrower");
54 tmpAutosuggest.setLanguage(
"en");
56 if (boraderArray !=
null) {
57 for (Object item : boraderArray) {
58 JSONObject tmpObject = (JSONObject) item;
59 HashMap<String, String> hstmp =
new HashMap();
60 String uriValueTmp = (String) tmpObject.get(
"uri");
62 String broaderUrl = GeneralFunctions.encodeURIComponent(uriValueTmp);
63 broaderUrl =
"http://oek1.fao.org/skosmos/rest/v1/agrovoc/label?lang=en&uri=" + broaderUrl;
64 URL obj =
new URL(broaderUrl);
65 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
66 con.setRequestMethod(
"GET");
67 BufferedReader broaderIn =
new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF8"));
68 String broaderInputLine;
69 StringBuilder broaderResponse =
new StringBuilder();
70 while ((broaderInputLine = broaderIn.readLine()) !=
null) {
71 broaderResponse.append(broaderInputLine);
75 JSONObject broaderJsonObject = (JSONObject)
new JSONParser().parse(broaderResponse.toString());
76 String broaderLabelValue = (String) broaderJsonObject.get(
"prefLabel");
77 hstmp.put(uriValueTmp, broaderLabelValue);
78 tmpAutosuggest.setBroaderTerm(hstmp);
82 if (narrowerArray !=
null) {
83 for (Object item : boraderArray) {
84 JSONObject tmpObject = (JSONObject) item;
85 HashMap<String, String> hstmp =
new HashMap();
86 String uriValueTmp = (String) tmpObject.get(
"uri");
88 String narrowerUrl = GeneralFunctions.encodeURIComponent(uriValueTmp);
89 narrowerUrl =
"http://oek1.fao.org/skosmos/rest/v1/agrovoc/label?lang=en&uri=" + narrowerUrl;
90 URL obj =
new URL(narrowerUrl);
91 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
92 con.setRequestMethod(
"GET");
93 BufferedReader narrowerIn =
new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF8"));
94 String narrowerInputLine;
95 StringBuilder narrowerResponse =
new StringBuilder();
96 while ((narrowerInputLine = narrowerIn.readLine()) !=
null) {
97 narrowerResponse.append(narrowerInputLine);
101 JSONObject broaderJsonObject = (JSONObject)
new JSONParser().parse(narrowerResponse.toString());
102 String narrowerLabelValue = (String) broaderJsonObject.get(
"prefLabel");
103 hstmp.put(uriValueTmp, narrowerLabelValue);
104 tmpAutosuggest.setNarrowerTerm(hstmp);
111 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
112 if (item.getType().equals(type)) {
113 quality = item.getQuality();
114 group = item.getGroup();
117 tmpAutosuggest.setType(type);
118 tmpAutosuggest.setQuality(quality);
119 tmpAutosuggest.setGroup(group);