ドイツ語text
のトークンに一致する正規表現を作成しました。これはタイプstring
です。Python 2.7 Regex Tokenizer実装が動作しない
私の正規表現は、regex101.comを使用して期待どおりに動作しています。ここ例文と私の正規表現のリンクは次のとおりです。My regex + example on regex101.com
だから私はこのようなpython 2.7
でそれを実装:
GERMAN_TOKENIZER = r'''(?x) # set flag to allow verbose regex
([A-ZÄÖÜ]\.)+ # abbrevations including ÄÖÜ
|\d+([.,]\d+)?([€$%])? # numbers, allowing commas as seperators and € as currency
|[\wäöü]+ # matches normal words
|\.\.\. # ellipsis
|[][.,;\"'?():-_'!] # matches special characters including !
'''
def tokenize_german_text(text):
'''
Takes a text of type string and
tokenizes the text
'''
matchObject = re.findall(GERMAN_TOKENIZER, text)
pass
tokenize_german_text(u'Das ist ein Deutscher Text! Er enthält auch Währungen, 10€')
結果:
を私はこれをデバッグした時、私はあることを発見しましたmatchObject
は空文字の11個のエントリを含むリストに過ぎません。なぜ期待どおりに動作しないのですか?これをどうすれば解決できますか?
追加します注意: 're.UNICODE'オプションで正規表現をコンパイルして、' \ w'がASCII以外の文字とマッチするようにすることができます。結局、ウムラウト以外のアクセントを含むドイツ語があります今はそれらが見当たりません。 –