Make kb_id and following kw-only

This commit is contained in:
Adriane Boyd 2023-02-09 09:04:00 +01:00
parent 5bbf8eb40f
commit 4a47e25a4a
6 changed files with 7 additions and 5 deletions

View File

@ -105,6 +105,7 @@ class Doc:
start_idx: int,
end_idx: int,
label: Union[int, str] = ...,
*,
kb_id: Union[int, str] = ...,
vector: Optional[Floats1d] = ...,
alignment_mode: str = ...,

View File

@ -520,7 +520,7 @@ cdef class Doc:
def doc(self):
return self
def char_span(self, int start_idx, int end_idx, label=0, kb_id=0, vector=None, alignment_mode="strict", span_id=0):
def char_span(self, int start_idx, int end_idx, label=0, *, kb_id=0, vector=None, alignment_mode="strict", span_id=0):
"""Create a `Span` object from the slice
`doc.text[start_idx : end_idx]`. Returns None if no valid `Span` can be
created.
@ -1605,7 +1605,7 @@ cdef class Doc:
for span_group in doc_json.get("spans", {}):
spans = []
for span in doc_json["spans"][span_group]:
char_span = self.char_span(span["start"], span["end"], span["label"], span["kb_id"])
char_span = self.char_span(span["start"], span["end"], span["label"], kb_id=span["kb_id"])
if char_span is None:
raise ValueError(Errors.E1039.format(obj="span", start=span["start"], end=span["end"]))
spans.append(char_span)

View File

@ -93,8 +93,8 @@ class Span:
self,
start_idx: int,
end_idx: int,
*,
label: Union[int, str] = ...,
*,
kb_id: Union[int, str] = ...,
vector: Optional[Floats1d] = ...,
alignment_mode: str = ...,

View File

@ -666,7 +666,7 @@ cdef class Span:
else:
return self.doc[root]
def char_span(self, int start_idx, int end_idx, *, label=0, kb_id=0, vector=None, alignment_mode="strict", span_id=0):
def char_span(self, int start_idx, int end_idx, label=0, *, kb_id=0, vector=None, alignment_mode="strict", span_id=0):
"""Create a `Span` object from the slice `span.text[start : end]`.
start_idx (int): The index of the first character of the span.

View File

@ -214,6 +214,7 @@ alignment mode `"strict".
| `start` | The index of the first character of the span. ~~int~~ |
| `end` | The index of the last character after the span. ~~int~~ |
| `label` | A label to attach to the span, e.g. for named entities. ~~Union[int, str]~~ |
| _keyword-only_ | |
| `kb_id` | An ID from a knowledge base to capture the meaning of a named entity. ~~Union[int, str]~~ |
| `vector` | A meaning representation of the span. ~~numpy.ndarray[ndim=1, dtype=float32]~~ |
| `alignment_mode` | How character indices snap to token boundaries. Options: `"strict"` (no snapping), `"contract"` (span of all tokens completely within the character span), `"expand"` (span of all tokens at least partially covered by the character span). Defaults to `"strict"`. ~~str~~ |

View File

@ -190,8 +190,8 @@ the character indices don't map to a valid span.
| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `start_idx` | The index of the first character of the span. ~~int~~ |
| `end_idx` | The index of the last character after the span. ~~int~~ |
| _keyword-only_ | |
| `label` | A label to attach to the span, e.g. for named entities. ~~Union[int, str]~~ |
| _keyword-only_ | |
| `kb_id` | An ID from a knowledge base to capture the meaning of a named entity. ~~Union[int, str]~~ |
| `vector` | A meaning representation of the span. ~~numpy.ndarray[ndim=1, dtype=float32]~~ |
| `alignment_mode` <Tag variant="new">3.5.1</Tag> | How character indices snap to token boundaries. Options: `"strict"` (no snapping), `"contract"` (span of all tokens completely within the character span), `"expand"` (span of all tokens at least partially covered by the character span). Defaults to `"strict"`. ~~str~~ |