spaCy/website/docs/usage
Adriane Boyd a322d6d5f2
Add SpanRuler component (#9880)
* Add SpanRuler component

Add a `SpanRuler` component similar to `EntityRuler` that saves a list
of matched spans to `Doc.spans[spans_key]`. The matches from the token
and phrase matchers are deduplicated and sorted before assignment but
are not otherwise filtered.

* Update spacy/pipeline/span_ruler.py

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>

* Fix cast

* Add self.key property

* Use number of patterns as length

* Remove patterns kwarg from init

* Update spacy/tests/pipeline/test_span_ruler.py

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>

* Add options for spans filter and setting to ents

* Add `spans_filter` option as a registered function'
* Make `spans_key` optional and if `None`, set to `doc.ents` instead of
`doc.spans[spans_key]`.

* Update and generalize tests

* Add test for setting doc.ents, fix key property type

* Fix typing

* Allow independent doc.spans and doc.ents

* If `spans_key` is set, set `doc.spans` with `spans_filter`.
* If `annotate_ents` is set, set `doc.ents` with `ents_fitler`.
  * Use `util.filter_spans` by default as `ents_filter`.
  * Use a custom warning if the filter does not work for `doc.ents`.

* Enable use of SpanC.id in Span

* Support id in SpanRuler as Span.id

* Update types

* `id` can only be provided as string (already by `PatternType`
definition)

* Update all uses of Span.id/ent_id in Doc

* Rename Span id kwarg to span_id

* Update types and docs

* Add ents filter to mimic EntityRuler overwrite_ents

* Refactor `ents_filter` to take `entities, spans` args for more
  filtering options
* Give registered filters more descriptive names
* Allow registered `filter_spans` filter
  (`spacy.first_longest_spans_filter.v1`) to take any number of
  `Iterable[Span]` objects as args so it can be used for spans filter
  or ents filter

* Implement future entity ruler as span ruler

Implement a compatible `entity_ruler` as `future_entity_ruler` using
`SpanRuler` as the underlying component:
* Add `sort_key` and `sort_reverse` to allow the sorting behavior to be
  customized. (Necessary for the same sorting/filtering as in
  `EntityRuler`.)
* Implement `overwrite_overlapping_ents_filter` and
  `preserve_existing_ents_filter` to support
  `EntityRuler.overwrite_ents` settings.
* Add `remove_by_id` to support `EntityRuler.remove` functionality.
* Refactor `entity_ruler` tests to parametrize all tests to test both
  `entity_ruler` and `future_entity_ruler`
* Implement `SpanRuler.token_patterns` and `SpanRuler.phrase_patterns`
  properties.

Additional changes:

* Move all config settings to top-level attributes to avoid duplicating
  settings in the config vs. `span_ruler/cfg`. (Also avoids a lot of
  casting.)

* Format

* Fix filter make method name

* Refactor to use same error for removing by label or ID

* Also provide existing spans to spans filter

* Support ids property

* Remove token_patterns and phrase_patterns

* Update docstrings

* Add span ruler docs

* Fix types

* Apply suggestions from code review

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>

* Move sorting into filters

* Check for all tokens in seen tokens in entity ruler filters

* Remove registered sort key

* Set Token.ent_id in a backwards-compatible way in Doc.set_ents

* Remove sort options from API docs

* Update docstrings

* Rename entity ruler filters

* Fix and parameterize scoring

* Add id to Span API docs

* Fix typo in API docs

* Include explicit labeled=True for scorer

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
2022-06-02 13:12:53 +02:00
..
101 Add edit tree lemmatizer (#10231) 2022-03-28 11:13:50 +02:00
_benchmarks-models.md final 3.0 benchmark numbers 2021-02-09 21:28:33 +01:00
embeddings-transformers.md add floret to static vectors docs (#10833) 2022-05-23 09:16:31 +02:00
facts-figures.md final 3.0 benchmark numbers 2021-02-09 21:28:33 +01:00
index.md Remove cuda extras for non-linux arm in install widget (#10796) 2022-05-20 09:57:41 +02:00
layers-architectures.md 🏷 Add Mypy check to CI and ignore all existing Mypy errors (#9167) 2021-10-14 15:21:40 +02:00
linguistic-features.md Remove NBSP's across tables in the docs (#10842) 2022-05-25 09:48:39 +02:00
models.md Document different ways to create a pipeline (#10762) 2022-05-06 15:40:59 +02:00
processing-pipelines.md Add edit tree lemmatizer (#10231) 2022-03-28 11:13:50 +02:00
projects.md Add documentation tip about overriding variables (#10780) 2022-05-11 10:15:32 +02:00
rule-based-matching.md Add SpanRuler component (#9880) 2022-06-02 13:12:53 +02:00
saving-loading.md Add `path.mkdir` to custom component examples of `to_disk` (#10348) 2022-03-08 16:04:10 +01:00
spacy-101.md Merge branch 'master' into develop 2020-12-11 13:44:41 +11:00
training.md `training.md`: Fix typos (#10775) 2022-05-09 19:44:14 +02:00
v2-1.md Merge branch 'spacy.io' [ci skip] 2021-03-06 17:38:54 +11:00
v2-2.md Update v3 docs [ci skip] 2020-07-05 16:11:16 +02:00
v2-3.md Merge branch 'spacy.io' [ci skip] 2021-03-06 17:38:54 +11:00
v2.md Merge branch 'spacy.io' [ci skip] 2021-03-06 17:38:54 +11:00
v3-1.md Remove NBSP's across tables in the docs (#10842) 2022-05-25 09:48:39 +02:00
v3-2.md Update Catalan acknowledgements for v3.2 (#9763) 2021-11-29 14:14:21 +01:00
v3-3.md Docs for v3.3 (#10628) 2022-04-28 14:09:35 +02:00
v3.md Remove NBSP's across tables in the docs (#10842) 2022-05-25 09:48:39 +02:00
visualizers.md Docs for v3.3 (#10628) 2022-04-28 14:09:35 +02:00