-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexc2md.bash
68 lines (66 loc) · 1.93 KB
/
lexc2md.bash
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
if test $# -lt 2 ; then
echo "Usage: $0 LEXC LANGUAGE"
echo
echo Create a markdown page from apertium-style lexc dictionary
echo Designed for github-pages but works with anything
exit 1
fi
# $1 be like foo/apertium-foo/apertium-foo.foo.lexc
PACKAGE=$(basename "$1" | sed -e 's/\..*//')
APELANG=$2
echo "# $PACKAGE: $APELANG dictionary"
echo
echo "This is an automatically generated visualisation "
echo "of an apertium dictionary, based on $(basename "$1")"
echo "*Note that due to the special nature of the lexc format, there can be"
echo "some inaccuracies and non-words in the list.*"
echo
echo "## Alphabets"
echo
echo '| *Symbol* | Comment |'
echo '|:---------|:--------|'
gawk '/Multichar_Symbols/,/LEXICON/ {print;}' "$1" |\
grep -E -v '^!.*' |\
grep -E -v '^$' |\
grep -F -v LEXICON |\
grep -F -v Multichar_Symbols |\
sed -e 's/ */\n/' |\
tr -s '\n' |
sed -e 's/%</`</' -e 's/%>/>`/' |\
sed -e 's/^/| /' -e 's/$/ |/'
echo
echo "## Dictionary"
echo
DICTEMP=$(mktemp -t apevis.XXXXXXXXXX )
gawk '/^LEXICON [A-Z][A-Z][^_]*$/,/^LEXICON [A-Z]*_/ {print;}' "$1" |\
grep -F -v LEXICON |\
grep -F -v '^!.*' |\
grep -E -v '^$' |\
grep -F : |\
sort |\
cut -d: -f 1 |\
tr '%' ' ' |\
tr '<>' '()' |\
sed -e 's/ )/)/' |\
sed -e 's/^/| /' -e 's/$/ |/' > "${DICTEMP}"
ALPHABET=$(sed -e 's/^..\(.\).*/\1/' < "${DICTEMP}" |\
tr '[:upper:]' '[:lower:]' |\
sort | uniq | grep -E '[[:alpha:]]' )
for c in $ALPHABET ; do
printf " [%s %s](#%s) |" "$c" "$(echo "$c" | tr '[:lower:]' '[:upper:]')" "$c"
done
echo
for c in $ALPHABET ; do
echo "### $c"
echo
echo "| *word* |"
echo "|:-------|"
grep "^| $c" < "${DICTEMP}"
grep "^| $(echo "$c" | tr '[:lower:]' '[:upper:]') " < "${DICTEMP}"
echo
done
echo
echo "-----------------"
echo "<small>Generated with [Flammie’s "
echo "ApeVis](https://github.com/flammie/apevis-xslt) lexc2md 0.1</small>"