mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 18:26:30 +03:00
Add Token.is_sent_start property, so can deprecate Token.sent_start
This commit is contained in:
parent
7e7116cdf7
commit
9e0ebee81c
|
@ -155,13 +155,13 @@ def test_doc_token_api_head_setter(en_tokenizer):
|
||||||
assert doc[2].left_edge.i == 0
|
assert doc[2].left_edge.i == 0
|
||||||
|
|
||||||
|
|
||||||
def test_sent_start(en_tokenizer):
|
def test_is_sent_start(en_tokenizer):
|
||||||
doc = en_tokenizer(u'This is a sentence. This is another.')
|
doc = en_tokenizer(u'This is a sentence. This is another.')
|
||||||
assert not doc[0].sent_start
|
assert doc[5].is_sent_start is None
|
||||||
assert not doc[5].sent_start
|
doc[5].is_sent_start = True
|
||||||
doc[5].sent_start = True
|
assert doc[5].is_sent_start is True
|
||||||
assert doc[5].sent_start
|
# Backwards compatibility
|
||||||
assert not doc[0].sent_start
|
assert doc[0].sent_start is False
|
||||||
doc.is_parsed = True
|
doc.is_parsed = True
|
||||||
assert len(list(doc.sents)) == 2
|
assert len(list(doc.sents)) == 2
|
||||||
|
|
||||||
|
|
|
@ -330,9 +330,29 @@ cdef class Token:
|
||||||
return self.c.r_kids
|
return self.c.r_kids
|
||||||
|
|
||||||
property sent_start:
|
property sent_start:
|
||||||
# TODO: fix and document
|
# TODO deprecation warning
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
return self.c.sent_start
|
# Handle broken backwards compatibility case: doc[0].sent_start
|
||||||
|
# was False.
|
||||||
|
if self.i == 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return self.sent_start
|
||||||
|
|
||||||
|
def __set__(self, value):
|
||||||
|
self.is_sent_start = value
|
||||||
|
|
||||||
|
property is_sent_start:
|
||||||
|
"""RETURNS (bool / None): Whether the token starts a sentence.
|
||||||
|
None if unknown.
|
||||||
|
"""
|
||||||
|
def __get__(self):
|
||||||
|
if self.c.sent_start == 0:
|
||||||
|
return None
|
||||||
|
elif self.c.sent_start < 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def __set__(self, value):
|
def __set__(self, value):
|
||||||
if self.doc.is_parsed:
|
if self.doc.is_parsed:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user