From 3d18600c052be8dca59e9193310f7fc6041011f8 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 10 Jul 2019 19:21:23 +0200 Subject: [PATCH] Return True from doc.is_... when no ambiguity * Make doc.is_sentenced return True if len(doc) < 2. * Make doc.is_nered return True if len(doc) == 0, for consistency. Closes #3934 --- spacy/tokens/doc.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index a040cdc67..c77e5c44e 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -240,6 +240,8 @@ cdef class Doc: return True if self.is_parsed: return True + if len(self) < 2: + return True for i in range(1, self.length): if self.c[i].sent_start == -1 or self.c[i].sent_start == 1: return True @@ -251,6 +253,8 @@ cdef class Doc: *any* of the tokens has a named entity tag set (even if the others are uknown values). """ + if len(self) == 0: + return True for i in range(self.length): if self.c[i].ent_iob != 0: return True