This repository was archived by the owner on Dec 19, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(irregularWords): add irregular words files and handlers
- Loading branch information
1 parent
8d46405
commit eea3614
Showing
12 changed files
with
5,568 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// tslint:disable:no-any | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
const SPECIAL_LETTERS = ['K', 'P', 'N', 'R'] | ||
SPECIAL_LETTERS.map((letter) => { | ||
;(IrregularWords as any)[`BEGINS_WITH_${letter}`] = IrregularWords.loadWords( | ||
`${letter.toLowerCase()}.txt`, | ||
true | ||
) | ||
}) | ||
|
||
// export default interface IrregularWords { | ||
// [key: string]: any; | ||
// } | ||
|
||
export default class IrregularWords { | ||
static ON_PREFIX_CHARACTERS = { | ||
meng: (IrregularWords as any).BEGINS_WITH_K, | ||
peng: (IrregularWords as any).BEGINS_WITH_K, | ||
mem: (IrregularWords as any).BEGINS_WITH_P, | ||
pem: (IrregularWords as any).BEGINS_WITH_P, | ||
} | ||
|
||
static ENDS_WITH_I = IrregularWords.loadWords('akhiran-i.txt') | ||
|
||
static ENDS_WITH_COMMON_CHARACTERS = { | ||
kah: IrregularWords.loadWords('kah.txt'), | ||
lah: IrregularWords.loadWords('lah.txt'), | ||
pun: IrregularWords.loadWords('pun.txt'), | ||
ku: IrregularWords.loadWords('ku.txt'), | ||
mu: IrregularWords.loadWords('mu.txt'), | ||
nya: IrregularWords.loadWords('nya.txt'), | ||
} | ||
|
||
static ENDS_WITH_SUFFIX_CHARACTERS = IrregularWords.ENDS_WITH_I.unshift( | ||
'majikan' | ||
) | ||
|
||
static loadWords(filename: string, chopped = false) { | ||
const fd = fs.openSync(IrregularWords.absolutePath(filename), 'r') | ||
|
||
let content = '' | ||
|
||
const buffer = Buffer.alloc(10) | ||
|
||
buffer.fill(0) | ||
|
||
let readCount = fs.readSync(fd, buffer, 0, 10, null) | ||
|
||
while (readCount > 0) { | ||
// console.log("Read " + readCount + " bytes."); | ||
|
||
content += buffer.toString().substr(0, readCount) | ||
|
||
readCount = fs.readSync(fd, buffer, 0, 10, null) | ||
} | ||
|
||
fs.closeSync(fd) | ||
|
||
let contents = content.split('\n') | ||
|
||
if (chopped) { | ||
contents = contents.map((word) => word.slice(1, word.length)) | ||
} | ||
|
||
return contents | ||
} | ||
|
||
static absolutePath(filename: string) { | ||
return path.join(__dirname, 'irregular-words', filename) | ||
} | ||
} | ||
|
||
// (IrregularWords as any).ON_PREFIX_CHARACTERS = { | ||
// meng: (IrregularWords as any).BEGINS_WITH_K, | ||
// peng: (IrregularWords as any).BEGINS_WITH_K, | ||
// mem: (IrregularWords as any).BEGINS_WITH_P, | ||
// pem: (IrregularWords as any).BEGINS_WITH_P | ||
// }; |
Oops, something went wrong.