问题描述
我尝试嵌入此 python 代码
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
for ent in doc.ents:
print(ent.text,ent.label_)
在.NET中如下:
using (Py.GIL())
{
dynamic spacy = Py.Import("spacy");
dynamic nlp = spacy.load("en_core_web_sm");
dynamic doc = nlp("Apple is looking at buying U.K. startup for $1 billion");
dynamic ent = doc.ents; // Here I get `ent.text`
//dynamic label = ent.label_; // Here I expect to get `ent.label_`
return ents;
}
现在我还需要获取 ent.label_。 我通过添加这一行来尝试:
dynamic label = ents.label_;
但我收到此错误:"Python.Runtime.PythonException: "AttributeError : 'tuple' object has no attribute 'label_'"
我希望得到以下输出:
Apple ORG,英国 GPE,10 亿美元
如何找到并输出ent.label_
?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)