首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spacy.strings.StringStore.__getitem__ TypeError中的第126行:'tuple‘和'int’的实例之间不支持“<”

spacy.strings.StringStore.__getitem__ TypeError中的第126行:'tuple‘和'int’的实例之间不支持“<”
EN

Stack Overflow用户
提问于 2022-02-14 15:54:41
回答 1查看 53关注 0票数 0

在使用此代码时,我得到了此错误,该代码使用spacy搜索文本文件中的特定术语,然后将这些项添加到熊猫数据文件中。

代码语言:javascript
复制
for ind,match in enumerate(matches):
    for sent in sents:
        if matches[ind][1] < sent.end:
            typematches = findmatch(sent,['Greenfield','greenfield', 'brownfield','Brownfield', 'de-bottlenecking', 'De-bottlenecking'],'Type')
            valuematches = findmatch(sent,['Crore', 'Cr','crore', 'cr'],'Value')
            datematches = findmatch(sent,['2020', '2021','2022', '2023','2024', '2025', 'FY21', 'FY22', 'FY23', 'FY24', 'FY25','FY26'],'Date')
            for match_id , start, end in itertools.zip_longest(typematches, valuematches, datematches):
                string_id = nlp.vocab.strings[match_id]
                span = doc[start:end]
                capextype = span.text
                allcapex.loc[len(allcapex.index)] = [capextype,'a','a','a','a']
            break

运行此代码后,我将得到以下错误

代码语言:javascript
复制
line 126, in spacy.strings.StringStore.__getitem__ TypeError: '<' not supported between instances of 'tuple' and 'int'
EN

回答 1

Stack Overflow用户

发布于 2022-02-15 06:05:49

zip_longest不像你想的那样做。

我假设您希望将匹配连接起来,这意味着您应该使用itertools.chain,而不是zip_longest

现在,调用match_idstartend的变量实际上是每个匹配项的一个元组,这很奇怪,不会给出有意义的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71114647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档