mirror of
https://github.com/syuilo/ai.git
synced 2024-11-14 17:57:59 +00:00
18 lines
478 B
TypeScript
18 lines
478 B
TypeScript
|
import { hiraganaToKatagana, hankakuToZenkaku } from './japanese';
|
|||
|
|
|||
|
export default function(text: string, words: string[]): boolean {
|
|||
|
if (text == null) return false;
|
|||
|
|
|||
|
text = cleanup(hankakuToZenkaku(hiraganaToKatagana(text)));
|
|||
|
words = words.map(word => hiraganaToKatagana(word));
|
|||
|
|
|||
|
return words.some(word => text == word);
|
|||
|
}
|
|||
|
|
|||
|
function cleanup(text: string): string {
|
|||
|
return text.trim()
|
|||
|
.replace(/[!!]+$/, '')
|
|||
|
.replace(/。$/, '')
|
|||
|
.replace(/(です|デス)$/, '');
|
|||
|
}
|