From 915fb580abf0a45c829bedbd942df4914183f912 Mon Sep 17 00:00:00 2001 From: Lucio Montero Date: Sat, 28 Jan 2023 01:38:16 -0600 Subject: [PATCH] Added the cluster score to the JSON output. --- examples/server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/server.py b/examples/server.py index efb0c58..abcb195 100644 --- a/examples/server.py +++ b/examples/server.py @@ -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") @@ -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"