用 spacy 单数化名词短语
singularize noun phrases with spacy
我正在寻找一种使用 spacy
来单数化名词块的方法
S='There are multiple sentences that should include several parts and also make clear that studying Natural language Processing is not difficult '
nlp = spacy.load('en_core_web_sm')
doc = nlp(S)
[chunk.text for chunk in doc.noun_chunks]
# = ['an example sentence', 'several parts', 'Natural language Processing']
还可以得到名词块的"root":
[chunk.root.text for chunk in doc.noun_chunks]
# = ['sentences', 'parts', 'Processing']
我正在寻找一种方法来单一化这些块的根。
目标:单一化:['sentence'、'part'、'Processing']
有什么明显的方法吗?这是否总是取决于每个词根的词性?
谢谢
注意:
我发现了这个:https://www.geeksforgeeks.org/nlp-singularizing-plural-nouns-and-swapping-infinite-phrases/
但在我看来,这种方法会导致许多不同的方法,当然每种语言都不同。 (我在 EN、FR、DE 工作)
有!你可以在每个名词块中取中心词的词元。
[chunk.root.lemma_ for chunk in doc.noun_chunks]
Out[82]: ['sentence', 'part', 'processing']
要获得每个单词的基本形式,可以使用“.lemma_” 属性 of chunk or token 属性
我用的是Spacy版本2.x
import spacy
nlp = spacy.load('en_core_web_sm', disable=['parser', 'ner'])
doc = nlp('did displaying words')
print (" ".join([token.lemma_ for token in doc]))
和输出:
do display word
希望对您有所帮助:)
我正在寻找一种使用 spacy
来单数化名词块的方法S='There are multiple sentences that should include several parts and also make clear that studying Natural language Processing is not difficult '
nlp = spacy.load('en_core_web_sm')
doc = nlp(S)
[chunk.text for chunk in doc.noun_chunks]
# = ['an example sentence', 'several parts', 'Natural language Processing']
还可以得到名词块的"root":
[chunk.root.text for chunk in doc.noun_chunks]
# = ['sentences', 'parts', 'Processing']
我正在寻找一种方法来单一化这些块的根。
目标:单一化:['sentence'、'part'、'Processing']
有什么明显的方法吗?这是否总是取决于每个词根的词性?
谢谢
注意: 我发现了这个:https://www.geeksforgeeks.org/nlp-singularizing-plural-nouns-and-swapping-infinite-phrases/ 但在我看来,这种方法会导致许多不同的方法,当然每种语言都不同。 (我在 EN、FR、DE 工作)
有!你可以在每个名词块中取中心词的词元。
[chunk.root.lemma_ for chunk in doc.noun_chunks]
Out[82]: ['sentence', 'part', 'processing']
要获得每个单词的基本形式,可以使用“.lemma_” 属性 of chunk or token 属性
我用的是Spacy版本2.x
import spacy
nlp = spacy.load('en_core_web_sm', disable=['parser', 'ner'])
doc = nlp('did displaying words')
print (" ".join([token.lemma_ for token in doc]))
和输出:
do display word
希望对您有所帮助:)