0

I am using spacy to parsing some text. I am defining my own patterns. However, I need to consider the POS, the dependency. For example, would like to use the following pattern (with POS and DEP):

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

But, the spyder return to an error:

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

IndentationError: unexpected indent

I have imported both matchers, but I only used one matcher, as follows:

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)

I thought the reason might be, I use both POS and DEP, whereas, I only add the pattern in Matcher but not DependencyMatcher? Is it like this? If so, how should I correct it?

Thanks!

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Nina
  • 33
  • 5
  • See https://stackoverflow.com/questions/3920628/indentationerror-unexpected-indent-error. Please fix your indentation error, re-try the code, and let know what the real issue is. – Wiktor Stribiżew Mar 30 '21 at 08:30
  • Does this answer your question? [IndentationError: unexpected indent error](https://stackoverflow.com/questions/3920628/indentationerror-unexpected-indent-error) – Wiktor Stribiżew Mar 30 '21 at 09:17

1 Answers1

-1

It is solved, which is not because of the matcher.

I just re-align the codes, it works.

These several lines were originally aligned, I cut them, and paste again and re-align again, then worked.

Nina
  • 33
  • 5