labelingsystem-server  Version 0.1.0.0
Retcat_Pleiades 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
75  {
76  try {
77  String outputUrl = url;
78  url = GeneralFunctions.encodeURIComponent(url);
79  url = "http://peripleo.pelagios.org/peripleo/places/" + url;
80  // query for json
81  URL obj = new URL(url);
82  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
83  con.setRequestMethod("GET");
84  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
85  String inputLine;
86  StringBuilder response = new StringBuilder();
87  while ((inputLine = in.readLine()) != null) {
88  response.append(inputLine);
89  }
90  in.close();
91  // parse json
92  JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
93  String title = (String) jsonObject.get("title");
94  String description = (String) jsonObject.get("description");
95  // output
96  JSONObject jsonOut = new JSONObject();
97  jsonOut.put("label", title);
98  jsonOut.put("lang", "");
99  // get retcat info
100  String type = "pleiades";
101  String quality = "";
102  String group = "";
103  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
104  if (item.getType().equals(type)) {
105  quality = item.getQuality();
106  group = item.getGroup();
107  }
108  }
109  jsonOut.put("type", type);
110  jsonOut.put("quality", quality);
111  jsonOut.put("group", group);
112  jsonOut.put("uri", outputUrl);
113  jsonOut.put("scheme", "Pleides Places");
114  JSONArray broader = new JSONArray();
115  JSONArray narrower = new JSONArray();
116  jsonOut.put("broaderTerms", broader);
117  jsonOut.put("narrowerTerms", narrower);
118  jsonOut.put("description", description);
119  if (jsonOut.get("label") != null && !jsonOut.get("label").equals("")) {
120  return jsonOut;
121  } else {
122  throw new RetcatException("no label for this uri available");
123  }
124  } catch (Exception e) {
125  return new JSONObject();
126  }
127  }

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

Referenced by RetcatResource.getInfoPelagios(), and RetcatResource.getQueryResultsPELAGIOS().

◆ 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://peripleo.pelagios.org/peripleo/search?query=" + searchword + "&types=place&limit=" + RetcatResource.getLimit();
30  URL url = new URL(url_string);
31  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
32  //conn.setRequestProperty("Accept", "application/json");
33  BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
34  String inputLine;
35  StringBuilder response = new StringBuilder();
36  while ((inputLine = br.readLine()) != null) {
37  response.append(inputLine);
38  }
39  br.close();
40  // fill objects
41  JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
42  JSONArray resultsArray = (JSONArray) jsonObject.get("items");
43  Map<String, SuggestionItem> autosuggests = new HashMap<String, SuggestionItem>();
44  for (Object element : resultsArray) {
45  JSONObject tmpElement = (JSONObject) element;
46  String uriValue = (String) tmpElement.get("identifier");
47  if (uriValue.contains("pleiades.stoa.org")) {
48  autosuggests.put(uriValue, new SuggestionItem(uriValue));
49  SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
50  String labelValue = (String) tmpElement.get("title");
51  tmpAutosuggest.setLabel(labelValue);
52  String descriptionValue = (String) tmpElement.get("description");
53  if (descriptionValue != null) {
54  tmpAutosuggest.setDescription(descriptionValue);
55  }
56  tmpAutosuggest.setSchemeTitle("Pleides Places");
57  // get retcat info
58  String type = "pleiades";
59  String quality = "";
60  String group = "";
61  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
62  if (item.getType().equals(type)) {
63  quality = item.getQuality();
64  group = item.getGroup();
65  }
66  }
67  tmpAutosuggest.setType(type);
68  tmpAutosuggest.setQuality(quality);
69  tmpAutosuggest.setGroup(group);
70  }
71  }
72  return autosuggests;
73  }

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

Referenced by RetcatResource.getQueryResultsPELAGIOS().

Exception