LEMMA 模式找不到模式

问题描述

我对这个论坛有点陌生,请原谅任何不正确的程序!

我正在使用 spaCy 并且正在寻找某些短语的词形还原,因为它们可能以不同的格式出现在文本中。对于测试,我尝试使用 Matcher 和以下代码

import spacy
from spacy.matcher import Matcher
import string
import pandas as pd

nlp = spacy.load('en_core_web_sm')
matcher = Matcher(nlp.vocab)

# Leaving it in for others who may experience the situation. But,# in pattern4,remove the second patter,{'LOWER': 'discontinue'}
# this will make the matcher use the LemmA properly.
pattern4 = [{'LemmA':'discontinue'},{'LOWER': 'discontinue'}]
pattern5 = [{'LOWER': 'solar'},{'LOWER': 'power'}]

# Removing the matcher won't work the first time. It's just for multi runs.
matcher.remove('Test')
matcher.add('Test',[pattern4,pattern5])
doc2 = nlp('Are you trying to say that solar power is discontinued?')
found_matches1 = matcher(doc2)
print(found_matches1)

当我打印出 doc2 中的 .lemma_ 时,它显示不连续是停止的引理,我认为这会使代码工作:

for token in doc2:
    print(token.lemma_)

结果或打印引理_: 是 你 尝试 到 说 那 太阳的 力量 是 中止 ?

谢谢,吉姆

我想通了。当我删除 pattern4 {'LOWER': 'discontinue'} 的第二部分时,LemmA 起作用了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)