0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ひらがな・カタカナ・漢字を別々に集計するテキスト統計ツールを作った

0
Posted at

作ったもの

Text Counthttps://sen.ltd/portfolio/text-count/

スクリーンショット

  • 文字数(空白あり/なし)、単語数、文数、段落数、行数
  • 読書時間(200 / 400 wpm)、朗読時間(150 wpm)
  • 日本語文字分類: ひらがな / カタカナ / 漢字 / ASCII / 数字 / その他
  • 単語頻度 TOP10
  • ユニーク単語数、平均単語長、平均文長
  • 文字頻度グラフ
  • SNS 文字数チェック(Twitter 280 / SMS 160 / Instagram 150 など)

vanilla JS、ゼロ依存、ビルド不要node --test で 73 ケース。

Unicode レンジで分類

if (code >= 0x3041 && code <= 0x309F) return 'hiragana';
if (code >= 0x30A0 && code <= 0x30FF) return 'katakana';
if (code >= 0x4E00 && code <= 0x9FFF) return 'kanji';

「200 文字(ひらがな 120・漢字 40・カタカナ 30・ASCII 10)」のように内訳が出るので、日本語の文体がわかる。

「単語」が定義しにくい日本語

英語は空白区切りで単語がわかる。日本語は区切りがない。真面目な分かち書きには MeCab / Kuromoji が必要 → クライアントサイドには重すぎ。

代案: CJK 文字 1 つ = 1 トークンとして簡易集計。正確ではないが、頻度分布の目安にはなる。

[...text].length で正しい文字数

"😀".length === 2(UTF-16 コード単位で数えるから)。[...text].length なら Unicode コードポイント単位で数える。Twitter は絵文字を 1 文字としてカウントするので、こちらが正解。

シリーズ

100+ 公開ポートフォリオ シリーズの #76 です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?