Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fuseki related
**/run/*
**/fuseki.out
73 changes: 52 additions & 21 deletions bin/esteemer.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
#!/usr/bin/env bash

# Requires fuseki-server to be installed
command -v robot 1> /dev/null 2>&1 || \
{ echo >&2 "fuseki-server required but it's not in PATH. Aborting."; exit 1; }

# Usage message
read -r -d '' USE_MSG <<'HEREDOC'
Usage:
esteemer.sh
esteemer.sh -h
esteemer.sh -p causal_pathway.json
esteemer.sh -s spek.json

Esteemer reads a spek from stdin or provided file path.
Esteemer is currently a rubber stamp that adds 'promoted by' predicate to approved candidates.

Options:
-h | --help print help and exit
-s | --spek path to spek file (default to stdin)
HEREDOC

# From Chris Down https://gist.github.com/cdown/1163649
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}

# From Chris Down https://gist.github.com/cdown/1163649
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}

# Parse args
PARAMS=()
while (( "$#" )); do
Expand Down Expand Up @@ -52,17 +79,23 @@ if [[ -z ${FUSEKI_PING}} || ${FUSEKI_PING} -ne 200 ]]; then
echo >&2 "Fuseki not running locally.";

# Try to start custom fuseki locally
FUSEKI_DIR=/opt/fuseki/apache-jena-fuseki-3.10.0
${FUSEKI_DIR}/fuseki-server --mem --update /ds 1> fuseki.out 2>&1 &

exit 1;
fuseki-server --mem --update /ds 1> fuseki.out 2>&1 &
read -p "Waiting five secs for Fuseki to start..." -t 5
fi

# Define SPARQL Queries for updates and results
# Define,url encode, and create param string for fully qualified graph iris.
VAL_SPEK="http://localhost:3030/ds/spek"
ENC_SPEK=$(urlencode "${VAL_SPEK}")
PARAM_SPEK="graph=${ENC_SPEK}"

VAL_SEEPS="http://localhost:3030/ds/seeps"
ENC_SEEPS=$(urlencode "${VAL_SEEPS}")
PARAM_SEEPS="graph=${ENC_SEEPS}"

# Define SPARQL Query for updating spek
read -r -d '' UPD_SPARQL <<'SPARQL'
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX cpo: <http://example.com/cpo#>
PREFIX slowmo: <http://example.com/slowmo#>

INSERT {
Expand All @@ -72,29 +105,27 @@ INSERT {
}
USING <http://localhost:3030/ds/spek>
WHERE {
?candi a cpo:cpo_0000053 .
?candi a obo:cpo_0000053 .
?candi slowmo:acceptable_by ?o
}
SPARQL


# Read from SPEK_FILE or pipe from stdin
# Use '-' to instruct curl to read from stdin
if [[ -z ${SPEK_FILE} ]]; then
SPEK_FILE="-"
# If spek file is not empty, load into fuseki
# Otherwise assume it's loaded into fuseki already.
if [[ ! -z ${SPEK_FILE} ]]; then
# Load in spek
curl --silent -X PUT --data-binary "@${SPEK_FILE}" \
--header 'Content-type: application/ld+json' \
"http://localhost:3030/ds?${PARAM_SPEK}" >&2
fi

# Load spek into fuseki
curl --silent -X PUT --data-binary "@${SPEK_FILE}" \
--header 'Content-type: application/ld+json' \
'http://localhost:3030/ds?graph=spek' >&2

# run update sparql
curl --silent -X POST --data-binary "${UPD_SPARQL}" \
--header 'Content-type: application/sparql-update' \
'http://localhost:3030/ds/update' >&2

# get updated spek
curl --silent -X GET --header 'Accept: application/ld+json' \
'http://localhost:3030/ds?graph=spek'

curl --silent -G --header 'Accept: application/ld+json' \
--data-urlencode "graph=http://localhost:3030/ds/spek" \
'http://localhost:3030/ds'
32 changes: 32 additions & 0 deletions test/alice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Start by assuming it was the path invoked.
THIS_SCRIPT="$0"

# Handle resolving symlinks to this script.
# Using ls instead of readlink, because bsd and gnu flavors
# have different behavior.
while [ -h "$THIS_SCRIPT" ] ; do
ls=`ls -ld "$THIS_SCRIPT"`
# Drop everything prior to ->
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
THIS_SCRIPT="$link"
else
THIS_SCRIPT=`dirname "$THIS_SCRIPT"`/"$link"
fi
done

# Get path to the scripts directory.
SCRIPT_DIR=$(dirname "${THIS_SCRIPT}")

ESTEEMER="${SCRIPT_DIR}/../bin/esteemer.sh"
TEST_SPEK="${SCRIPT_DIR}/alice_spek.json"


CANDIDATE_TYPE="http://purl.obolibrary.org/obo/cpo_0000053"

${ESTEEMER} -s ${TEST_SPEK} |\
jq --arg t "$CANDIDATE_TYPE" '."@graph"[] | select(."@type" == $t and ."AncestorPerformer" == "_:pAlice")' |\
grep --color -E '"promoted_by.*"|^'

Loading