-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-rdf-metadata
executable file
·67 lines (55 loc) · 1.52 KB
/
load-rdf-metadata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/bash
set -euo pipefail
function usage() {
echo "Usage: $0 COLLECTION_ID [--issued]"
echo "Update description about a collection in Fuseki."
echo "Option --issued updates dct:issued with current timestamp."
exit
}
issued=${2:-}
[[ "${1:-}" =~ ^[0-9]*$ ]] || usage
[[ $# -le 2 ]] || usage
[[ $# -eq 2 ]] && [[ "$issued" != "--issued" ]] && usage
function error() {
echo $@ >&2
exit 1
}
id=$1
uri=https://graph.nfdi4objects.net/collection/$id
collections=collections.json
about=$(jq --arg id $uri '.[]|select(.id==$id)' $collections \
| npm run --silent -- jsonld2rdf -c sources/context.json)
[[ -z "$about" ]] && error "Missing $uri in $collections"
filter="FILTER (?p != dct:issued)"
[[ -z "$issued" ]] || filter=""
echo "Deleting metadata of $uri"
sparql=$(cat <<-SPARQL
PREFIX n4oc: <https://graph.nfdi4objects.net/collection/>
PREFIX dct: <http://purl.org/dc/terms/>
WITH n4oc:
DELETE { ?s ?p ?o }
WHERE {
{ VALUES ?s { n4oc:$id } ?s ?p ?o }
UNION
{ VALUES ?o { n4oc:$id } ?s ?p ?o }
$filter
}
SPARQL
)
# echo "$sparql"
./update-rdf "$sparql"
[[ ! -z "$issued" ]] && issued="<$uri> dct:issued \"$(date -Iminutes)\"^^xsd:dateTime ."
echo "Adding new metadata of $uri"
sparql=$(cat <<-SPARQL
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
INSERT DATA { GRAPH <https://graph.nfdi4objects.net/collection/> {
$about
<$uri> skos:notation "$id" .
$issued
} }
SPARQL
)
# echo "$sparql"
./update-rdf "$sparql"