Skip to content

Instantly share code, notes, and snippets.

@escowles

escowles/10k-memberof.sh

Last active Jul 26, 2016
Embed
What would you like to do?
members vs. uris
#!/bin/bash
BASE=http://localhost:8080/rest/$RANDOM
COL=$BASE/collection
curl -X PUT $BASE/objects && echo
# create a collection
curl -X PUT $COL && echo
N=0
MAX=$1
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`
# create indirect container for members
curl -s -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:hasMemberRelation pcdm:memberOf ;
ldp:insertedContentRelation ore:proxyIn ;
ldp:membershipResource <$OBJ> ." $OBJ/membership > /dev/null
# add membership proxy
curl -s -X POST -H "Content-type: text/turtle" --data-binary "
@prefix ore: <http://www.openarchives.org/ore/terms/> .
<> a ore:Proxy ;
ore:proxyFor <$OBJ> ;
ore:proxyIn <$COL> ." $OBJ/membership > /dev/null
N=$(( $N + 1 ))
if [ $(( $N % 100 )) = 0 ]; then
echo $N objects created
fi
done
echo retrieving $COL without members
time -p curl -H "Accept: application/n-triples" $COL > 10k-members.nt
grep -c memberOf 10k-members.nt
echo "retrieving $COL with members (inbound links)"
time -p curl -H "Accept: application/n-triples" -H "Prefer: return=representation; include=\"http://fedora.info/definitions/v4/repository#InboundReferences\"" $COL > 10k-members.nt
grep -c memberOf 10k-members.nt
#!/bin/bash
BASE=http://localhost:8080/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:hasMemberRelation pcdm:hasMember ;
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: text/turtle" --data-binary "
@prefix ore: <http://www.openarchives.org/ore/terms/> .
<> a ore:Proxy ;
ore:proxyFor <$OBJ> ;
ore:proxyIn <$COL> ." $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
#!/bin/sh
BASE=http://localhost:8080/rest/$RANDOM
OBJ=$BASE/propsCollection
# create a collection
curl -X PUT $OBJ && echo
N=0
MAX=10000
while [ $N -lt $MAX ]; do
# add a property
curl -X PATCH -H "Content-Type: application/sparql-update" -d "
prefix dc: <http://purl.org/dc/elements/1.1/>
insert { <> dc:title \"this is object # $N\" } where { }" $OBJ
N=$(( $N + 1 ))
if [ $(( $N % 500 )) == 0 ]; then
echo $N props
fi
done
echo retrieving object
time curl -H "Accept: application/n-triples" $OBJ > 10k-props.nt
grep -c title 10k-props.nt
#!/bin/sh
BASE=http://localhost:8080/rest/$RANDOM
COL=$BASE/uriCollection
# create a collection
curl -X PUT $COL && echo
N=0
MAX=10000
while [ $N -lt $MAX ]; do
# add a property
curl -X PATCH -H "Content-Type: application/sparql-update" -d "
prefix dc: <http://purl.org/dc/elements/1.1/>
insert { <> dc:relation <http://example.org/uri/$N> } where { }" $COL
N=$(( $N + 1 ))
if [ $(( $N % 500 )) == 0 ]; then
echo $N properties
fi
done
echo retrieving $COL
time -p curl -H "Accept: application/n-triples" $COL > 10k-uris.nt
grep -c relation 10k-uris.nt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment