28 searchword = GeneralFunctions.encodeURIComponent(searchword);
29 String url_string =
"http://vocabularies.unesco.org/browser/rest/v1/search?query=*" + searchword +
"*&lang=en&type=skos:Concept&fields=narrower%20broader&vocab=thesaurus&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 JSONArray outArray =
new JSONArray();
42 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
43 JSONArray resultsArray = (JSONArray) jsonObject.get(
"results");
44 Map<String, SuggestionItem> autosuggests =
new HashMap<String, SuggestionItem>();
45 for (Object element : resultsArray) {
46 JSONObject tmpElement = (JSONObject) element;
47 String uriValue = (String) tmpElement.get(
"uri");
48 autosuggests.put(uriValue,
new SuggestionItem(uriValue));
49 SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
50 String labelValue = (String) tmpElement.get(
"prefLabel");
51 tmpAutosuggest.setLabel(labelValue);
52 JSONArray desArray = (JSONArray) tmpElement.get(
"skos:scopeNote");
53 if (desArray !=
null) {
54 for (Object e : desArray) {
55 String descStr = e.toString();
56 tmpAutosuggest.setDescription(descStr);
59 String vocabValue = (String) tmpElement.get(
"vocab");
60 tmpAutosuggest.setSchemeTitle(
"unesco");
61 JSONArray boraderArray = (JSONArray) tmpElement.get(
"broader");
62 JSONArray narrowerArray = (JSONArray) tmpElement.get(
"narrower");
63 tmpAutosuggest.setLanguage(
"en");
65 if (boraderArray !=
null) {
66 for (Object item : boraderArray) {
67 JSONObject tmpObject = (JSONObject) item;
68 HashMap<String, String> hstmp =
new HashMap();
69 String uriValueTmp = (String) tmpObject.get(
"uri");
71 String broaderUrl = GeneralFunctions.encodeURIComponent(uriValueTmp);
72 broaderUrl =
"http://vocabularies.unesco.org/browser/rest/v1/thesaurus/label?lang=en&uri=" + broaderUrl;
73 URL obj =
new URL(broaderUrl);
74 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
75 con.setRequestMethod(
"GET");
76 BufferedReader broaderIn =
new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF8"));
77 String broaderInputLine;
78 StringBuilder broaderResponse =
new StringBuilder();
79 while ((broaderInputLine = broaderIn.readLine()) !=
null) {
80 broaderResponse.append(broaderInputLine);
84 JSONObject broaderJsonObject = (JSONObject)
new JSONParser().parse(broaderResponse.toString());
85 String broaderLabelValue = (String) broaderJsonObject.get(
"prefLabel");
86 hstmp.put(uriValueTmp, broaderLabelValue);
87 tmpAutosuggest.setBroaderTerm(hstmp);
91 if (narrowerArray !=
null) {
92 for (Object item : boraderArray) {
93 JSONObject tmpObject = (JSONObject) item;
94 HashMap<String, String> hstmp =
new HashMap();
95 String uriValueTmp = (String) tmpObject.get(
"uri");
97 String narrowerUrl = GeneralFunctions.encodeURIComponent(uriValueTmp);
98 narrowerUrl =
"http://vocabularies.unesco.org/browser/rest/v1/thesaurus/label?lang=en&uri=" + narrowerUrl;
99 URL obj =
new URL(narrowerUrl);
100 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
101 con.setRequestMethod(
"GET");
102 BufferedReader narrowerIn =
new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF8"));
103 String narrowerInputLine;
104 StringBuilder narrowerResponse =
new StringBuilder();
105 while ((narrowerInputLine = narrowerIn.readLine()) !=
null) {
106 narrowerResponse.append(narrowerInputLine);
110 JSONObject broaderJsonObject = (JSONObject)
new JSONParser().parse(narrowerResponse.toString());
111 String narrowerLabelValue = (String) broaderJsonObject.get(
"prefLabel");
112 hstmp.put(uriValueTmp, narrowerLabelValue);
113 tmpAutosuggest.setNarrowerTerm(hstmp);
117 String type =
"unesco";
120 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
121 if (item.getType().equals(type)) {
122 quality = item.getQuality();
123 group = item.getGroup();
126 tmpAutosuggest.setType(type);
127 tmpAutosuggest.setQuality(quality);
128 tmpAutosuggest.setGroup(group);