Skip to content

Commit

Permalink
Remove deprecated spacier.components.merge_entities()
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewilde committed Jul 14, 2019
1 parent fa4bb86 commit 953c116
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
20 changes: 0 additions & 20 deletions tests/spacier/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,3 @@ def test_attrs_on_doc(spacy_lang, spacy_doc):
for attr in tsc.attrs:
assert spacy_doc._.has(attr) is True
assert isinstance(spacy_doc._.get(attr), (int, float, dict)) is True


def test_merge_entities_deprecation(spacy_lang):
doc = spacy_lang("Matthew Honnibal and Ines Montani do great work on spaCy.")
with pytest.warns(DeprecationWarning):
_ = components.merge_entities(doc)


def test_merge_entities(spacy_lang):
doc1 = spacy_lang("Matthew Honnibal and Ines Montani do great work on spaCy.")
# (temporarily) add this other component to the pipeline
spacy_lang.add_pipe(components.merge_entities, after="ner")
doc2 = spacy_lang("Matthew Honnibal and Ines Montani do great work on spaCy.")
# check the key behaviors we'd expect
assert spacy_lang.has_pipe("merge_entities") is True
assert len(doc1) > len(doc2)
assert any(tok.text == "Matthew Honnibal" for tok in doc2)
assert any(tok.text == "Ines Montani" for tok in doc2)
# now remove this component, since we don't want it elsewhere
spacy_lang.remove_pipe("merge_entities")
35 changes: 0 additions & 35 deletions textacy/spacier/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

from spacy.tokens import Doc

from . import utils as spacier_utils
from .. import compat
from .. import text_stats
from .. import utils

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -113,36 +111,3 @@ def __call__(self, doc):
)
raise
return doc


def merge_entities(doc):
"""
Merge named entities into single tokens in ``doc``, *in-place*.
Can be used as a stand-alone function, or as part of a spaCy language pipeline::
>>> spacy_lang = textacy.load_spacy_lang('en')
>>> spacy_lang.add_pipe(merge_entities, after='ner')
>>> doc = spacy_lang('Burton DeWilde is an entity in this sentence.')
>>> doc[0]
Burton DeWilde
Args:
doc (:class:`spacy.tokens.Doc`)
Returns:
:class:`spacy.tokens.Doc`: Input ``doc`` with entities merged.
Warning:
*DEPRECATED!* For equivalent functionality, use
:func:`spacy.pipeline.functions.merge_entities()` instead.
For details, see https://spacy.io/api/pipeline-functions.
"""
utils.deprecated(
"`merge_entities()` has been deprecated! for equivalent functionality, "
"use :func:`spacy.pipeline.functions.merge_entities()` instead. "
"For details, see https://spacy.io/api/pipeline-functions.",
action="once",
)
spacier_utils.merge_spans(doc.ents, doc)
return doc

0 comments on commit 953c116

Please sign in to comment.