Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support skos:altLabel and skos:example in list filter (#657) #662

Open
wants to merge 1 commit into
base: 656-addSkosData
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]">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