File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change
1
+ import spacy
2
+
3
+ from zshot import PipelineConfig , displacy
4
+ from zshot .tests .config import EX_ENTITIES , EX_DOCS
5
+ from zshot .tests .linker .test_linker import DummyLinkerEnd2End
6
+ from zshot .tests .mentions_extractor .test_mention_extractor import DummyMentionsExtractor
1
7
from zshot .utils .data_models import Span
2
8
from zshot .utils .alignment_utils import align_spans , AlignmentMode , filter_overlapping_spans
3
9
@@ -164,3 +170,17 @@ def test_alignment_expand_overlaps_no_score():
164
170
assert filtered_spans [0 ].label == "A"
165
171
assert filtered_spans [1 ].start == 3 and filtered_spans [1 ].end == 8
166
172
assert filtered_spans [1 ].label == "C"
173
+
174
+
175
+ def test_displacy_render ():
176
+ nlp = spacy .blank ("en" )
177
+
178
+ nlp .add_pipe ("zshot" , config = PipelineConfig (
179
+ mentions_extractor = DummyMentionsExtractor (),
180
+ linker = DummyLinkerEnd2End (),
181
+ entities = EX_ENTITIES ), last = True )
182
+ doc = nlp (EX_DOCS [1 ])
183
+ assert len (doc .ents ) > 0
184
+ assert len (doc ._ .spans ) > 0
185
+ res = displacy .render (doc , style = "ent" , jupyter = False )
186
+ assert res is not None
Original file line number Diff line number Diff line change @@ -27,12 +27,12 @@ def color_from_label(label: str):
27
27
class displacy :
28
28
29
29
@staticmethod
30
- def render (doc , options : Dict = None , ** kwargs ):
30
+ def render (doc , options : Dict = None , ** kwargs ) -> str :
31
31
if options :
32
32
options ['colors' ] = ents_colors (doc )
33
33
else :
34
34
options = {'colors' : ents_colors (doc )}
35
- s_displacy .render (doc , options = options , ** kwargs )
35
+ return s_displacy .render (doc , options = options , ** kwargs )
36
36
37
37
@staticmethod
38
38
def serve (doc , options : Dict = None , ** kwargs ):
You can’t perform that action at this time.
0 commit comments