Skip to content

Instantly share code, notes, and snippets.

@awoods
Created July 25, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awoods/2f790d6b0e089ef04a352d87dfd7cc3c to your computer and use it in GitHub Desktop.
Save awoods/2f790d6b0e089ef04a352d87dfd7cc3c to your computer and use it in GitHub Desktop.
Modeling membership with ldp:isMemberOfRelation
#!/bin/bash
BASE=http://localhost:8080/fcrepo/rest/$RANDOM
COL=$BASE/memberCollection
curl -X PUT $BASE/objects && echo
# create a collection
curl -X PUT $COL && echo
# create indirect container for members
curl -X PUT -H "Content-Type: text/turtle" -d "
@prefix ore: <http://www.openarchives.org/ore/terms/> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix pcdm: <http://pcdm.org/models#> .
<> a ldp:IndirectContainer ;
ldp:isMemberOfRelation pcdm:memberOf ;
ldp:insertedContentRelation ore:proxyFor ;
ldp:membershipResource <$COL> ." $COL/members && echo
N=0
MAX=10000
while [ $N -lt $MAX ]; do
# create an object
OBJ=`curl -s -X POST -H "Content-Type: application/sparql-update" -d "
prefix dc: <http://purl.org/dc/elements/1.1/>
insert { <> dc:title \"this is object # $N\" } where { }" $BASE/objects`
# add membership proxy
curl -s -X POST -H "Content-type: application/sparql-update" -d "
prefix ore: <http://www.openarchives.org/ore/terms/>
insert {
<> a ore:Proxy ;
ore:proxyFor <$OBJ> ;
ore:proxyIn <$COL> . }
where { }" $COL/members > /dev/null
N=$(( $N + 1 ))
if [ $(( $N % 500 )) == 0 ]; then
echo $N objects
fi
done
echo retrieving $COL
time -p curl -H "Accept: application/n-triples" $COL > 10k-members.nt
grep -c hasMember 10k-members.nt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment