diff --git a/build.gradle b/build.gradle index e259efb8..544c1ac9 100644 --- a/build.gradle +++ b/build.gradle @@ -314,8 +314,6 @@ android { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' - -// signingConfig android.signingConfigs.release } } buildFeatures { diff --git a/scripts/aosp2tt9.js b/scripts/aosp2tt9.js new file mode 100644 index 00000000..d448d70f --- /dev/null +++ b/scripts/aosp2tt9.js @@ -0,0 +1,78 @@ +const { basename } = require('path'); +const { createReadStream, existsSync } = require('fs'); +const { createInterface } = require('readline'); + + +function printHelp() { + console.log(`Usage ${basename(process.argv[1])} aosp-dictionary-file.txt [minimum-frequency] [--no-freq]`); + console.log('Converts an AOSP dictionary to TT9 compatible format. The second parameter must be an integer and allows for filtering words with frequency less than the given number. If "--no-freq" is set, only words without frequencies will be listed.'); + console.log('LOCALE could be any valid JS locale, for example: en, en-US, etc...'); +} + + + +function validateInput() { + if (process.argv.length < 3) { + printHelp(); + process.exit(1); + } + + if (!existsSync(process.argv[2])) { + console.error(`Failure! Could not find dictionary file "${process.argv[3]}."`); + process.exit(2); + } + + return { + fileName: process.argv[2], + minFrequency: Number.isNaN(Number.parseInt(process.argv[3])) ? 0 : Number.parseInt(process.argv[3]), + noFrequencies: process.argv[4] === '--no-freq' + }; +} + + +function printWords(wordList) { + if (Array.isArray(wordList)) { + wordList.forEach(w => console.log(w)); + } +} + + +async function convert({ fileName, minFrequency, noFrequencies }) { + words = []; + + let lineReader = createInterface({ input: createReadStream(fileName) }); + for await (const line of lineReader) { + let word = line + .replace(/^dictionary=main.+$/, '') + .replace(/^\s+/, '') + .replace(/^shortcut=.+/, '') + .replace(/^word=([^,]+),f=(\d+)($|,.+$)/, '$1\t$2'); + + if (minFrequency && word !== '') { + const parts = word.split('\t'); + if (!(parts.length > 1 && Number.parseInt(parts[1]) >= minFrequency)) { + word = ''; + } + } + + if (noFrequencies) { + const parts = word.split('\t'); + if (parts.length > 0) { + word = parts[0]; + } + } + + + if (word !== '') { + words.push(word); + } + } + + return words; +} + + +/** main **/ +convert(validateInput()) + .then(words => printWords(words)) + .catch(e => console.error(e)); \ No newline at end of file