-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Spanish dictionary, use latinize
- Loading branch information
1 parent
4e13ee7
commit 8adccbb
Showing
4 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import { Locale } from '@scrabble-solver/types'; | ||
import latinize from 'latinize'; | ||
|
||
import { getTxtWordList } from './lib'; | ||
|
||
const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/fise-2/master/fise-2.txt'; | ||
const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/spanish/fise-2.txt'; | ||
|
||
const getEsEsWordList = async (): Promise<string[]> => { | ||
const words = await getTxtWordList(FILE_URL, Locale.ES_ES); | ||
return words.map(normalizeWord); | ||
}; | ||
|
||
const normalizeWord = (word: string): string => { | ||
// normalization from https://stackoverflow.com/a/37511463 | ||
return word.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); | ||
return words.map(latinize); | ||
}; | ||
|
||
export default getEsEsWordList; |
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 |
---|---|---|
@@ -1,23 +1,13 @@ | ||
import fs from 'fs'; | ||
import { Locale } from '@scrabble-solver/types'; | ||
import latinize from 'latinize'; | ||
|
||
import { downloadFile, extractWords, getTempFilepath, unzip } from './lib'; | ||
import { getTxtWordList } from './lib'; | ||
|
||
const FILE_URL = 'https://dexonline.ro/static/download/scrabble/loc-flexiuni-5.0.zip'; | ||
const FILE_TO_EXTRACT_FROM_ZIP = 'loc-flexiuni-5.0.txt'; | ||
const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/romanian/loc-5.0.txt'; | ||
|
||
const getRoRoWordList = async (): Promise<string[]> => { | ||
const tempFilepath = getTempFilepath(); | ||
const zipTempFilename = await downloadFile(FILE_URL); | ||
await unzip(zipTempFilename, FILE_TO_EXTRACT_FROM_ZIP, tempFilepath); | ||
fs.unlinkSync(zipTempFilename); | ||
const file = fs.readFileSync(tempFilepath, 'utf-8'); | ||
fs.unlinkSync(tempFilepath); | ||
const words = extractWords(replaceDiacritics(file.toLocaleString()), 'ro-RO'); | ||
return words; | ||
}; | ||
|
||
const replaceDiacritics = (file: string): string => { | ||
return file.replaceAll('ă', 'a').replaceAll('â', 'a').replaceAll('î', 'i').replaceAll('ș', 's').replaceAll('ț', 't'); | ||
const words = await getTxtWordList(FILE_URL, Locale.RO_RO); | ||
return words.map(latinize); | ||
}; | ||
|
||
export default getRoRoWordList; |