mirror of https://github.com/explosion/spaCy.git
* Fix missing n_patterns property in Matcher class. Fix from_dir method
This commit is contained in:
parent
3acf60df06
commit
430affc347
|
@ -99,7 +99,7 @@ def map_attr_name(attr):
|
|||
cdef class Matcher:
|
||||
cdef Pool mem
|
||||
cdef vector[Pattern*] patterns
|
||||
cdef readonly int n_patterns
|
||||
cdef readonly Vocab vocab
|
||||
|
||||
def __init__(self, vocab, patterns):
|
||||
self.mem = Pool()
|
||||
|
@ -107,6 +107,19 @@ cdef class Matcher:
|
|||
for entity_key, (etype, attrs, specs) in sorted(patterns.items()):
|
||||
self.add(entity_key, etype, attrs, specs)
|
||||
|
||||
@classmethod
|
||||
def from_dir(cls, data_dir, Vocab vocab):
|
||||
patterns_loc = path.join(data_dir, 'vocab', 'gazetteer.json')
|
||||
if path.exists(patterns_loc):
|
||||
patterns_data = open(patterns_loc).read()
|
||||
patterns = json.loads(patterns_data)
|
||||
return cls(vocab, patterns)
|
||||
else:
|
||||
return cls(vocab, {})
|
||||
|
||||
property n_patterns:
|
||||
def __get__(self): return self.patterns.size()
|
||||
|
||||
def add(self, entity_key, etype, attrs, specs):
|
||||
if isinstance(entity_key, basestring):
|
||||
entity_key = self.vocab.strings[entity_key]
|
||||
|
@ -120,16 +133,6 @@ cdef class Matcher:
|
|||
spec = _convert_strings(spec, self.vocab.strings)
|
||||
self.patterns.push_back(init_pattern(self.mem, spec, etype))
|
||||
|
||||
@classmethod
|
||||
def from_dir(cls, vocab, data_dir):
|
||||
patterns_loc = path.join(data_dir, 'vocab', 'gazetteer.json')
|
||||
if path.exists(patterns_loc):
|
||||
patterns_data = open(patterns_loc).read()
|
||||
patterns = json.loads(patterns_data)
|
||||
return cls(vocab, patterns)
|
||||
else:
|
||||
return cls(vocab, {})
|
||||
|
||||
def __call__(self, Doc doc):
|
||||
cdef vector[Pattern*] partials
|
||||
cdef int n_partials = 0
|
||||
|
|
Loading…
Reference in New Issue