Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: helper methods for testing Span overlaps #55

Open
comorbidity opened this issue Aug 7, 2023 · 0 comments
Open

Feature request: helper methods for testing Span overlaps #55

comorbidity opened this issue Aug 7, 2023 · 0 comments

Comments

@comorbidity
Copy link
Contributor

comorbidity commented Aug 7, 2023

def overlaps(span1: Span, span2: Span) -> set:
"""
:param span1: 1st text Span
:param span2: 2nd text Span
:return: set of CHAR positions (convertible to range or Span)
"""
range1 = range(span1.begin, span1.end)
range2 = range(span2.begin, span2.end)
return set(range1).intersection(set(range2))

def overlaps(span1: Span, span2: Span, min_length=2, max_length=20) -> bool:
"""
True/False text overlap exists between two spans of 'highlighted' text.

:param span1: 1st text Span
:param span2: 2nd text Span
:param min_length: MIN length of comparison, default 2 chars
:param max_length: MAX length of comparison, default 20 chars (or equals)
:return: true/false the two spans overlap
"""
shared = intersect(span1, span2)
if len(shared) == len(range(span1.begin, span1.end)):
    return True
elif (len(shared) >= min_length) and (len(shared) <= max_length):
    return True
else:
    return False
@comorbidity comorbidity changed the title Improvmeent: helper method for testing Span overlaps Improvment: helper method for testing Span overlaps Aug 7, 2023
@comorbidity comorbidity changed the title Improvment: helper method for testing Span overlaps Feature request: helper methods for testing Span overlaps Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant