テキストマイニングなどを行うためには文書、文、単語などの文字列の正規化が重要です。 単語の大文字小文字の統一、半角全角の統一などをする必要があります。 文字列の正規化のために利用しているpythonコードを以下に書いておきます。 今後増える可能性もあります。 実行環境 Ubuntu 10.04 64ビット python 2.6.5 unicode型に変換する def unicode_ignore_invalid_char(text): if isinstance(text, str): return text.decode('utf-8', 'ignore') return text 変換不能な文字列を無視してstr型からunicode型に変換する。 str型に変換する def str_ignore_invalid_char(text): if isinstance(text, unico
