spacy3.0 matcher.add 方法报错:ValueError: [E178] Each pattern should be a list of dicts, but got:
- 报错展示
- 任务背景
- 问题原因
- 问题解决
报错展示
ValueError: [E178] Each pattern should be a list of dicts, but got: {‘TEXT’: ‘iPhone’}. Maybe you accidentally passed a single pattern to Matcher.add instead of a list of patterns? If you only want to add one pattern, make sure to wrap it in a list. For example: `matcher.add(‘IPHONE_PATTERN’, [pattern])
任务背景
使用 spacy.match.Mather().add() 方法发生报错
问题原因
问题解决
在原来的模式pattern列表上,再添加一个中括号就行啦!!
原来的是:
# 给matcher加入模板
pattern = [{
"TEXT": "iPhone"}, {
"TEXT": "X"}]
matcher.add("IPHONE_PATTERN", pattern)
修改为:
# 给matcher加入模板
pattern = [[{
"TEXT": "iPhone"}, {
"TEXT": "X"}]]
matcher.add("IPHONE_PATTERN", pattern)