-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Dictionary files and load them only as needed (#2484)
* Add script to fetch dict files and convert to wordlists * Add script for dictionary splitting * Add split .dic.js files * Add a dictionaryLoader class to handle the lazy loading of the dictionary parts * Use NFKD unicode normalization to get consistent splitting and lookup
- Loading branch information
1 parent
594b5b6
commit 136bb89
Showing
213 changed files
with
1,078,412 additions
and
288,208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#!/bin/bash | ||
|
||
###################################################### | ||
# Script to fetch dictionary files from | ||
# cgit.freedesktop.org/libreoffice/dictionaries/tree/ | ||
# and convert them into wordlists | ||
###################################################### | ||
|
||
set -e | ||
|
||
usage() { | ||
cat <<USAGE | ||
Usage: $0 [options] | ||
Fetch dictionary files for specified language and convert to a wordlist | ||
Options: | ||
-h, --help: | ||
print this message | ||
-l, --lang: | ||
(required) language to generate wordlist for | ||
options: ar, en, es, fr, hi, pt, ru, sw | ||
-d, --dry-run: | ||
print commands instead of executing them | ||
-v, --verbose: | ||
print each line of code before it is executed | ||
Caveats: | ||
This script assumes: | ||
* internet access | ||
* scripts.wordlist defined in package.json | ||
* hunspell-reader installed with npm | ||
If you run this script many times in rapid succession, | ||
your dictionary download may be throttled by the source | ||
USAGE | ||
} | ||
|
||
if [[ $# -eq 0 ]] ; then | ||
usage | ||
exit 0 | ||
fi | ||
|
||
DRYRUN=0 | ||
LANG= | ||
while [[ $# -gt 0 ]] ; do | ||
arg="$1" | ||
shift | ||
|
||
case ${arg} in | ||
-h|--help) | ||
usage | ||
exit 0 | ||
;; | ||
-l|--lang) | ||
LANG=$1 | ||
shift | ||
if [[ "${LANG}" =~ [^a-z] ]]; then | ||
echo "The -l/--lang argument must be lowercase alphabetic" | ||
exit 1 | ||
fi | ||
;; | ||
-d|--dry-run) | ||
DRYRUN=1 | ||
;; | ||
-v|--verbose) | ||
set -x | ||
;; | ||
*) | ||
echo "Unrecognized argument: ${arg}" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
SRC=https://cgit.freedesktop.org/libreoffice/dictionaries/plain/ | ||
case ${LANG} in | ||
ar) | ||
# URL=${SRC}ar/ar | ||
echo "The Arabic LibreOffice dictionary generates a 1.5 GB wordlist." | ||
echo "Manually download the wordlist from https://sourceforge.net/projects/arabic-wordlist/ instead" | ||
echo "and save it to src/resources/dictionaries/ar.txt for use with the split_dictionary.py script." | ||
exit 1 | ||
;; | ||
en) | ||
URL=${SRC}en/en_US | ||
;; | ||
es) | ||
URL=${SRC}es/es | ||
;; | ||
fr) | ||
URL=${SRC}fr_FR/fr | ||
;; | ||
hi) | ||
URL=${SRC}hi_IN/hi_IN | ||
;; | ||
pt) | ||
URL=${SRC}pt_BR/pt_BR | ||
;; | ||
ru) | ||
URL=${SRC}ru_RU/ru_RU | ||
;; | ||
sw) | ||
URL=${SRC}sw_TZ/sw_TZ | ||
;; | ||
*) | ||
echo "Unavailable language: ${LANG}" | ||
echo "Options: ar, en, es, fr, hi, pt, ru, sw" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
DIR=src/resources/dictionaries/ | ||
|
||
echo "** Fetching .aff file **" | ||
AFF=${DIR}${LANG}.aff | ||
cmd="curl -o ${AFF} ${URL}.aff" | ||
if [[ $DRYRUN -eq 1 ]] ; then | ||
echo "$cmd" | ||
else | ||
$cmd | ||
fi | ||
|
||
echo "** Fetching .dic file **" | ||
DIC=${DIR}${LANG}.dic | ||
cmd="curl -o ${DIC} ${URL}.dic" | ||
if [[ $DRYRUN -eq 1 ]] ; then | ||
echo "$cmd" | ||
else | ||
$cmd | ||
fi | ||
|
||
echo "** Converting to .txt wordlist **" | ||
TXT=${DIR}${LANG}.txt | ||
cmd="npm run wordlist -- ${DIC} -po ${TXT}" | ||
if [[ $DRYRUN -eq 1 ]] ; then | ||
echo "$cmd" | ||
else | ||
$cmd | ||
fi | ||
echo "** Wordlist saved to ${TXT} **" | ||
|
||
if [[ $DRYRUN -eq 1 ]] ; then | ||
echo "rm $AFF" | ||
echo "rm $DIC" | ||
else | ||
rm $AFF | ||
rm $DIC | ||
fi | ||
echo "** Deleted .aff and .dic files **" |
Oops, something went wrong.