The example code given on the github default page does not work
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!
@Code4SAFrankie Did you manage to solve this? I am looking into using this for pattern matching and I also still get the same error
@laurencgreen @Code4SAFrankie I solved it, check my branch in the pull request. https://github.com/cyclecycle/spacy-pattern-builder/pull/2
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.
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.
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 overtoken_idxs[0]instead oftoken_idxssolves the problem.
Thanks for the reply, Yet now I got (name 'token_idxs' is not defined) error.