From 19657b392a5fab8392be1e518fefacb442fd78a3 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 21 Dec 2022 13:02:20 +0100 Subject: [PATCH] Update docs. --- spacy/tokens/span_group.pyx | 19 ++++++++++--------- website/docs/api/spangroup.md | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/spacy/tokens/span_group.pyx b/spacy/tokens/span_group.pyx index e01a57dfb..9cb724a02 100644 --- a/spacy/tokens/span_group.pyx +++ b/spacy/tokens/span_group.pyx @@ -158,6 +158,16 @@ cdef class SpanGroup: return self._concat(other) return NotImplemented + def __iter__(self): + """ + Iterate over the spans in this SpanGroup. + YIELDS (Span): A span in this SpanGroup. + + DOCS: https://spacy.io/api/spangroup#iter + """ + for i in range(self.c.size()): + yield self[i] + def append(self, Span span): """Add a span to the group. The span must refer to the same Doc object as the span group. @@ -170,15 +180,6 @@ cdef class SpanGroup: raise ValueError(Errors.E855.format(obj="span")) self.push_back(span.c) - def __iter__(self): - """ - Iterate over the spans in this SpanGroup. - YIELDS (Span): A span in this SpanGroup. - - DOCS: https://spacy.io/api/spangroup#iter - """ - for i in range(self.c.size()): - yield self[i] def extend(self, spans_or_span_group: Union[SpanGroup, Iterable["Span"]]): """Add multiple spans or contents of another SpanGroup to the group. diff --git a/website/docs/api/spangroup.md b/website/docs/api/spangroup.md index 2d1cf73c4..97ba3c587 100644 --- a/website/docs/api/spangroup.md +++ b/website/docs/api/spangroup.md @@ -202,6 +202,23 @@ already present in the current span group. | `other` | The span group or spans to append. ~~Union[SpanGroup, Iterable[Span]]~~ | | **RETURNS** | The span group. ~~SpanGroup~~ | +## SpanGroup.\_\_iter\_\_ {#iter tag="method" new="3.5"} + +Iterate over the spans in this SpanGroup. + +> #### Example +> +> ```python +> doc = nlp("Their goi ng home") +> doc.spans["errors"] = [doc[0:1], doc[1:3]] +> for error_span in doc.spans["errors"]: +> print(error_span) +> ``` + +| Name | Description | +| ---------- | ----------------------------------- | +| **YIELDS** | A span in this SpanGroup.. ~~Span~~ | + ## SpanGroup.append {#append tag="method"} Add a [`Span`](/api/span) object to the group. The span must refer to the same