labelingsystem-server  Version 0.1.0.0
Retcat_BGSLinkedData Class Reference

Static Public Member Functions

static Map< String, SuggestionItem > query (String searchword)
 
static JSONObject info (String url) throws MalformedURLException, IOException, ParseException, ParseException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, RetcatException
 

Member Function Documentation

◆ info()

static JSONObject info ( String  url) throws MalformedURLException, IOException, ParseException, ParseException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, RetcatException
static
31  {
32  try {
33  String dataURL = url.replace("/id/", "/doc/");
34  dataURL += ".JSON";
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"));
39  String inputLine;
40  StringBuilder response = new StringBuilder();
41  while ((inputLine = in.readLine()) != null) {
42  response.append(inputLine);
43  }
44  in.close();
45  // parse json
46  JSONObject jsonOut = new JSONObject();
47  JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
48  // output
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"));
58  }
59  JSONArray scheme = (JSONArray) conceptObject.get("http://www.w3.org/2004/02/skos/core#inScheme");
60  if (scheme != null) {
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]);
65  } else {
66  jsonOut.put("scheme", "BGS Linked Data");
67  }
68  jsonOut.put("uri", url);
69  // get retcat info
70  String type = "bgs";
71  String quality = "";
72  String group = "";
73  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
74  if (item.getType().equals(type)) {
75  quality = item.getQuality();
76  group = item.getGroup();
77  }
78  }
79  jsonOut.put("type", type);
80  jsonOut.put("quality", quality);
81  jsonOut.put("group", group);
82  // broader and narrower (not yet available)
83  jsonOut.put("broaderTerms", new JSONArray());
84  jsonOut.put("narrowerTerms", new JSONArray());
85  if (jsonOut.get("label") != null && !jsonOut.get("label").equals("")) {
86  return jsonOut;
87  } else {
88  throw new RetcatException("no label for this uri available");
89  }
90  } catch (Exception e) {
91  return new JSONObject();
92  }
93  }

References LocalRetcatItems.getLocalCatalogue().

Referenced by RetcatResource.getInfoBGS(), and RetcatResource.getQueryResultsBGS().

◆ query()

static Map<String, SuggestionItem> query ( String  searchword)
static
26  {
27  // no query API available, return empty object, use info with uri prefix
28  return new HashMap<>();
29  }

Referenced by RetcatResource.getQueryResultsBGS().

Exception