Beispiel #1
0
 def LF_before_yesterday(self, span):
     left = get_left_span(span, span.sentence, window=2).text
     right = get_right_span(span, span.sentence, window=2).text
     rgx = r'''\b(yesterday)\b'''
     return self.class_map["BEFORE"] if re.search(
         rgx, left, re.I) or re.search(rgx, right,
                                       re.I) else self.class_map["ABSTAIN"]
Beispiel #2
0
 def LF_overlaps_now(self, span):
     left = get_left_span(span, span.sentence, window=1).text
     right = get_right_span(span, span.sentence, window=1).text
     rgx = r'''\b(now)\b'''
     return self.class_map["OVERLAPS"] if re.search(
         rgx, left, re.I) or re.search(rgx, right,
                                       re.I) else self.class_map["ABSTAIN"]
Beispiel #3
0
 def LF_after_tomorrow(self, span):
     left = get_left_span(span, span.sentence, window=5).text
     right = get_right_span(span, span.sentence, window=5).text
     rgx = r'''\b(tomorrow)\b'''
     return self.class_map["AFTER"] if re.search(
         rgx, left, re.I) or re.search(rgx, right,
                                       re.I) else self.class_map["ABSTAIN"]
Beispiel #4
0
 def LF_history_of(self, span):
     rgx = r'''((family|surgical|oncologic|medical|patient) history|history of|history:|(his|her) history)'''
     left = get_left_span(span, span.sentence, window=2)
     right = get_right_span(span, span.sentence, window=2)
     context = f"{left.text} {span.text} {right.text}"
     return self.class_map["BEFORE_OVERLAPS"] if re.search(
         rgx, context, re.I) else self.class_map["ABSTAIN"]
Beispiel #5
0
 def LF_after_next_x(self, span):
     rgx = r'''\b((next|upcoming) (month|week|monday|tuesday|wednesday|thursday|friday)|(later (today|tonight|date|this (week|month|afternoon|evening))))\b'''.format(
         rgx_number_full)
     left = get_left_span(span, span.sentence, window=5).text
     right = get_right_span(span, span.sentence, window=5).text
     return self.class_map["AFTER"] if re.search(
         rgx, left, re.I) or re.search(rgx, right,
                                       re.I) else self.class_map["ABSTAIN"]
Beispiel #6
0
 def LF_before_x_ago(self, span):
     rgx = r'''\b(([1-9][0-9]|{}|few|a) ((year|month|week|day|hour)[s]*) ago)\b'''.format(
         rgx_number_full)
     left = get_left_span(span, span.sentence, window=5).text
     right = get_right_span(span, span.sentence, window=5).text
     return self.class_map["BEFORE"] if re.search(
         rgx, left, re.I) or re.search(rgx, right,
                                       re.I) else self.class_map["ABSTAIN"]
Beispiel #7
0
 def LF_regex_before_left(self, span):
     sentence_text = get_left_span(span, span.sentence, window=5).text
     for rgx in self.regex_before_left:
         if rgx.search(sentence_text):
             return self.class_map["BEFORE"]
         else:
             continue
     return self.class_map["ABSTAIN"]
Beispiel #8
0
 def LF_regex_before_overlap_left(self, span):
     left = get_left_span(span, span.sentence, window=4)
     context = f"{left.text} {span.text}"
     for rgx in self.regex_before_overlap_left:
         if rgx.search(context):
             return self.class_map["BEFORE_OVERLAPS"]
         else:
             continue
     return self.class_map["ABSTAIN"]
Beispiel #9
0
    def LF_regex_after_left(self, span):
        rgxs_stop_words = [
            re.compile(stop_word, re.I)
            for stop_word in ['otherwise', 'today']
        ]
        left = get_left_span(span, span.sentence, window=10)
        small_left = get_left_span(span, span.sentence, window=2)
        context = f"{left.text} {span.text}"
        # Filter stopwords
        for rgx_stop in rgxs_stop_words:
            if rgx_stop.search(small_left.text):
                return self.class_map["ABSTAIN"]
            else:
                continue

        for rgx in self.regex_after_left:
            if rgx.search(context) and span.text not in [
                    'arranged', 'agreed', 'consented', 'discussed', 'plan',
                    'plans', 'scheduled'
            ]:
                return self.class_map["AFTER"]
            else:
                continue
        return self.class_map["ABSTAIN"]
Beispiel #10
0
    def _is_hypothetical(span):
        accept_rgxs = [
            r"\b(if need be)\b",
            r"\b((if|should)\s+(you|she|he|be)|(she|he|you)\s+(might|could|may)\s*(be)*|if)\b",
            r"\b((possibility|potential|chance|need) (for|of)|potentially)\b",
            r"\b(candidate for|pending)\b", r"\b(assuming)\s+(you|she|he)\b",
            r"(recommendation)\s*[:]", r"(planned procedure)\s*[:]",
            r"\b(upcoming|would benefit from|(undergo|requires) a)\b",
            r'''\b(please call or return (for|if))\b''',
            r"\b(proceed with|consider|to undergo|scheduled for)\b"
        ]

        text = get_left_span(span, span.sentence, window=20).text

        for rgx in accept_rgxs:
            if re.search(rgx, text, re.I):
                return True

        return False
Beispiel #11
0
 def LF_after_should(self, span):
     left = get_left_span(span, span.sentence, window=10).text
     rgx = r'''\b(should (be)*)\b'''
     return self.class_map["AFTER"] if re.search(
         rgx, left, re.I) else self.class_map["ABSTAIN"]
Beispiel #12
0
 def LF_after_will(self, span):
     left = get_left_span(span, span.sentence, window=6).text
     rgx = r'''\b(will (try)*|plan(ning)*)\b'''
     return self.class_map["AFTER"] if re.search(
         rgx, left, re.I) else self.class_map["ABSTAIN"]
Beispiel #13
0
 def LF_before_recent(self, span):
     left = get_left_span(span, span.sentence, window=2)
     return self.class_map["BEFORE"] if re.search(
         r'''\b(recent(ly)*)\b''', left.text,
         re.I) else self.class_map["ABSTAIN"]
Beispiel #14
0
 def LF_overlaps_current(self, span):
     left = get_left_span(span, span.sentence, window=4)
     return self.class_map["OVERLAPS"] if re.search(
         r'''\b(current(ly)*)\b''', left.text,
         re.I) else self.class_map["ABSTAIN"]