mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-05 04:40:20 +03:00
group matches by pattern keys.
This commit is contained in:
parent
18ffe5bbd6
commit
46748c5dfa
|
@ -1,4 +1,5 @@
|
||||||
# cython: infer_types=True, profile=True
|
# cython: infer_types=True, profile=True
|
||||||
|
from collections import defaultdict
|
||||||
from typing import List, Iterable
|
from typing import List, Iterable
|
||||||
|
|
||||||
from libcpp.vector cimport vector
|
from libcpp.vector cimport vector
|
||||||
|
@ -313,10 +314,14 @@ cdef class Matcher:
|
||||||
else:
|
else:
|
||||||
final_results = final_matches
|
final_results = final_matches
|
||||||
# perform the callbacks on the filtered set of results
|
# perform the callbacks on the filtered set of results
|
||||||
for i, (key, *_) in enumerate(final_matches):
|
key_matches = defaultdict(list)
|
||||||
|
for (key, *_) in final_matches:
|
||||||
|
key_matches[key].append((key,*_))
|
||||||
|
|
||||||
|
for key, matches in key_matches.items():
|
||||||
on_match = self._callbacks.get(key, None)
|
on_match = self._callbacks.get(key, None)
|
||||||
if on_match is not None:
|
if on_match is not None:
|
||||||
on_match(self, doc, i, final_matches)
|
on_match(self, doc, key, matches)
|
||||||
return final_results
|
return final_results
|
||||||
|
|
||||||
def _normalize_key(self, key):
|
def _normalize_key(self, key):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user