Skip to content

Commit

Permalink
Support skos:altLabel and skos:example in list filter (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Dec 27, 2024
1 parent c099d7e commit 52dc57d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/nwbib/Classification.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ private SearchResponse classificationData() {

private enum Property {
LABEL("http://www.w3.org/2004/02/skos/core#prefLabel"), //
ALT_LABEL("http://www.w3.org/2004/02/skos/core#altLabel"), //
EXAMPLE("http://www.w3.org/2004/02/skos/core#example"), //
BROADER("http://www.w3.org/2004/02/skos/core#broader"), //
NOTATION("http://www.w3.org/2004/02/skos/core#notation"), //
NARROW_MATCH("http://www.w3.org/2004/02/skos/core#narrowMatch"), //
Expand Down Expand Up @@ -457,6 +459,8 @@ private static void collectLabelAndValue(SearchHit hit, JsonNode json,
(style == Label.PLAIN || notation.isEmpty() ? ""
: "<span class='notation'>" + notation + "</span>" + " ")
+ label.findValue("@value").asText()) //
.put("altLabel", findValues(json, Property.ALT_LABEL)) //
.put("example", findValues(json, Property.EXAMPLE)) //
.put("hits", Lobid.getTotalHitsNwbibClassification(id)) //
.put("notation", notation) //
.put("focus", focus(json)) //
Expand All @@ -465,6 +469,11 @@ private static void collectLabelAndValue(SearchHit hit, JsonNode json,
}
}

private static List<String> findValues(JsonNode json, Property p) {
return json.has(p.value) ? json.get(p.value).findValuesAsText("@value")
: Arrays.asList();
}

private static List<String> matches(JsonNode json) {
List<String> result = new ArrayList<>();
addMatches(json, Property.NARROW_MATCH, result);
Expand Down
4 changes: 3 additions & 1 deletion app/views/tags/browse_list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
</script>
@for(json <- classes.getOrElse(Seq());
entryLabel = label(json);
altLabel = (json\"altLabel").asOpt[Seq[String]].getOrElse(Seq()).mkString("; ");
example = (json\"example").asOpt[Seq[String]].getOrElse(Seq()).mkString("; ");
normalized = entryLabel.replaceAll("ß", "ss") + entryLabel.replaceAll("ss", "ß");
value = (json\"value").as[String];
hits = (json\"hits").asOpt[scala.Long].getOrElse(0L);
Expand Down Expand Up @@ -107,7 +109,7 @@ <h4 class="modal-title" id="label-@matches.hashCode">Links für @Html(entryLabel
</div>
}
@if(t!="Zeitschriften"){<span @if(t!="Wikidata"){class='copy-link'}><a data-toggle="tooltip" data-placement="right" title="Identifikator und Bezeichnung in die Zwischenablage kopieren" href="#" onclick="copyToClipboard('@textToCopy', $(this));return false;"><span class="octicon octicon-clippy"></span></a></span>}
<div style="display: none">@normalized</div>
<div style="display: none">@normalized @altLabel @example</div>
}
@if(t=="Wikidata"){
@if(anchor.startsWith("Q")) {
Expand Down
20 changes: 20 additions & 0 deletions test/tests/InternalIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public void testLeadingBlanksInSearchWord() {
searchLeadingBlankWith("word=");
}

@Test // See https://github.com/hbz/nwbib/issues/657
public void testSearchInAltLabel() {
running(testServer(3333), () -> {
assertIndexDataForIdContains("N566042", "Ortsteil"); // from altLabel
});
}

@Test // See https://github.com/hbz/nwbib/issues/657
public void testSearchInExample() {
running(testServer(3333), () -> {
assertIndexDataForIdContains("N543620", "Betriebsrat"); // from example
});
}

private static void assertIndexDataForIdContains(String id, String string) {
assertThat(
Classification.ids("https://nwbib.de/subjects#" + id, "").toString())
.as("index data for " + id).contains(string);
}

private static void searchLeadingBlankWith(String param) {
running(testServer(3333), () -> {
try {
Expand Down

0 comments on commit 52dc57d

Please sign in to comment.