
单词表格可以准确地生成英语单词的所有可能形式。它可以结合动词。它可以将语音的不同部分连接到名词中,形容词,形容词副词,名词对动词等。它可以使单数名词相元。它可以在一个函数中完成所有操作。享受!
一些非常及时的例子:p
> >> from word_forms . word_forms import get_word_forms
> >> get_word_forms ( "president" )
> >> { 'n' : { 'presidents' , 'presidentships' , 'presidencies' , 'presidentship' , 'president' , 'presidency' },
'a' : { 'presidential' },
'v' : { 'preside' , 'presided' , 'presiding' , 'presides' },
'r' : { 'presidentially' }}
> >> get_word_forms ( "elect" )
> >> { 'n' : { 'elects' , 'electives' , 'electors' , 'elect' , 'eligibilities' , 'electorates' , 'eligibility' , 'elector' , 'election' , 'elections' , 'electorate' , 'elective' },
'a' : { 'eligible' , 'electoral' , 'elective' , 'elect' },
'v' : { 'electing' , 'elects' , 'elected' , 'elect' },
'r' : set ()}
> >> get_word_forms ( "politician" )
> >> { 'n' : { 'politician' , 'politics' , 'politicians' },
'a' : { 'political' },
'v' : set (),
'r' : { 'politically' }}
> >> get_word_forms ( "am" )
> >> { 'n' : { 'being' , 'beings' },
'a' : set (),
'v' : { 'was' , 'be' , "weren't" , 'am' , "wasn't" , "aren't" , 'being' , 'were' , 'is' , "isn't" , 'been' , 'are' , 'am not' },
'r' : set ()}
> >> get_word_forms ( "ran" )
> >> { 'n' : { 'run' , 'runniness' , 'runner' , 'runninesses' , 'running' , 'runners' , 'runnings' , 'runs' },
'a' : { 'running' , 'runny' },
'v' : { 'running' , 'run' , 'ran' , 'runs' },
'r' : set ()}
> >> get_word_forms ( 'continent' , 0.8 ) # with configurable similarity threshold
> >> { 'n' : { 'continents' , 'continency' , 'continences' , 'continent' , 'continencies' , 'continence' },
'a' : { 'continental' , 'continent' },
'v' : set (),
'r' : set ()}如您所见,输出是一个带有四个键的字典。 “ r”代表副词,a“用于形容词”,名词和动词的“ v”。不要问我为什么“ R”代表副词。这就是WordNet使用的,所以这就是为什么我也使用它:-)
可以随时通过键入以下内容获得帮助:
> >> help ( get_word_forms )在自然语言处理和搜索中,通常需要将诸如“ run”和“ ran”,“ love”和“ love”,“可爱”或“政治家”和“政治”等单词视为相同的词。这通常是通过将每个单词简化为基本单词然后比较基本单词的算法来完成的。该过程称为词干。例如,搬运工将“爱”和“可爱”都简化为基本单词“爱”。
Stemmers有几个缺点。首先,Stemmer产生的基本单词并不总是有效的英语单词。例如,搬运工将“操作”一词简化为“操作”。其次,茎的人具有很高的假负率。例如,“ run”将减少为“运行”,“ ran”降低为“ ran”。发生这种情况是因为Stemmers使用一组理性规则来查找基本单词,而且众所周知,英语并不总是很合理地行事。
柠檬剂比Stemmater更准确,因为它们产生了字典中存在的碱基形式(也称为引理)。因此,简化的单词始终是一个有效的英语单词。但是,柠檬剂也有虚假的负面因素,因为它们不太擅长在演讲的不同部分之间连接单词。 NLTK随附的WordNet lemmatizer在几乎所有此类示例中都失败了。 “操作”将减少为“操作”,而“操作”降低为“操作”。
单词表格试图通过找到给定的英语单词的所有可能形式来解决此问题。它可以执行动词共轭,将名词形式连接到动词形式,形容词形式,副词形式,构成单数形式等。
我们还基于word_forms提供了非常简单的Lemmatizer。这是如何使用它。
> >> from word_forms . lemmatizer import lemmatize
> >> lemmatize ( "operations" )
'operant'
> >> lemmatize ( "operate" )
'operant'享受!
在Python 3上测试
使用pip :
pip install -U word_forms
或者,您可以从源头安装它:
git clone https://github.com/gutfeeling/word_forms.git
pip或setup.py安装它 pip install -e word_forms
% or
cd word_forms
python setup.py install
嗨,我是Dibya,我维持了这个存储库。我很想听听您的来信。请随时通过[email protected]与我联系。
单词形式并不完美。特别是,可以改善几个方面。
如果您喜欢此软件包,请随时做出贡献。您最欢迎您的拉力请求。