mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 01:46:28 +03:00
Partially apply doc/span/token into method
We want methods to act like they're "bound" to the object, so that you can make your method conditional on the `doc`, `span` or `token` instance --- like, well, a method. We therefore partially apply the function, which works like this: ``` def partial(unbound_method, constant_arg): def bound_method(*args, **kwargs): return unbound_method(constant_arg, *args, **kwargs) return bound_method
This commit is contained in:
parent
de374dc72a
commit
51d18937af
|
@ -1,3 +1,5 @@
|
|||
import functools
|
||||
|
||||
class Underscore(object):
|
||||
doc_extensions = {}
|
||||
span_extensions = {}
|
||||
|
@ -22,7 +24,7 @@ class Underscore(object):
|
|||
if getter is not None:
|
||||
return getter(self._obj)
|
||||
elif method is not None:
|
||||
return method
|
||||
return functools.partial(method, self._obj)
|
||||
else:
|
||||
return self._doc.user_data.get(self._get_key(name), default)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user