2
嗨我從來沒有處理過正則表達式,我試圖用Python和NLTK預處理一些原始文本。 當我試圖來標記使用文檔:蟒蛇正則表達式nltk網站提取
tokens = nltk.regexp_tokenize(corpus, sentence_re)
sentence_re = r'''(?x) # set flag to allow verbose regexps
([A-Z])(\.[A-Z])+\.? # abbreviations, e.g. U.S.A.
| \w+(-\w+)* # words with optional internal hyphens
| \$?\d+(\.\d+)?%? # currency and percentages, e.g. $12.40, 82%
| \#?\w+|\@?\w+ # hashtags and @ signs
| \.\.\. # ellipsis
| [][.,;"'?()-_`] # these are separate tokens
| ?:http://|www.)[^"\' ]+ # websites
'''
其不能夠把所有的網站爲一個單一的令牌:
print toks[:50]
['on', '#Seamonkey', '(', 'SM', ')', '-', 'I', 'had', 'a', 'short', 'chirp', 'exchange', 'with', '@angie1234p', 'at', 'the', '18thDec', ';', 'btw', 'SM', 'is', 'faster', 'has', 'also', 'an', 'agile', '...', '1', '/', '2', "'", '...', 'user', 'community', '-', 'http', ':', '/', '/', 'bit', '.', 'ly', '/', 'XnF5', '+', 'ICR', 'http', ':', '/', '/']
任何幫助是極大的appreicated。非常感謝!
-Florie
自然語言解析是一個開始學習正則表達式的好地方。 –