-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt2ttl.sh
executable file
·53 lines (43 loc) · 941 Bytes
/
txt2ttl.sh
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
47
48
49
50
51
52
53
#!/bin/bash
outfile=/dev/stdout
language=${LANG:0:2}
usage () {
echo "$1"
cat <<EOF
USAGE: $0 [ -o OUTFILE ] [ -l LANGUAGE ] TXT-FILE
-o send RDF/turtle output to OUTFILE; defaults to $outfile
-l language of the text literal; defaults to $language
This makes a single RDF triple from the contents of a plaintext file.
EOF
exit $2
}
while (($# > 1)); do
case $1 in
-o)
outfile=$2
shift
shift
;;
-l)
language=$2
shift
shift
;;
-h)
shift
usage "" 1
;;
-*)
usage "" 2
;;
esac
done
if [ $# -lt 1 ]; then usage "" 1; fi
[ -f $1 ] || usage "ERROR: '$1' no such file" 1
infile=$1
rangeId=$(basename -s .txt $infile)
subject="<http://github.com/lueck/standoff-mode/annotation/"$rangeId">"
predicate="<http://github.com/lueck/standoff-mode/owl#text>"
cat > $outfile <<EOF
$subject $predicate "$(sed "s/\\\"/\\\\\"/g" $infile)"@$language .
EOF