Count labels with language filtering
This commit is contained in:
parent
5075d78537
commit
c07af3d794
1 changed files with 20 additions and 11 deletions
|
@ -282,6 +282,14 @@ class IndividualResponseBuilder {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String LABEL_QUERY = ""
|
||||||
|
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
|
+ "SELECT ?label WHERE { \n"
|
||||||
|
+ " ?subject rdfs:label ?label \n"
|
||||||
|
+ " FILTER isLiteral(?label) \n"
|
||||||
|
+ "}" ;
|
||||||
|
|
||||||
|
// Query that was previously used for a count of labels in all languages
|
||||||
private static String LABEL_COUNT_QUERY = ""
|
private static String LABEL_COUNT_QUERY = ""
|
||||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
+ "SELECT ( str(COUNT(?label)) AS ?labelCount ) WHERE { \n"
|
+ "SELECT ( str(COUNT(?label)) AS ?labelCount ) WHERE { \n"
|
||||||
|
@ -297,19 +305,20 @@ class IndividualResponseBuilder {
|
||||||
+ "}" ;
|
+ "}" ;
|
||||||
|
|
||||||
private static Integer getLabelCount(String subjectUri, VitroRequest vreq) {
|
private static Integer getLabelCount(String subjectUri, VitroRequest vreq) {
|
||||||
String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri);
|
// 1.12.0 Now filtering to only the labels for the current locale so as
|
||||||
|
// to be consistent with other editing forms. Because the language
|
||||||
|
// filter can only act on a result set containing actual literals,
|
||||||
|
// we can't do the counting with a COUNT() in the query itself. So
|
||||||
|
// we will now use the LABEL_QUERY instead of LABEL_COUNT_QUERY and
|
||||||
|
// count the rows.
|
||||||
|
String queryStr = QueryUtils.subUriForQueryVar(LABEL_QUERY, "subject", subjectUri);
|
||||||
log.debug("queryStr = " + queryStr);
|
log.debug("queryStr = " + queryStr);
|
||||||
int theCount = 0;
|
int theCount = 0;
|
||||||
try {
|
try {
|
||||||
//ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||||
//Get query results across all languages in order for template to show manage labels link correctly
|
while(results.hasNext()) {
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
results.next();
|
||||||
if (results.hasNext()) {
|
theCount++;
|
||||||
QuerySolution soln = results.nextSolution();
|
|
||||||
RDFNode labelCount = soln.get("labelCount");
|
|
||||||
if (labelCount != null && labelCount.isLiteral()) {
|
|
||||||
theCount = labelCount.asLiteral().getInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue