【问题标题】:How to use POS and DEP together in one single pattern in spacy如何在 spacy 中以一种模式同时使用 POS 和 DEP
【发布时间】:2021-03-30 08:22:06
【问题描述】:

我正在使用 spacy 来解析一些文本。 我正在定义我自己的模式。 但是,我需要考虑 POS,即依赖项。例如,想使用以下模式(使用 POS 和 DEP):

pattern = [
          {'POS': {'IN': ['NOUN','ADJ'] } , 
           "DEP": {'IN': ['attr', 'amod']}, 
           "OP": "+"},
          {'TEXT': {'IN': ['to','of', 'on','by','from','in']} , "OP": "+"},
          {'POS': {'IN': ['NOUN','VERB']}}               
           ]

但是,spyder返回错误:

   matcher.add('rule', [pattern])
^

IndentationError: unexpected indent

两个matcher我都导入了,但是我只用了一个matcher,如下:

from spacy.matcher import Matcher

from spacy.matcher import DependencyMatcher
matcher = Matcher(nlp.vocab)
matcher.add('rule', [pattern]) #### the error shows in this line####
matches = matcher(doc)

我认为原因可能是,我同时使用 POS 和 DEP,而我只在 Matcher 中添加模式而不是 DependencyMatcher?是这样的吗? 如果是这样,我应该如何纠正它?

谢谢!

【问题讨论】:

标签: python spacy


【解决方案1】:

解决了,不是因为matcher。

我只是重新对齐代码,它可以工作。

这几行本来是对齐的,我剪下来,再粘贴一遍,重新对齐,然后就工作了。

【讨论】:

    猜你喜欢
    • 2020-02-01
    • 2022-08-19
    • 2019-08-26
    • 1970-01-01
    • 2016-03-10
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多