Skip to content

Commit 915fb58

Browse files
committed
Added the cluster score to the JSON output.
1 parent 60338df commit 915fb58

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

examples/server.py

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
unicode_ = str
1414

1515

16+
def spans_to_str(dct):
17+
"""Converts spacy.tokens.span.Span objects in the dictionary keys to strings"""
18+
new_dict = {}
19+
for (key, value) in dct.items():
20+
keyd = str(key)
21+
if isinstance(value, dict):
22+
new_dict[keyd] = spans_to_str(value)
23+
else:
24+
new_dict[keyd] = value
25+
return new_dict
26+
1627
class AllResource(object):
1728
def __init__(self):
1829
self.nlp = spacy.load("en")
@@ -48,6 +59,7 @@ def on_get(self, req, resp):
4859
self.response["mentions"] = mentions
4960
self.response["clusters"] = clusters
5061
self.response["resolved"] = resolved
62+
self.response["scores"] = spans_to_str(doc._.coref_scores)
5163

5264
resp.body = json.dumps(self.response)
5365
resp.content_type = "application/json"

0 commit comments

Comments
 (0)