Skip to content

Commit

Permalink
Added the cluster score to the JSON output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucioric2000 committed Jan 28, 2023
1 parent 60338df commit 915fb58
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
unicode_ = str


def spans_to_str(dct):
"""Converts spacy.tokens.span.Span objects in the dictionary keys to strings"""
new_dict = {}
for (key, value) in dct.items():
keyd = str(key)
if isinstance(value, dict):
new_dict[keyd] = spans_to_str(value)
else:
new_dict[keyd] = value
return new_dict

class AllResource(object):
def __init__(self):
self.nlp = spacy.load("en")
Expand Down Expand Up @@ -48,6 +59,7 @@ def on_get(self, req, resp):
self.response["mentions"] = mentions
self.response["clusters"] = clusters
self.response["resolved"] = resolved
self.response["scores"] = spans_to_str(doc._.coref_scores)

resp.body = json.dumps(self.response)
resp.content_type = "application/json"
Expand Down

0 comments on commit 915fb58

Please sign in to comment.