Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PoS标记与特定文本与`testacy.extract.PoS_regex_matches(…)匹配`_Regex_Python 3.x_Nlp_Spacy_Pos Tagger - Fatal编程技术网

将PoS标记与特定文本与`testacy.extract.PoS_regex_matches(…)匹配`

将PoS标记与特定文本与`testacy.extract.PoS_regex_matches(…)匹配`,regex,python-3.x,nlp,spacy,pos-tagger,Regex,Python 3.x,Nlp,Spacy,Pos Tagger,我正在使用textacy的pos\u regex\u matches方法来查找句子中的某些文本块 例如,假设我有文本:Huey、Dewey和Louie是三连体卡通人物。,我想检测Huey、Dewey和Louie是一个枚举 为此,我使用以下代码(在testacy 0.3.4上,编写本文时提供的版本): 但是,如果我有以下内容: sentence = 'Donald Duck - Disney' words.extend(keyword_map[w]) 然后,-(破折号)被识别为,整个句子被识别

我正在使用
textacy
pos\u regex\u matches
方法来查找句子中的某些文本块

例如,假设我有文本:
Huey、Dewey和Louie是三连体卡通人物。
,我想检测
Huey、Dewey和Louie
是一个枚举

为此,我使用以下代码(在
testacy 0.3.4
上,编写本文时提供的版本):

但是,如果我有以下内容:

sentence = 'Donald Duck - Disney'
words.extend(keyword_map[w])
然后,
-
(破折号)被识别为
,整个句子被识别为一个列表——它不是

是否有办法指定只有
是否对列表有效

我已经找了一些关于这个正则表达式语言的参考资料来匹配没有运气的PoS标签,有人能帮忙吗?提前谢谢


PS:我试图用注释中建议的
替换
,但没有效果…

很短,不可能:请参阅

然而,合并请求包含页面中描述的修改版本的代码,因此可以重新创建功能,尽管它的性能不如使用
SpaCy
Matcher
(请参阅和--尽管我不知道如何使用
Matcher
重新实现我的问题)

如果你想沿着这条车道走,你必须改变路线:

words.extend(map(lambda x: re.sub(r'\W', '', x), keyword_map[w]))
以下是:

sentence = 'Donald Duck - Disney'
words.extend(keyword_map[w])

否则,每个符号(如我的例子中的
)都将被剥离。

尝试用[,;]替换点