Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The example code given on the github default page does not work #1

Open
Code4SAFrankie opened this issue Jan 28, 2020 · 5 comments
Open

Comments

@Code4SAFrankie
Copy link

The example code given on the github default page does not work:

The line:

matcher = DependencyTreeMatcher(doc.vocab)

Gives the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'DependencyTreeMatcher' is not defined

If I replace this with:

matcher = DependencyMatcher(doc.vocab)

It then errors futher down on:

matcher.add('pattern', None, pattern)
matches = matcher(doc)
for match_id, token_idxs in matches:
     tokens = [doc[i] for i in token_idxs]
     tokens = sorted(tokens, key=lambda w: w.i)  # Make sure tokens are in their original order
     print(tokens)  # [We, introduce, methods]

with the error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in <listcomp>
  File "doc.pyx", line 296, in spacy.tokens.doc.Doc.__getitem__
TypeError: '<' not supported between instances of 'list' and 'int'

I'm on Windows 10 with WinPython (Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32). Thanks otherwise, I have been looking for pattern matching for ages without luck!

@laurencgreen
Copy link

@Code4SAFrankie Did you manage to solve this? I am looking into using this for pattern matching and I also still get the same error

@sai-prasanna
Copy link

sai-prasanna commented Jul 30, 2020

@laurencgreen @Code4SAFrankie I solved it, check my branch in the pull request. #2

@fatihbozdag
Copy link

Greetings, I still get the same error, I've already check pull request yet I did not really get how to solve the problem. Can you please guide me?

Thanks.

@iamkissg
Copy link

iamkissg commented Sep 17, 2020

Hi all, I have the same error. After checking what is inside matches (it's really a list of list of int, i.e. [[1, 0, 3]], but not a list of int), so iterating over token_idxs[0] instead of token_idxs solves the problem.

@fatihbozdag
Copy link

Hi all, I have the same error. After checking what is inside matches (it's really a list of list of int, i.e. [[1, 0, 3]], but not a list of int), so iterating over token_idxs[0] instead of token_idxs solves the problem.

Thanks for the reply, Yet now I got (name 'token_idxs' is not defined) error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants