Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Python 如何将正确的spacy正则表达式模式添加到jsonl文件_Python_Regex_Spacy - Fatal编程技术网

Python 如何将正确的spacy正则表达式模式添加到jsonl文件

Python 如何将正确的spacy正则表达式模式添加到jsonl文件,python,regex,spacy,Python,Regex,Spacy,我有一个正在工作的正则表达式模式,我想在标记名称身份识别和使用spacy查找它时使用它。 我将其存储在.jsonl文件中,我使用.from_disk方法读取该文件 下面是python中的一个工作示例: import re pattern = '(RAS?[\S]+)' # I want to find all strings starting with RAS and ending right before space or similar character words = ['RAS', '

我有一个正在工作的正则表达式模式,我想在标记名称身份识别和使用spacy查找它时使用它。 我将其存储在
.jsonl
文件中,我使用
.from_disk
方法读取该文件

下面是python中的一个工作示例:

import re
pattern = '(RAS?[\S]+)' # I want to find all strings starting with RAS and ending right before space or similar character
words = ['RAS', 'RAS', 'su RAS s:', 'SuRASs:', 'suRASs dfas:', 'raSan']
[re.findall(pattern, x) for x in words]

Out[7]: [['RAS'], ['RAS'], ['RAS'], ['RASs:'], ['RASs'], []]
但是,当我尝试在jsonl文件中使用正则表达式模式并将其添加到NamedEntityRecognizer时,我得到一个错误:

ValueError:第1行的JSON无效:{“label”:“REFERENCE_TLC”,“pattern”:[{“TEXT”:{“REGEX”:(RAS?[\S]+)“}}}}}

你知道spacy在使用正则表达式时是否有一些限制吗

因为当我使用这个regex
(RAS)
,它可以工作,但找不到我需要的案例


下面是他们文档中的官方
spacy
regex示例,但这对我没有帮助:

我自己终于找到了解决方案,但如果它发生在其他人身上,我会把这个问题留在这里

这种情况下正确的正则表达式应该是
“RAS?+”
,它匹配
RAS
之后的所有内容。我在仔细阅读spacy文档时发现的原因是:

从本节开始:当使用正则表达式操作符时,请记住它只对单个令牌进行操作,而不是对整个文本进行操作。您提供的每个表达式都将在标记上匹配


因为我的文本已经标记化了,所以在下一个空格或非空格字符结束之前不存在这样的事情。我已经有了没有空格的代币。。。愚蠢的我没有注意到这一点,当它被写为重要提示:facepalm:

你应该在回答部分回答自己的问题,而不是在这里编辑它。谢谢你的建议,我现在将答案与原始问题分开。