【发布时间】:2021-03-24 08:52:51
【问题描述】:
我有这段代码可以使用 spacy 提取名词-形容词对,但是这段代码非常适合英语而不是法语,因为在法语中我们很难提取一对名词-形容词:
1- la voiture est belle,grande et jolie。 (当我们有很多形容词时,CCONJ = "et") 2- le tableau qui est juste en dessous est grand et beau。 (所以我们在这里有一个共指,我们应该将 grand et beau 与“tableau”相关联
我知道 spacy 中的dependencymatcher 是健壮的,但在我的情况下,有时我的文本没有被清理,因为它是关于人们的意见......所以我们需要手动完成......
在输出中我们应该有这样的东西: {"voiture":["belle","grande","jolie"], "tableau":["beau","grand"]}
import spacy
nlp = spacy.load("fr_core_news_sm")
doc = nlp('la voiture est belle et jolie. le tableau qui est juste en dessous est grand ')
noun_adj_pairs = {}
for chunk in doc.noun_chunks:
adj = []
noun = ""
for tok in chunk:
if tok.pos_ == "NOUN":
noun = tok.text
if tok.pos_ == "ADJ" or tok.pos_ == "CCONJ":
adj.append(tok.text)
if noun:
noun_adj_pairs.update({noun:" ".join(adj)})
【问题讨论】:
标签: python python-3.x nlp spacy