Skip to content

Commit bddb883

Browse files
buhrmannines
authored andcommitted
Allow passing of empty text strings (#10)
* For compatibility with native Spacy language classes allow passing of empty text strings. This will produce 0-length docs, rather than raising an exception. * Increment minor version.
1 parent b972009 commit bddb883

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

spacy_stanfordnlp/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = "spacy-stanfordnlp"
2-
__version__ = "0.1.0"
2+
__version__ = "0.1.1"
33
__summary__ = "Use the latest StanfordNLP research models directly in spaCy"
44
__uri__ = "https://explosion.ai"
55
__author__ = "Ines Montani"

spacy_stanfordnlp/language.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from stanfordnlp.models.common.vocab import UNK_ID
88
from stanfordnlp.models.common.pretrain import Pretrain
9+
from stanfordnlp.pipeline.doc import Document
910

1011
import numpy
1112
import re
@@ -130,11 +131,12 @@ def __call__(self, text):
130131
text (unicode): The text to process.
131132
RETURNS (spacy.tokens.Doc): The spaCy Doc object.
132133
"""
133-
snlp_doc = self.snlp(text)
134+
snlp_doc = self.snlp(text) if text else Document("")
134135
text = snlp_doc.text
135136
tokens, heads = self.get_tokens_with_heads(snlp_doc)
136137
if not len(tokens):
137-
raise ValueError("No tokens available.")
138+
return Doc(self.vocab)
139+
138140
words = []
139141
spaces = []
140142
pos = []

0 commit comments

Comments
 (0)