summaryrefslogtreecommitdiff
path: root/bibtotxt.sh
blob: 71f16ec4be181836b3ef290f7e8b2b3e2bdcdb0e (plain)
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
#!/bin/sh

rdf="$1"

echo "Academic Publications"
echo "-----------------------------------------------------------------------"
echo ""

q="PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX bibo: <http://purl.org/ontology/bibo/>
SELECT ?a ?title ?artdate ?stat ?jtitle ?juri ?vol ?iss
WHERE {
?a a bibo:Article;
   dc:title ?title;
   dc:date ?artdate;
   dc:isPartOf ?j.
   OPTIONAL { ?a bibo:status ?stat }.
   OPTIONAL { ?a bibo:volume ?vol }.
   OPTIONAL { ?a bibo:issue ?iss }.
?j dc:title ?jtitle;
   bibo:uri ?juri.
}
ORDER BY DESC(?artdate)"

roqet -q -r csv -e "$q" -D /dev/stdin < $rdf | sed '/^Result/d' \
| while read r; do
	# note that plan9 sed needs the ( in uri( etc escaped with \(
	uri=`echo $r | awk -F , '{print $2}'| sed -e 's/^uri(//' -e 's/)$//'`
	reluri=`echo $uri | sed 's/.*\///'`
	title=`echo $r | awk -F , '{print $3}'| sed -e 's/^"//' -e 's/"$//'`
	artdate=`echo $r | awk -F , '{print $4}'| sed -e 's/^"//' -e 's/"$//'`
	stat=`echo $r | awk -F , '{print $5}'| sed -e 's/^uri(//' -e 's/^[^\/]*\///' -e 's/)$//'`
	jtitle=`echo $r | awk -F , '{print $6}'| sed -e 's/^"//' -e 's/"$//'`
	juri=`echo $r | awk -F , '{print $7}'| sed -e 's/^"//' -e 's/"$//'`
	vol=`echo $r | awk -F , '{print $8}'| sed -e 's/^"//' -e 's/"$//'`
	iss=`echo $r | awk -F , '{print $9}'| sed -e 's/^"//' -e 's/"$//'`

	echo "- [${title}](${reluri})"
	echo "  [[PDF]](${reluri}.pdf) (${artdate})"
	echo "  *[${jtitle}](${juri})*"
	test -n "$vol" && echo -n "  Vol. $vol"
	test -n "$iss" && echo ", No. $iss"
	test -n "$stat" && echo "  [${stat}]"
done

exit 0