Skip to content

Commit

Permalink
Extend mapping to RDF
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Aug 19, 2024
1 parent 5feb0b7 commit 7589dd4
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 479 deletions.
26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
all: n4o-collections.pg n4o-databases.pg n4o-databases.nt
all: rdf pg

n4o-databases.nt: n4o-databases.json
@npm run --silent jsonld2nt -- $< -c context.json > $@
@wc -l $@
rdf: n4o-sources.nt n4o-sources.ttl

n4o-databases.json: n4o-databases.csv
./update.js

n4o-collections.json: n4o-collections.csv
@node csv2json.js < $< > $@

n4o-collections.nt: n4o-collections.json
@npm run --silent jsonld2nt -- $< -c context.json > $@
n4o-sources.nt: n4o-collections.json n4o-databases.json
@npm run --silent jsonld2rdf -- $^ -c context.json > $@
@wc -l $@

n4o-sources.ttl: n4o-collections.json n4o-databases.json
@npm run --silent jsonld2rdf -- $^ -c context.json -p prefixes.json > $@
@echo $@

pg: n4o-collections.pg n4o-databases.pg

n4o-databases.pg: n4o-databases.csv
@npm run --silent update

n4o-collections.pg: n4o-collections.csv
@./pg.py > $@
@wc -l $@

n4o-source.nt: n4o-collections.nt n4o-databases.nt
cat $^ > $@
n4o-sources-pg.json: n4o-sources.pg
@npm run pgraph -- $< $@
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ verwendet mit folgenden Unterschieden:
- Zur Angabe einer Homepage wird `foaf:url` verwendet, da diese RDF Property bereits etabliert ist
- Es werden keinen eigenen URIs für Herausgeber, APIs und Dateiformate gebildet sondern Wikidata-URIs verwendet

Darüber hinaus werden die Daten als Property Graph in den Dateien [`n4o-databases-pg.json`] und [`n4o-databases.pg`] als PG-JSON bzw. PG format gespeichert.
Darüber hinaus werden die Daten als Property Graph in den Dateien [`n4o-sources-pg.json`] und [`n4o-sources.pg`] als PG-JSON bzw. PG format gespeichert.

### Collections

Expand Down Expand Up @@ -82,5 +82,5 @@ Alle Daten stehen als Public Domain (CC0) frei zur Verfügung.
[`n4o-databases.json`]: n4o-databases.json
[`n4o-databases.nt`]: n4o-databases.nt
[`n4o-databases.ttl`]: n4o-databases.ttl
[`n4o-databases-pg.json`]: n4o-databases-pg.json
[`n4o-databases.pg`]: n4o-databases.pg
[`n4o-sources-pg.json`]: n4o-sources-pg.json
[`n4o-sources.pg`]: n4o-sources.pg
12 changes: 8 additions & 4 deletions context.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
"schema": "http://schema.org/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"xsd": "http://www.w3.org/2001/XMLSchema#",

"@base": "http://www.wikidata.org/entity/",
"id": "@id",
"wikidata": "@id",
"db": {
"@context": { "@base": "http://www.wikidata.org/entity/" },
"@type": "@id",
"@reverse": "dcat:dataset"
},
"re3data": {
"@context": { "@base": "https://www.re3data.org/repository/" },
"@type": "@id",
Expand All @@ -20,11 +24,11 @@
"name": "schema:name",
"type": {
"@type": "@id",
"@id": "rdfs:type"
"@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"url": {
"@id": "foaf:homepage",
"@type": "dcat:anyURI"
"@type": "@id"
},
"publisher": {
"@id": "dcterms:publisher"
Expand Down
20 changes: 20 additions & 0 deletions csv2json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'fs'
import csv from 'csv-parser'

const results = []
process.stdin
.pipe(csv())
.on('data', (data) => {
for (let key in data) {
if (data[key] === "") delete data[key]
}
if ("id" in data) {
data.id = "http://data.nfdi4objects.net/collection/" + data.id
data.type = ["fabio:Database","dcat:Dataset"]
} else if ("wikidata" in data) {
data.id = "http://www.wikidata.org/entity/" + data.id
// TODO: type
}
results.push(data)
})
.on('end', () => console.log(JSON.stringify(results, null, 2)))
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ <h1>Forschungsdatenbanken im Rahmen von NFDI4Objects</h1>
eingetragen werden (Übernahme von Daten von dort ist geplant).
</p>
<p>
Die zusammengeführten Daten stehen
<a href="n4o-databases.json">in JSON</a>
Die zusammengeführten Daten stehen in JSON
(<a href="n4o-databases.json">databases</a> und <a href="n4o-collections.json">collections</a>)
und RDF
(<a href="n4o-databases.ttl">Turtle</a> und <a href="n4o-databases.nt">NTriples</a>)
(<a href="n4o-sources.ttl">Turtle</a> und <a href="n4o-sources.nt">NTriples</a>)
sowie als property graph
(<a href="n4o-databases-pg.json">PG-JSON</a> und <a href="n4o-databases.pg">PG format</a>)
(<a href="n4o-sources-pg.json">PG-JSON</a> und <a href="n4o-sources.pg">PG format</a>)
als Open Data zur freien Verfügung
(<a href="https://creativecommons.org/publicdomain/zero/1.0/deed.de">CC0</a>).
</p>
Expand Down
24 changes: 13 additions & 11 deletions jsonld2rdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ const readJSON = file => JSON.parse(fs.readFileSync(file, 'utf-8'))

program
.name("jsonld2rdf")
.argument("[file]","JSON-LD input file (- for stdin)")
.argument("[file...]","JSON-LD input file")
.option('-c, --context <file>', 'JSON-LD context document')
.option('-p, --prefixes <file>', 'RDF Prefix map (as JSON object) for Turtle output')
.action(async (file, options) => {
file = (!file || file == '-') ? process.stdin.fd : file
const data = readJSON(file)
.action(async (files, options) => {

const input = files.length ? files.map(readJSON) : readJSON(process.stdin.fd)

if (options.context) {
const context = readJSON(options.context)
if (Array.isArray(data)) {
data.forEach(item => (item["@context"] = context))
} else {
data["@context"] = context
for (let data of input) {
if (Array.isArray(data)) {
data.forEach(item => (item["@context"] = context))
} else {
data["@context"] = context
}
}
}

const nt = await jsonld.toRDF(data, {format: 'application/n-quads'})
const nt = (await Promise.all(input.map(
data => jsonld.toRDF(data, {format: 'application/n-quads'})
))).join("\n")

// pretty-print Turtle
if (options.prefixes) {
const prefixes = readJSON(options.prefixes)

const quads = []
const parserN3 = new ParserN3()
const output = parserN3.import(Readable.from(nt))
Expand Down
107 changes: 107 additions & 0 deletions n4o-collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[
{
"id": "http://data.nfdi4objects.net/collection/1",
"name": "Ur- und Frühgeschichtliche Sammlung der FAU",
"url": "https://objekte-im-netz.fau.de/projekt/node/22",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/2",
"name": "Paläontologischen Sammlung der FAU|Geowissenschaftliche Sammlung der FAU",
"url": "https://objekte-im-netz.fau.de/projekt/node/20",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/3",
"name": "Graphische Sammlung der FAU",
"url": "https://objekte-im-netz.fau.de/projekt/node/17",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/4",
"name": "Musikinstrumentensammlung der FAU",
"url": "https://objekte-im-netz.fau.de/projekt/node/19",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/5",
"name": "Medizinische Sammlung der FAU",
"url": "https://objekte-im-netz.fau.de/projekt/node/18",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/6",
"name": "Schulgeschichtliche Sammlung der FAU und Schulmuseum",
"url": "https://objekte-im-netz.fau.de/projekt/node/21",
"db": "Q124695065",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/7",
"name": "KENOM Virtuelles Münzportal",
"url": "http://www.kenom.de/",
"db": "Q21040628",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/8",
"name": "Samian Research Database",
"url": "https://rgzm.github.io/samian-lod/",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/9",
"name": "Linked Open Ogham",
"url": "https://doi.org/10.5281/zenodo.4765603",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/10",
"name": "African Red Slip Ware",
"url": "https://doi.org/10.5281/zenodo.5642751",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/11",
"name": "Digitale Sammlungen der Museen der Klassikstiftung Weimar",
"url": "https://ores.klassik-stiftung.de/ords/ksw_internet/r/300/home",
"db": "Q124536091",
"type": [
"fabio:Database"
]
},
{
"id": "http://data.nfdi4objects.net/collection/12",
"name": "Graphische Sammlung des Germanisches National Museum",
"url": "https://www.gnm.de/sammlungen/sammlungen-a-z/graphische-sammlung",
"db": "Q478695",
"type": [
"fabio:Database"
]
}
]
Loading

0 comments on commit 7589dd4

Please sign in to comment.