I need to detect if a given entity is surrounded by quotes, either single or double quotes. How would I go about this.
My first thought was to add a custom extension to the span:
def is_quoted(span):
prev_token = span.doc[span.start - 1]
next_token = span.doc[span.end + 1]
return prev_token in ["\"", "'"] and next_token in ["\"", "'"]
Span.set_extension("is_quoted", getter=is_quoted)
But would this really be the most efficient way of doing this? I only want to do this on entities.
Or am I better of just writing a custom matcher, with a specific regex? But this will then run on my entire document.