Skip to content

Commit

Permalink
Merge branch '134-datasetDescription' of https://github.com/hbz/lobid…
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg authored and sol committed Sep 20, 2018
2 parents 8e1bbeb + 49b0210 commit 78dc48b
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 10 deletions.
34 changes: 28 additions & 6 deletions app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public Result index() {
.setQuery(functionScoreQuery).setFrom(0).setSize(1);
SearchHit hit = requestBuilder.execute().actionGet().getHits().getAt(0);
AuthorityResource entity = entityWithImage(hit.getSourceAsString());
return ok(views.html.index.render(entity));
JsonNode dataset = Json.parse(readFile(config("dataset.file")));
return ok(views.html.index.render(entity, dataset));
}

/**
Expand Down Expand Up @@ -245,15 +246,36 @@ private Result result(String content, String contentType) {

public Result context() {
response().setHeader("Access-Control-Allow-Origin", "*");
return ok(readFile(config("context.file"))).as(config("context.content"));
}

/**
* See https://www.w3.org/TR/dwbp/#metadata
*
* @param format
* The format ("jsonld" or "")
*
* @return JSON-LD dataset metadata
*/
public Result dataset(String format) {
response().setHeader("Access-Control-Allow-Origin", "*");
Format responseFormat = Accept.formatFor(format, request().acceptedTypes());
String content = readFile(config("dataset.file"));
return responseFormat.queryParamString.startsWith("json") ? //
ok(content).as(config("dataset.content")) : //
ok(views.html.dataset.render(Json.parse(content)));
}

private String readFile(String name) {
try {
File file = env.getFile(config("context.file"));
File file = env.getFile(name);
Path path = Paths.get(file.getAbsolutePath());
return ok(Files.readAllLines(path).stream().collect(Collectors.joining("\n")))
.as(config("context.content"));
String content = Files.readAllLines(path).stream().collect(Collectors.joining("\n"));
return content;
} catch (IOException e) {
e.printStackTrace();
Logger.error("Couldn't get: " + name, e);
return null;
}
return null;
}

public Result gnd(String id) {
Expand Down
51 changes: 51 additions & 0 deletions app/views/dataset.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@* Copyright 2014-2018 Fabian Steeg, hbz. Licensed under the GPLv2 *@

@(json: com.fasterxml.jackson.databind.JsonNode)

@import helper._

@main("", "Dataset: lobid-gnd") {
<h3>Daten<small><a title="Beschreibung als JSON-LD anzeigen" href='@routes.HomeController.dataset("json")'><img class='json-ld-icon' src='@routes.Assets.versioned("images/json-ld.png")'></a></small></h3>
<table class="table table-striped">
<tr><th width="20%"/><th width="80%"/></tr>
<tr>
<td>Titel</td>
<td><a href='@json.get("id").asText()'>
@json.get("name").get("de").asText() &mdash; @json.get("alternateName").get("de").asText()
</a></td>
</tr>
<tr><td>Beschreibung</td><td>@Html(json.get("description").get("de").asText())</td></tr>
<tr>
<td>Schlagwörter</td>
<td>@json.get("keywords").toString().replaceAll("\",\"", ", ").replaceAll("[\"\\[\\]]", "")</td>
</tr>
@defining(json.get("publisher")) { pub =>
<tr>
<td>Veröffentlicht von</td>
<td><a href='@pub.get("id").asText()'>
@pub.get("name").get("de").asText() &mdash; @pub.get("alternateName").elements().next().asText()
</a></td>
</tr>
}
<tr><td>Basiert auf</td><td><a href='@json.get("isBasedOn").get("url").asText()'>@json.get("isBasedOn").get("name").get("de").asText()</a></td></tr>
<tr><td>Veröffentlicht am</td><td>@json.get("datePublished").asText()</td></tr>
<tr><td>Sprache</td><td>@json.get("inLanguage").elements().next().asText()</td></tr>
<tr><td>Ergänzungsfrequenz</td><td>@json.get("accrualPeriodicity").get("name").get("de").asText()</td></tr>
<tr><td>Kontakt</td><td><a href='@json.get("contactPoint").asText()'>@json.get("contactPoint").asText()</a></td></tr>
</table>
<h3>API</h3>
@defining(json.get("distribution").elements().next()) { dist =>
<table class="table table-striped">
<tr><th width="20%"/><th width="80%"/></tr>
<tr><td>Titel</td><td>@dist.get("name").get("de").asText()</td></tr>
<tr><td>Beschreibung</td><td>@Html(dist.get("description").get("de").asText())</td></tr>
<tr><td>Dokumentation</td><td><a href='@dist.get("documentation").asText()'>@Html(dist.get("documentation").asText())</a></td></tr>
<tr><td>URL</td><td><a href='@dist.get("url").asText()'>@dist.get("url").asText()</a></td></tr>
<tr><td>Lizenz</td><td><a href='@dist.get("license").asText()'>@dist.get("license").asText()</a></td></tr>
<tr><td>Medientypen</td><td>@dist.get("encodingFormat").toString().replaceAll("\",\"", ", ").replaceAll("[\"\\[\\]]", "")</td></tr>
</table>
}
<script type="application/ld+json">
@Html(json.toString)
</script>
}
6 changes: 2 additions & 4 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@* Copyright 2017 Fabian Steeg, hbz. Licensed under the GPLv2 *@

@(entity: AuthorityResource)
@(entity: AuthorityResource, dataset: com.fasterxml.jackson.databind.JsonNode)

@import helper._

Expand All @@ -11,9 +11,7 @@ <h1>lobid-gnd <small>&mdash; Rechercheoberfläche &amp; LOD-API für die GND</sm
</div>
<div class="row">
<div class="col-md-9 intro">
<p class="lead">Die Gemeinsame Normdatei (GND) enthält über 15 Millionen Normdatensätze. Sie wird zur Katalogisierung von Literatur in Bibliotheken, sowie von Archiven, Museen, und verschiedenen Projekten genutzt.</p>
<p>Die GND enthält normierte Einträge für Personen, Körperschaften, Kongresse, Geografika, Sachschlagwörter und Werktitel. Sie wird von der Deutschen Nationalbibliothek (DNB), den deutschsprachigen Bibliotheksverbünden, der Zeitschriftendatenbank (ZDB) und zahlreichen weiteren Institutionen kooperativ geführt. Die Daten sind unter CC0 lizenziert.</p>
<p>lobid-gnd bietet <a href='@routes.HomeController.search("*")'>eine Rechercheoberfläche zum Durchsuchen der GND</a> und <a href='@routes.HomeController.api()'>eine Web-API auf Basis von JSON-LD</a> zur Verwendung der Daten in neuen Kontexten.</p>
@Html(dataset.get("description").get("de").asText())
</div>
<div class="col-md-3">
<figure>
Expand Down
3 changes: 3 additions & 0 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<li @if(title=="lobid-gnd - API"){class="active"}>
<a href="@routes.HomeController.api()" title="Programmierschnittstelle">Programmierschnittstelle (API)</a>
</li>
<li @if(title=="Dataset: lobid-gnd"){class="active"}>
<a href='@routes.HomeController.dataset("")'>Datenbeschreibung</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Kontakt</li>
<li><a href="mailto:semweb@@hbz-nrw.de?subject=Feedback%20zu%20lobid-gnd,%20aktuelle%20URL%20@controllers.HomeController.currentUri()">Feedback zur aktuellen Seite</a></li>
Expand Down
5 changes: 5 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ context {
prod: "http://lobid.org/gnd/context.jsonld"
}

dataset {
file: "conf/dataset.jsonld"
content: "application/ld+json; charset=utf-8"
}

topLevelTypes : [
AuthorityResource,
CorporateBody,
Expand Down
99 changes: 99 additions & 0 deletions conf/dataset.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"@context":{
"id":"@id",
"type":"@type",
"@vocab":"http://schema.org/",
"accrualPeriodicity":{
"@id":"http://purl.org/dc/terms/accrualPeriodicity",
"@type":"@id"
},
"description":{
"@container":"@language"
},
"name":{
"@container":"@language"
},
"alternateName": {
"@container": "@language"
},
"Concept": "http://www.w3.org/2004/02/skos/core#Concept"
},
"id":"http://lobid.org/resources/dataset#!",
"type":"Dataset",
"name":{
"de":"lobid-gnd",
"en":"lobid-gnd"
},
"alternateName": {
"de":"LOD-API für die Gemeinsame Normdatei (GND)",
"en":"LOD-API for the Integrated Authority File (GND)"
},
"description":{
"de":"<p class='lead'>Die Gemeinsame Normdatei (GND) enthält über 15 Millionen Normdatensätze. Sie wird zur Katalogisierung von Literatur in Bibliotheken, sowie von Archiven, Museen, und Forschungsprojekten genutzt.</p><p>Die GND enthält normierte Einträge für Personen, Körperschaften, Kongresse, Geografika, Sachschlagwörter und Werktitel. Sie wird von der Deutschen Nationalbibliothek (DNB), den deutschsprachigen Bibliotheksverbünden, der Zeitschriftendatenbank (ZDB) und zahlreichen weiteren Institutionen kooperativ geführt. Die Daten sind unter CC0 lizenziert.</p><p>lobid-gnd bietet eine <a href=\"http://lobid.org/gnd/search\">Rechercheoberfläche zum Durchsuchen der GND</a> und eine <a href=\"http://lobid.org/gnd/api\">Web-API auf Basis von JSON-LD</a> zur Verwendung der Daten in verschiedenen Kontexten.</p>",
"en":"<p class='lead'>The Integrated Authority File (GND) contains more than 15 Million authority records. It is used for cataloging in libraries as well as in archives, museums and other contexts.</p><p>The GND contains authority records for persons, corporate bodies, congresses, places, subject headings and works. It is maintained cooperatively by the German National Library (DNB), German-speaking library networks, the German Union Catalogue of Serials (ZDB) and many other institutions. The data is licensed under CC0.</p><p>lobid-gnd provides a <a href=\"http://lobid.org/gnd/search\">search interface for exploring GND</a> and <a href=\"http://lobid.org/gnd/api\">a web API based on JSON-LD</a> to enable use of the data in different contexts.</p>"
},
"keywords":[
"authority data",
"Germany",
"Austria",
"Switzerland"
],
"datePublished":"2018-07-11",
"contactPoint":"http://lobid.org/contact",
"accrualPeriodicity":{
"id":"http://purl.org/linked-data/sdmx/2009/code#freq-B",
"type": "Concept",
"name":{
"en":"Daily - business week",
"de":"Täglich (werktags)"
}
},
"inLanguage":[
"de"
],
"publisher":{
"id":"http://lobid.org/organisations/DE-605#!",
"type": "Organization",
"name":{
"de":"Hochschulbibliothekszentrum des Landes Nordrhein-Westfalen",
"en":"North Rhine-Westphalian Library Service"
},
"alternateName":[
"hbz"
]
},
"isBasedOn": {
"type": "Dataset",
"url": "http://d-nb.info/gnd/7749153-1",
"name":{
"de":"Gemeinsame Normdatei (GND)",
"en":"Integrated Authority File (GND)"
},
"description":{
"de":"Genutzt werden die von der DNB bereitgestellten RDF-Datenabzüge der GND, siehe <a href=\"http://www.dnb.de/DE/Service/DigitaleDienste/LinkedData/linkeddata_node.html\">http://www.dnb.de/DE/Service/DigitaleDienste/LinkedData/linkeddata_node.html</a>.",
"en":"lobid-gnd uses the RDF dumps of the GND as provided by DNB, see <a href=\"http://www.dnb.de/EN/Service/DigitaleDienste/LinkedData/linkeddata_node.html\"></a>."
},
"license": "https://creativecommons.org/publicdomain/zero/1.0/"
},
"distribution":[
{
"id":"http://lobid.org/gnd/search",
"type":"WebAPI",
"name": {
"de": "lobid-gnd-API",
"en": "lobid-gnd API"
},
"description": {
"en": "<p>The API gives access to machine-readable data (JSON-LD via HTTP).</p>",
"de": "<p>Die API bietet Zugriff auf strukturierte Daten (JSON-LD via HTTP).</p>"
},
"url":"http://lobid.org/gnd/search",
"documentation": "http://lobid.org/gnd/api",
"encodingFormat":[
"application/json",
"application/ld+json"
],
"license": "https://creativecommons.org/publicdomain/zero/1.0/"
}
]
}
3 changes: 3 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ GET /gnd/api controllers.HomeController.api

GET /gnd/context.jsonld controllers.HomeController.context()

GET /gnd/dataset.jsonld controllers.HomeController.dataset(format="json")
GET /gnd/dataset controllers.HomeController.dataset(format?="")

GET /gnd/search controllers.HomeController.search(q ?= "", filter ?= "", from: Int ?= 0, size: Int ?= 10, format ?= null)

GET /gnd/:id.:format controllers.HomeController.authorityDotFormat(id, format)
Expand Down
6 changes: 6 additions & 0 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,10 @@ figcaption {
max-width: 100%;
max-height: 300px;
float: right;
}

.json-ld-icon {
margin-left: 1px;
float:right;
height: 1.4em
}
7 changes: 7 additions & 0 deletions test/controllers/AcceptIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class AcceptIntegrationTest extends IndexTest {
public static Collection<Object[]> data() {
// @formatter:off
return Arrays.asList(new Object[][] {
// service meta data: context and dataset description
{ fakeRequest(GET, "/gnd/context.jsonld"), /*->*/ "application/ld+json" },
{ fakeRequest(GET, "/gnd/dataset.jsonld"), /*->*/ "application/ld+json" },
{ fakeRequest(GET, "/gnd/dataset"), /*->*/ "application/ld+json" },
{ fakeRequest(GET, "/gnd/dataset").header("Accept", "text/html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/gnd/dataset").header("Accept", "application/ld+json"), /*->*/ "application/ld+json" },
{ fakeRequest(GET, "/gnd/dataset").header("Accept", "application/json"), /*->*/ "application/ld+json" },
// search, default format: JSON
{ fakeRequest(GET, "/gnd/search?q=*"), /*->*/ "application/json" },
{ fakeRequest(GET, "/gnd/search?q=*").header("Accept", "*/*"), /*->*/ "application/json" },
Expand Down

0 comments on commit 78dc48b

Please sign in to comment.