Skip to content

Instantly share code, notes, and snippets.

@butchi
Last active January 23, 2020 16:57
Show Gist options
  • Save butchi/5acbd64eb59b512eb4c2d8e065f28d5f to your computer and use it in GitHub Desktop.
Save butchi/5acbd64eb59b512eb4c2d8e065f28d5f to your computer and use it in GitHub Desktop.
const MeCab = new require('mecab-async')
const mecab = new MeCab();
mecab.parse(process.argv[2], (err, result) => {
if (err) throw err;
const txt = result.map(item => {
if (false) {
} else if (['接尾'].includes(item[2])) {
return item[0];
} else if (['人名', '組織', '地域'].includes(item[3])) {
return `[${item[2]}]`;
} else if (['固有名詞', '代名詞', '数'].includes(item[2])) {
return `[${item[2]}]`;
} else if (['名詞', '動詞', '形容詞', '副詞', '感動詞'].includes(item[1])) {
return `[${item[1]}]`;
} else {
return item[0];
}
}).join('')
console.log(txt);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment