Skip to content

Commit

Permalink
Allow passing of empty text strings (#10)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
buhrmann authored and ines committed May 11, 2019
1 parent b972009 commit bddb883
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spacy_stanfordnlp/about.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "spacy-stanfordnlp"
__version__ = "0.1.0"
__version__ = "0.1.1"
__summary__ = "Use the latest StanfordNLP research models directly in spaCy"
__uri__ = "https://explosion.ai"
__author__ = "Ines Montani"
Expand Down
6 changes: 4 additions & 2 deletions spacy_stanfordnlp/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from stanfordnlp.models.common.vocab import UNK_ID
from stanfordnlp.models.common.pretrain import Pretrain
from stanfordnlp.pipeline.doc import Document

import numpy
import re
Expand Down Expand Up @@ -130,11 +131,12 @@ def __call__(self, text):
text (unicode): The text to process.
RETURNS (spacy.tokens.Doc): The spaCy Doc object.
"""
snlp_doc = self.snlp(text)
snlp_doc = self.snlp(text) if text else Document("")
text = snlp_doc.text
tokens, heads = self.get_tokens_with_heads(snlp_doc)
if not len(tokens):
raise ValueError("No tokens available.")
return Doc(self.vocab)

words = []
spaces = []
pos = []
Expand Down

0 comments on commit bddb883

Please sign in to comment.