Created
August 25, 2016 14:33
-
-
Save jindrichmynarz/706dc4dd62efd64ec3d76ce77c6f38a6 to your computer and use it in GitHub Desktop.
Match concepts from two SKOS code lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Match concepts from two SKOS code lists. | |
# Usage: match_code_lists.sh code_list_1.ttl code_list_2.ttl | |
# Outputs RDF in Turtle with the links found. | |
set -e | |
shopt -s extglob | |
die () { | |
echo >&2 "$@" | |
exit 1 | |
} | |
# Test correct number of arguments. | |
if [ "$#" -ne 2 ]; then | |
die "Two files must be provided for matching!" | |
fi | |
# Test if the linked files exist. | |
for i in "$@" | |
do | |
if [ ! -f $i ]; then | |
die "File $i not found!" | |
fi | |
done | |
! [ $1 == $2 ] || die "Cannot link the same file." | |
# Test if arq is installed. | |
command -v arq >/dev/null 2>&1 || die "Missing Jena ARQ!" | |
QUERY=$(cat <<-END | |
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | |
CONSTRUCT { | |
?a skos:exactMatch ?b . | |
} | |
WHERE { | |
GRAPH <$1> { | |
?a a skos:Concept ; | |
skos:prefLabel ?prefLabel ; | |
skos:notation ?notation . | |
} | |
GRAPH <$2> { | |
?b a skos:Concept ; | |
skos:prefLabel ?prefLabel ; | |
skos:notation ?notation . | |
} | |
} | |
END) | |
arq --namedGraph $1 --namedGraph $2 "${QUERY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment