labelingsystem-server  Version 0.1.0.0
AutocompleteResource Class Reference

Public Member Functions

Response getSuggestionsForLabels (@QueryParam("query") String requestquery)
 
Response getSuggestionsForLabelsFilter (@QueryParam("query") String requestquery, @PathParam("filter") String filter, @PathParam("value") String value)
 
Response getSuggestionsForAgents (@QueryParam("query") String requestquery)
 
Response getSuggestionsForVocabs (@QueryParam("query") String requestquery)
 

Member Function Documentation

◆ getSuggestionsForAgents()

Response getSuggestionsForAgents ( @QueryParam("query") String  requestquery)
132  {
133  try {
134  String substing = requestquery.toLowerCase();
135  substing = URLDecoder.decode(substing, "UTF-8");
136  int suggestions = 10;
137  int minLength = 1;
138  if (substing.length() <= minLength) {
139  throw new AutocompleteLengthException();
140  } else {
141  RDF rdf = new RDF();
142  String query = rdf.getPREFIXSPARQL();
143  query += "SELECT * WHERE { "
144  + "?s a ls:Agent . "
145  + "?s dc:identifier ?acquery . "
146  + "FILTER(regex(?acquery, '" + substing + "', 'i'))";
147  query += "} "
148  + "ORDER BY ASC(?acquery) "
149  + "LIMIT " + suggestions;
150  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
151  List<String> suggestion_uri = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "s");
152  List<String> suggestion_string = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "acquery");
153  JSONObject jsonobj_query = new JSONObject();
154  JSONArray jsonarray_suggestions = new JSONArray();
155  for (int i = 0; i < suggestion_uri.size(); i++) {
156  JSONObject jsonobj_suggestion = new JSONObject();
157  String[] sugstr = suggestion_string.get(i).split("@");
158  if (sugstr.length > 1) {
159  jsonobj_suggestion.put("value", sugstr[0].replace("\"", ""));
160  jsonobj_suggestion.put("lang", sugstr[1].replace("\"", ""));
161  } else {
162  jsonobj_suggestion.put("value", suggestion_string.get(i));
163  }
164  jsonobj_suggestion.put("data", suggestion_uri.get(i));
165  jsonarray_suggestions.add(jsonobj_suggestion);
166  }
167  jsonobj_query.put("suggestions", jsonarray_suggestions);
168  jsonobj_query.put("query", substing);
169  return Response.ok(jsonobj_query).header("Content-Type", "application/json;charset=UTF-8").build();
170  }
171  } catch (Exception e) {
172  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AutocompleteResource"))
173  .header("Content-Type", "application/json;charset=UTF-8").build();
174  }
175  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

◆ getSuggestionsForLabels()

Response getSuggestionsForLabels ( @QueryParam("query") String  requestquery)
28  {
29  try {
30  String substing = requestquery.toLowerCase();
31  substing = URLDecoder.decode(substing, "UTF-8");
32  int suggestions = 20;
33  int minLength = 1;
34  if (substing.length() <= minLength) {
35  throw new AutocompleteLengthException();
36  } else {
37  RDF rdf = new RDF();
38  String query = rdf.getPREFIXSPARQL();
39  query += "SELECT * WHERE { "
40  + "?s a ls:Label . "
41  + "?s skos:prefLabel ?acquery . "
42  + "FILTER(regex(?acquery, '" + substing + "', 'i'))"
43  + "} "
44  + "ORDER BY ASC(?acquery)"
45  + "LIMIT " + suggestions;
46  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
47  List<String> suggestion_uri = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "s");
48  List<String> suggestion_string = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "acquery");
49  JSONObject jsonobj_query = new JSONObject();
50  JSONArray jsonarray_suggestions = new JSONArray();
51  for (int i = 0; i < suggestion_uri.size(); i++) {
52  JSONObject jsonobj_suggestion = new JSONObject();
53  String[] sugstr = suggestion_string.get(i).split("@");
54  if (sugstr.length > 1) {
55  jsonobj_suggestion.put("value", sugstr[0].replace("\"", ""));
56  jsonobj_suggestion.put("lang", sugstr[1].replace("\"", ""));
57  } else {
58  jsonobj_suggestion.put("value", suggestion_string.get(i));
59  }
60  jsonobj_suggestion.put("data", suggestion_uri.get(i));
61  jsonarray_suggestions.add(jsonobj_suggestion);
62  }
63  jsonobj_query.put("suggestions", jsonarray_suggestions);
64  jsonobj_query.put("query", substing);
65  return Response.ok(jsonobj_query).header("Content-Type", "application/json;charset=UTF-8").build();
66  }
67  } catch (Exception e) {
68  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AutocompleteResource"))
69  .header("Content-Type", "application/json;charset=UTF-8").build();
70  }
71  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

◆ getSuggestionsForLabelsFilter()

Response getSuggestionsForLabelsFilter ( @QueryParam("query") String  requestquery,
@PathParam("filter") String  filter,
@PathParam("value") String  value 
)
76  {
77  try {
78  String substing = requestquery.toLowerCase();
79  substing = URLDecoder.decode(substing, "UTF-8");
80  int suggestions = 20;
81  int minLength = 1;
82  if (substing.length() <= minLength) {
83  throw new AutocompleteLengthException();
84  } else {
85  RDF rdf = new RDF();
86  String query = rdf.getPREFIXSPARQL();
87  query += "SELECT * WHERE { "
88  + "?s a ls:Label . "
89  + "?s skos:prefLabel ?acquery . "
90  + "?s dc:creator ?creator . "
91  + "?s skos:inScheme ?vocabulary . "
92  + "FILTER(regex(?acquery, '" + substing + "', 'i'))";
93  if (filter.equals("creator")) {
94  query += "FILTER(?creator=\"" + value + "\")";
95  } else if (filter.equals("vocabulary")) {
96  query += "FILTER(?vocabulary=<" + rdf.getPrefixItem("ls_voc:" + value) + ">)";
97  }
98  query += "} "
99  + "ORDER BY ASC(?acquery)"
100  + "LIMIT " + suggestions;
101 
102  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
103  List<String> suggestion_uri = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "s");
104  List<String> suggestion_string = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "acquery");
105  JSONObject jsonobj_query = new JSONObject();
106  JSONArray jsonarray_suggestions = new JSONArray();
107  for (int i = 0; i < suggestion_uri.size(); i++) {
108  JSONObject jsonobj_suggestion = new JSONObject();
109  String[] sugstr = suggestion_string.get(i).split("@");
110  if (sugstr.length > 1) {
111  jsonobj_suggestion.put("value", sugstr[0].replace("\"", ""));
112  jsonobj_suggestion.put("lang", sugstr[1].replace("\"", ""));
113  } else {
114  jsonobj_suggestion.put("value", suggestion_string.get(i));
115  }
116  jsonobj_suggestion.put("data", suggestion_uri.get(i));
117  jsonarray_suggestions.add(jsonobj_suggestion);
118  }
119  jsonobj_query.put("suggestions", jsonarray_suggestions);
120  jsonobj_query.put("query", substing);
121  return Response.ok(jsonobj_query).header("Content-Type", "application/json;charset=UTF-8").build();
122  }
123  } catch (Exception e) {
124  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AutocompleteResource"))
125  .header("Content-Type", "application/json;charset=UTF-8").build();
126  }
127  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

◆ getSuggestionsForVocabs()

Response getSuggestionsForVocabs ( @QueryParam("query") String  requestquery)
180  {
181  try {
182  String substing = requestquery.toLowerCase();
183  substing = URLDecoder.decode(substing, "UTF-8");
184  int suggestions = 10;
185  int minLength = 1;
186  if (substing.length() <= minLength) {
187  throw new AutocompleteLengthException();
188  } else {
189  RDF rdf = new RDF();
190  String query = rdf.getPREFIXSPARQL();
191  query += "SELECT * WHERE { "
192  + "?s a ls:Vocabulary . "
193  + "?s dc:title ?acquery . "
194  + "FILTER(regex(?acquery, '" + substing + "', 'i'))";
195  query += "} "
196  + "ORDER BY ASC(?acquery) "
197  + "LIMIT " + suggestions;
198  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
199  List<String> suggestion_uri = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "s");
200  List<String> suggestion_string = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "acquery");
201  JSONObject jsonobj_query = new JSONObject();
202  JSONArray jsonarray_suggestions = new JSONArray();
203  for (int i = 0; i < suggestion_uri.size(); i++) {
204  JSONObject jsonobj_suggestion = new JSONObject();
205  String[] sugstr = suggestion_string.get(i).split("@");
206  if (sugstr.length > 1) {
207  jsonobj_suggestion.put("value", sugstr[0].replace("\"", ""));
208  jsonobj_suggestion.put("lang", sugstr[1].replace("\"", ""));
209  } else {
210  jsonobj_suggestion.put("value", suggestion_string.get(i));
211  }
212  jsonobj_suggestion.put("data", suggestion_uri.get(i));
213  jsonarray_suggestions.add(jsonobj_suggestion);
214  }
215  jsonobj_query.put("suggestions", jsonarray_suggestions);
216  jsonobj_query.put("query", substing);
217  return Response.ok(jsonobj_query).header("Content-Type", "application/json;charset=UTF-8").build();
218  }
219  } catch (Exception e) {
220  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.AutocompleteResource"))
221  .header("Content-Type", "application/json;charset=UTF-8").build();
222  }
223  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

rdf
Definition: RDF.java:1
Exception