mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-14 05:37:03 +03:00
Add remove_extension method on Doc, Token and Span (closes #2242)
This commit is contained in:
parent
a512fa60ef
commit
1c6d77610c
|
@ -60,6 +60,15 @@ def test_token_underscore_method():
|
||||||
assert token._.hello() == 'cheese'
|
assert token._.hello() == 'cheese'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('obj', [Doc, Span, Token])
|
||||||
|
def test_doc_underscore_remove_extension(obj):
|
||||||
|
ext_name = 'to_be_removed'
|
||||||
|
obj.set_extension(ext_name, default=False)
|
||||||
|
assert obj.has_extension(ext_name)
|
||||||
|
obj.remove_extension(ext_name)
|
||||||
|
assert not obj.has_extension(ext_name)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('obj', [Doc, Span, Token])
|
@pytest.mark.parametrize('obj', [Doc, Span, Token])
|
||||||
def test_underscore_raises_for_dup(obj):
|
def test_underscore_raises_for_dup(obj):
|
||||||
obj.set_extension('test', default=None)
|
obj.set_extension('test', default=None)
|
||||||
|
|
|
@ -108,6 +108,12 @@ cdef class Doc:
|
||||||
def has_extension(cls, name):
|
def has_extension(cls, name):
|
||||||
return name in Underscore.doc_extensions
|
return name in Underscore.doc_extensions
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def remove_extension(cls, name):
|
||||||
|
if not cls.has_extension(name):
|
||||||
|
raise ValueError(Errors.E046.format(name=name))
|
||||||
|
return Underscore.doc_extensions.pop(name)
|
||||||
|
|
||||||
def __init__(self, Vocab vocab, words=None, spaces=None, user_data=None,
|
def __init__(self, Vocab vocab, words=None, spaces=None, user_data=None,
|
||||||
orths_and_spaces=None):
|
orths_and_spaces=None):
|
||||||
"""Create a Doc object.
|
"""Create a Doc object.
|
||||||
|
|
|
@ -36,6 +36,12 @@ cdef class Span:
|
||||||
def has_extension(cls, name):
|
def has_extension(cls, name):
|
||||||
return name in Underscore.span_extensions
|
return name in Underscore.span_extensions
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def remove_extension(cls, name):
|
||||||
|
if not cls.has_extension(name):
|
||||||
|
raise ValueError(Errors.E046.format(name=name))
|
||||||
|
return Underscore.span_extensions.pop(name)
|
||||||
|
|
||||||
def __cinit__(self, Doc doc, int start, int end, attr_t label=0,
|
def __cinit__(self, Doc doc, int start, int end, attr_t label=0,
|
||||||
vector=None, vector_norm=None):
|
vector=None, vector_norm=None):
|
||||||
"""Create a `Span` object from the slice `doc[start : end]`.
|
"""Create a `Span` object from the slice `doc[start : end]`.
|
||||||
|
|
|
@ -41,6 +41,12 @@ cdef class Token:
|
||||||
def has_extension(cls, name):
|
def has_extension(cls, name):
|
||||||
return name in Underscore.token_extensions
|
return name in Underscore.token_extensions
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def remove_extension(cls, name):
|
||||||
|
if not cls.has_extension(name):
|
||||||
|
raise ValueError(Errors.E046.format(name=name))
|
||||||
|
return Underscore.token_extensions.pop(name)
|
||||||
|
|
||||||
def __cinit__(self, Vocab vocab, Doc doc, int offset):
|
def __cinit__(self, Vocab vocab, Doc doc, int offset):
|
||||||
"""Construct a `Token` object.
|
"""Construct a `Token` object.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user