I am trying to capture quotes using spacy and textcy. The quotes are getting extracte But I am not able to put it back on the UI
def predict_quote(prediction_request: PredictionRequest) -> PredictionResponse:
# Load the CAS and type system from the request
typesystem = load_typesystem(prediction_request.typeSystem)
cas = load_cas_from_xmi(prediction_request.document.xmi, typesystem=typesystem)
AnnotationType = typesystem.get_type(prediction_request.layer)
# Extract the tokens from the CAS and create a spacy doc from it
sentences = list(cas.select(SENTENCE_TYPE))
print("sentences:",sentences)
words = [cas.get_covered_text(token) for token in sentences]
print(words)
doc =nlp("".join(words))
print(doc.sents)
# Find the quote entities
quote_entities = direct_quotations(doc)
print(list(quote_entities))
# For every entity returned by spacy, create an annotation in the CAS
for ent in (quote_entities):
for i in ent:
fields = {'begin': tokens[i.start].begin,
'end': tokens[i.end - 1].end,
IS_PREDICTION: True,
prediction_request.feature: "speaker"}
annotation = AnnotationType(**fields)
cas.add_annotation(annotation)
break
xmi = cas.to_xmi()
return PredictionResponse(xmi)
I am trying to capture quotes using spacy and textcy. The quotes are getting extracte But I am not able to put it back on the UI