-
Notifications
You must be signed in to change notification settings - Fork 0
Issue #8, convert hunspell output to spellchecker JSON format #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
7833457
a197b6e
ccada06
d225ac5
d1a31dd
768d0e2
2429ed8
f3f1597
1a2ee88
039864a
54a60d2
81adc92
77b1f9f
893fca6
8c0e6fd
9e4af1a
01d8e7a
9e79d4d
eb1d37e
d8aaff2
9ae2d84
a7e2db5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ### huntojson.sh | ||
| Convert hunspell output to JSON for spellchecker. | ||
|
|
||
| Launch hunspell on input file, convert output to spellchecker JSON format and write to standard output. | ||
| Usage: `./huntojson.sh [options...] [file]` | ||
| Options: | ||
| `-h` display this help and exit | ||
| `-d dict` use custom dictionaries | ||
|
|
||
| Example: | ||
| ```bash | ||
| ./huntojson.sh demo.tex # launch hunspell on 'demo.tex' | ||
| ./huntojson.sh -d ru_RU ru_demo.tex # use russian dictionary | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/bin/bash | ||
|
|
||
| # usage info | ||
| show_help() { | ||
| cat << EOF | ||
| Usage: ${0##*/} [options...] [file] | ||
| Launch hunspell on file, convert output to JSON format | ||
| and write to standard output. | ||
|
|
||
| -h display this help and exit | ||
| -d dict use custom dictionaries | ||
|
|
||
| Example: ${0##*/} demo.tex # launch hunspell on 'demo.tex' | ||
| ${0##*/} -d ru_RU ru_demo.tex # use russian dictionary | ||
| EOF | ||
| } | ||
|
|
||
| DICT= | ||
| OPTIND=1 | ||
|
|
||
| # command line arguments processing | ||
| while getopts ":hd:" opt; do | ||
| case "$opt" in | ||
| h) | ||
| show_help | ||
| exit 0 | ||
| ;; | ||
| d) | ||
| DICT="-p $OPTARG" | ||
| ;; | ||
| ?) | ||
| echo -e "Invalid option: -$OPTARG\n" >&2 | ||
| show_help >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| shift $((OPTIND-1)) | ||
|
|
||
| if [ "$#" != "1" ] | ||
| then | ||
| echo -e "Missing input file\n" >&2 | ||
| show_help >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| INFILE=$1 | ||
|
|
||
| JSON=$( | ||
| cat $INFILE | | ||
| hunspell -a -t | | ||
| grep "^&.*" | | ||
|
||
| awk $DICT ' | ||
| BEGIN { print "{" } | ||
| { | ||
| print "\t\""$2"\": [" ; | ||
|
||
|
|
||
| split($0, split_string, ": "); | ||
| options_number=split(split_string[2], options, ", "); | ||
|
|
||
| for (i = 1; i <= options_number; i++) | ||
| {print "\t\t\""options[i]"\","} | ||
|
||
|
|
||
| print "\t]," } | ||
| END { print "}" } | ||
| ' | ||
| ) | ||
|
|
||
| echo $JSON | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enquote
$INFILE, otherwise you're going have troubles with spaces in the path