mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Fix a few minor bugs in the SpanGroup API web docs (#10650)
* Fix a few minor bugs in the SpanGroup API web docs * Update SpanGroup docs examples to have Spans reflect intended "errors"
This commit is contained in:
parent
64602d997d
commit
4228f3c757
|
@ -21,13 +21,13 @@ cdef class SpanGroup:
|
||||||
>>> doc.spans["errors"] = SpanGroup(
|
>>> doc.spans["errors"] = SpanGroup(
|
||||||
doc,
|
doc,
|
||||||
name="errors",
|
name="errors",
|
||||||
spans=[doc[0:1], doc[2:4]],
|
spans=[doc[0:1], doc[1:3]],
|
||||||
attrs={"annotator": "matt"}
|
attrs={"annotator": "matt"}
|
||||||
)
|
)
|
||||||
|
|
||||||
Construction 2
|
Construction 2
|
||||||
>>> doc = nlp("Their goi ng home")
|
>>> doc = nlp("Their goi ng home")
|
||||||
>>> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
>>> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
>>> assert isinstance(doc.spans["errors"], SpanGroup)
|
>>> assert isinstance(doc.spans["errors"], SpanGroup)
|
||||||
|
|
||||||
DOCS: https://spacy.io/api/spangroup
|
DOCS: https://spacy.io/api/spangroup
|
||||||
|
|
|
@ -585,7 +585,7 @@ objects or a [`SpanGroup`](/api/spangroup) to a given key.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|
|
|
@ -21,7 +21,7 @@ Create a `SpanGroup`.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> spans = [doc[0:1], doc[2:4]]
|
> spans = [doc[0:1], doc[1:3]]
|
||||||
>
|
>
|
||||||
> # Construction 1
|
> # Construction 1
|
||||||
> from spacy.tokens import SpanGroup
|
> from spacy.tokens import SpanGroup
|
||||||
|
@ -60,7 +60,7 @@ the scope of your function.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> assert doc.spans["errors"].doc == doc
|
> assert doc.spans["errors"].doc == doc
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -76,9 +76,9 @@ Check whether the span group contains overlapping spans.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> assert not doc.spans["errors"].has_overlap
|
> assert not doc.spans["errors"].has_overlap
|
||||||
> doc.spans["errors"].append(doc[1:2])
|
> doc.spans["errors"].append(doc[2:4])
|
||||||
> assert doc.spans["errors"].has_overlap
|
> assert doc.spans["errors"].has_overlap
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ Get the number of spans in the group.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> assert len(doc.spans["errors"]) == 2
|
> assert len(doc.spans["errors"]) == 2
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -113,11 +113,11 @@ changes to be reflected in the span group.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> span = doc.spans["errors"][1]
|
> span = doc.spans["errors"][1]
|
||||||
> assert span.text == "goi ng"
|
> assert span.text == "goi ng"
|
||||||
> span.label_ = 'LABEL'
|
> span.label_ = 'LABEL'
|
||||||
> assert doc.spans["errors"][1] != 'LABEL' # The span within the group was not updated
|
> assert doc.spans["errors"][1].label_ != 'LABEL' # The span within the group was not updated
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|
@ -133,7 +133,7 @@ Set a span in the span group.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> span = doc[0:2]
|
> span = doc[0:2]
|
||||||
> doc.spans["errors"][0] = span
|
> doc.spans["errors"][0] = span
|
||||||
> assert doc.spans["errors"][0].text == "Their goi"
|
> assert doc.spans["errors"][0].text == "Their goi"
|
||||||
|
@ -152,7 +152,7 @@ Delete a span from the span group.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> del doc.spans[0]
|
> del doc.spans[0]
|
||||||
> assert len(doc.spans["errors"]) == 1
|
> assert len(doc.spans["errors"]) == 1
|
||||||
> ```
|
> ```
|
||||||
|
@ -171,8 +171,8 @@ over `attrs` in the second.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> doc.spans["other"] = [doc[0:2], doc[1:3]]
|
> doc.spans["other"] = [doc[0:2], doc[2:4]]
|
||||||
> span_group = doc.spans["errors"] + doc.spans["other"]
|
> span_group = doc.spans["errors"] + doc.spans["other"]
|
||||||
> assert len(span_group) == 4
|
> assert len(span_group) == 4
|
||||||
> ```
|
> ```
|
||||||
|
@ -192,7 +192,7 @@ already present in the current span group.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> doc.spans["errors"] += [doc[3:4], doc[2:3]]
|
> doc.spans["errors"] += [doc[3:4], doc[2:3]]
|
||||||
> assert len(doc.spans["errors"]) == 4
|
> assert len(doc.spans["errors"]) == 4
|
||||||
> ```
|
> ```
|
||||||
|
@ -212,7 +212,7 @@ Add a [`Span`](/api/span) object to the group. The span must refer to the same
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1]]
|
> doc.spans["errors"] = [doc[0:1]]
|
||||||
> doc.spans["errors"].append(doc[2:4])
|
> doc.spans["errors"].append(doc[1:3])
|
||||||
> assert len(doc.spans["errors"]) == 2
|
> assert len(doc.spans["errors"]) == 2
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ group.
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = []
|
> doc.spans["errors"] = []
|
||||||
> doc.spans["errors"].extend([doc[2:4], doc[0:1]])
|
> doc.spans["errors"].extend([doc[1:3], doc[0:1]])
|
||||||
> assert len(doc.spans["errors"]) == 2
|
> assert len(doc.spans["errors"]) == 2
|
||||||
> span_group = SpanGroup([doc[1:4], doc[0:3])
|
> span_group = SpanGroup([doc[1:4], doc[0:3])
|
||||||
> doc.spans["errors"].extend(span_group)
|
> doc.spans["errors"].extend(span_group)
|
||||||
|
@ -251,7 +251,7 @@ Return a copy of the span group.
|
||||||
> from spacy.tokens import SpanGroup
|
> from spacy.tokens import SpanGroup
|
||||||
>
|
>
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[2:4], doc[0:3]]
|
> doc.spans["errors"] = [doc[1:3], doc[0:3]]
|
||||||
> new_group = doc.spans["errors"].copy()
|
> new_group = doc.spans["errors"].copy()
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ Serialize the span group to a bytestring.
|
||||||
>
|
>
|
||||||
> ```python
|
> ```python
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> group_bytes = doc.spans["errors"].to_bytes()
|
> group_bytes = doc.spans["errors"].to_bytes()
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ it.
|
||||||
> from spacy.tokens import SpanGroup
|
> from spacy.tokens import SpanGroup
|
||||||
>
|
>
|
||||||
> doc = nlp("Their goi ng home")
|
> doc = nlp("Their goi ng home")
|
||||||
> doc.spans["errors"] = [doc[0:1], doc[2:4]]
|
> doc.spans["errors"] = [doc[0:1], doc[1:3]]
|
||||||
> group_bytes = doc.spans["errors"].to_bytes()
|
> group_bytes = doc.spans["errors"].to_bytes()
|
||||||
> new_group = SpanGroup()
|
> new_group = SpanGroup()
|
||||||
> new_group.from_bytes(group_bytes)
|
> new_group.from_bytes(group_bytes)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user