33 String dataURL = url.replace(
"/id/",
"/doc/");
35 URL obj =
new URL(dataURL);
36 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
37 con.setRequestMethod(
"GET");
38 BufferedReader in =
new BufferedReader(
new InputStreamReader(con.getInputStream(),
"UTF8"));
40 StringBuilder response =
new StringBuilder();
41 while ((inputLine = in.readLine()) !=
null) {
42 response.append(inputLine);
46 JSONObject jsonOut =
new JSONObject();
47 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
49 JSONObject conceptObject = (JSONObject) jsonObject.get(url);
50 JSONArray prefLabel = (JSONArray) conceptObject.get(
"http://www.w3.org/2000/01/rdf-schema#label");
51 JSONObject prefLabelObj = (JSONObject) prefLabel.get(0);
52 jsonOut.put(
"label", prefLabelObj.get(
"value"));
53 jsonOut.put(
"lang", prefLabelObj.get(
"lang"));
54 JSONArray definition = (JSONArray) conceptObject.get(
"http://www.w3.org/2004/02/skos/core#definition");
55 if (definition !=
null) {
56 JSONObject definitionObj = (JSONObject) definition.get(0);
57 jsonOut.put(
"description", definitionObj.get(
"value"));
59 JSONArray scheme = (JSONArray) conceptObject.get(
"http://www.w3.org/2004/02/skos/core#inScheme");
61 JSONObject schemeObj = (JSONObject) scheme.get(0);
62 String schemeValue = (String) schemeObj.get(
"value");
63 String[] schemeSplit = schemeValue.split(
"/");
64 jsonOut.put(
"scheme", schemeSplit[schemeSplit.length - 1]);
66 jsonOut.put(
"scheme",
"BGS Linked Data");
68 jsonOut.put(
"uri", url);
73 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
74 if (item.getType().equals(type)) {
75 quality = item.getQuality();
76 group = item.getGroup();
79 jsonOut.put(
"type", type);
80 jsonOut.put(
"quality", quality);
81 jsonOut.put(
"group", group);
83 jsonOut.put(
"broaderTerms",
new JSONArray());
84 jsonOut.put(
"narrowerTerms",
new JSONArray());
85 if (jsonOut.get(
"label") !=
null && !jsonOut.get(
"label").equals(
"")) {
88 throw new RetcatException(
"no label for this uri available");
91 return new JSONObject();