NLTK文档和示例的流行数量主要用于词典化和词干化,但在规范化的问题上非常稀少:
请指点我在NLTK挖掘的地方.欢迎任何用于上述目的的NLTK等同物(JAVA或任何其他).谢谢.
UPD.我已经编写了一个文本规范化的python库,用于文本到语音的目的https://github.com/soshial/text-normalization.它也可能适合你.
Max*_* Li 17
同样在NLTK规范中,许多(子)任务都是使用纯python 方法解决的.
a)将所有字母转换为大写或小写
text='aiUOd'
print text.lower()
>> 'aiuod'
print text.upper()
>> 'AIUOD'
Run Code Online (Sandbox Code Playgroud)
b)删除标点符号
text='She? Hm, why not!'
puncts='.?!'
for sym in puncts:
text= text.replace(sym,' ')
print text
>> 'She Hm why not '
Run Code Online (Sandbox Code Playgroud)
c)将数字转换为单词
在这里,编写一些内容并不是那么简单,但是如果你谷歌的话,有很多已有的解决方案.代码片段,库等
d)去除重音符号和其他变音符号
仰望点二),只需创建一个变音符号作为列表puncts
e)扩展缩写
创建一个包含缩写的字典:
text='USA and GB are ...'
abbrevs={'USA':'United States','GB':'Great Britain'}
for abbrev in abbrevs:
text= text.replace(abbrev,abbrevs[abbrev])
print text
>> 'United States and Great Britain are ...'
Run Code Online (Sandbox Code Playgroud)
f)删除停用词或"太常见"的词
创建一个包含停用词的列表:
text='Mary had a little lamb'
temp_corpus=text.split(' ')
stops=['a','the','had']
corpus=[token for token in temp_corpus if token not in stops]
print corpus
>> ['Mary', 'little', 'lamb']
Run Code Online (Sandbox Code Playgroud)
g)文本规范化(肿瘤=肿瘤,它是=它)
对于肿瘤 - >肿瘤使用正则表达.
最后,但并非最不重要的是,请注意上面的所有示例通常都需要对真正的文本进行校准,我将它们作为方向去编写.