labelingsystem-server  Version 0.1.0.0
Retcat_ChronOntology Class Reference

Static Public Member Functions

static Map< String, SuggestionItem > query (String searchword) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, link.labeling.retcat.exceptions.ResourceNotAvailableException
 
static JSONObject info (String url) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, RetcatException
 

Member Function Documentation

◆ info()

static JSONObject info ( String  url) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, RetcatException
static
87  {
88  try {
89  String outputUrl = url;
90  url = url.replace("/period", "/data/period");
91  // query for json
92  URL obj = new URL(url);
93  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
94  con.setRequestMethod("GET");
95  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
96  String inputLine;
97  StringBuilder response = new StringBuilder();
98  while ((inputLine = in.readLine()) != null) {
99  response.append(inputLine);
100  }
101  in.close();
102  // parse json
103  JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
104  JSONObject resourceObject = (JSONObject) jsonObject.get("resource");
105  JSONArray names = (JSONArray) resourceObject.get("names");
106  String labelValue = null;
107  String labelLang = null;
108  for (Object item : names) {
109  JSONObject tmp = (JSONObject) item;
110  if (tmp.get("lang").equals("en")) {
111  labelLang = (String) tmp.get("lang");
112  JSONArray content = (JSONArray) tmp.get("content");
113  labelValue = (String) content.get(0);
114  }
115  }
116  String descValue = "";
117  if (resourceObject.get("description") != null) {
118  descValue = resourceObject.get("description").toString();
119  }
120  // output
121  JSONObject jsonOut = new JSONObject();
122  jsonOut.put("label", labelValue);
123  jsonOut.put("lang", labelLang);
124  // get retcat info
125  String type = "chronontology";
126  String quality = "";
127  String group = "";
128  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
129  if (item.getType().equals(type)) {
130  quality = item.getQuality();
131  group = item.getGroup();
132  }
133  }
134  jsonOut.put("type", type);
135  jsonOut.put("quality", quality);
136  jsonOut.put("group", group);
137  jsonOut.put("description", descValue);
138  jsonOut.put("uri", outputUrl);
139  jsonOut.put("scheme", "ChronOntology");
140  jsonOut.put("broaderTerms", new JSONArray());
141  jsonOut.put("narrowerTerms", new JSONArray());
142  if (jsonOut.get("label") != null && !jsonOut.get("label").equals("")) {
143  return jsonOut;
144  } else {
145  throw new RetcatException("no label for this uri available");
146  }
147  } catch (Exception e) {
148  return new JSONObject();
149  }
150  }

References LocalRetcatItems.getLocalCatalogue().

Referenced by RetcatResource.getInfoChronontology(), and RetcatResource.getQueryResultsCHRONONTOLOGY().

◆ query()

static Map<String, SuggestionItem> query ( String  searchword) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, link.labeling.retcat.exceptions.ResourceNotAvailableException
static
27  {
28  searchword = GeneralFunctions.encodeURIComponent(searchword);
29  String url_string = "http://chronontology.dainst.org/data/period?q=" + searchword + "&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"));
33  String inputLine;
34  StringBuilder response = new StringBuilder();
35  while ((inputLine = br.readLine()) != null) {
36  response.append(inputLine);
37  }
38  br.close();
39  // init output
40  JSONArray outArray = new JSONArray();
41  // fill objects
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  JSONObject resourceObject = (JSONObject) tmpElement.get("resource");
48  String uriValue = (String) tmpElement.get("@id");
49  uriValue = "http://chronontology.dainst.org" + uriValue;
50  autosuggests.put(uriValue, new SuggestionItem(uriValue));
51  SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
52  JSONArray names = (JSONArray) resourceObject.get("names");
53  String labelValue = null;
54  String labelLang = null;
55  for (Object item : names) {
56  JSONObject tmp = (JSONObject) item;
57  if (tmp.get("lang").equals("en")) {
58  labelLang = (String) tmp.get("lang");
59  JSONArray content = (JSONArray) tmp.get("content");
60  labelValue = (String) content.get(0);
61  }
62  }
63  tmpAutosuggest.setLabel(labelValue);
64  tmpAutosuggest.setLanguage(labelLang);
65  String descriptionValue = (String) resourceObject.get("description");
66  if (descriptionValue != null) {
67  tmpAutosuggest.setDescription(descriptionValue);
68  }
69  tmpAutosuggest.setSchemeTitle("ChronOntology");
70  // get retcat info
71  String type = "chronontology";
72  String quality = "";
73  String group = "";
74  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
75  if (item.getType().equals(type)) {
76  quality = item.getQuality();
77  group = item.getGroup();
78  }
79  }
80  tmpAutosuggest.setType(type);
81  tmpAutosuggest.setQuality(quality);
82  tmpAutosuggest.setGroup(group);
83  }
84  return autosuggests;
85  }

References GeneralFunctions.encodeURIComponent(), RetcatResource.getLimit(), and LocalRetcatItems.getLocalCatalogue().

Referenced by RetcatResource.getQueryResultsCHRONONTOLOGY().

Exception