def get_iud_brand(document: Document, expected=None): """ Heuristics: * there can be multiple brands mentioned in a single sentence, but more frequent usually selecte * context which discusses 'use'/'had'/'insert'/'contraception' retained prior to other mentions :param document: :param expected: :return: """ brands = determine_iud_brand(document) if len(brands) > 1: # if any has_using ('use', 'insert', 'contraception') values, only retain those has_using = bool([u for _, u, _ in brands if u]) # get most frequent (sometimes there is discussion of more than one) brands = ((b, u, t) for b, u, t in brands if u == has_using) c = Counter(b for b, u, _ in brands) if len(c) > 1: # still multiple brands v1, v2 = c.most_common(2) if v1[1] == v2[ 1]: # equally frequent, likely hypothetical discussion if False: yield Result(BrandStatus.NONE, -1, expected, text=document.text) raise StopIteration brands = ((b, u, t) for b, u, t in brands if c[b] == v1[1]) for brand, using, text in brands: if brand.value in [1, 2, 3, 4, 5, 6]: yield Result(brand, brand.value, expected, text=text)
def confirm_iud_expulsion(document: Document, expected=None): for status, history, text in determine_iud_expulsion(document): yield Result(status, status.value, expected, text, extras=ExpulsionStatus.HISTORY if history else None)
def confirm_iud_insertion(document: Document, expected=None): value, text = determine_iud_insertion(document) res = classify_result(value) yield Result(value, res, expected, text)
def confirm_iud_perforation(document: Document, expected=None): for value, text, date in determine_iud_perforation(document): if value.value in [1, 5, 7, 8]: yield Result(value, value.value, expected, text, date=date)
def get_parity(document: Document, expected=None): status, text, source = determine_parity(document) conf = Confidence.LOW if source == ParitySource.CHILDREN else Confidence.MEDIUM yield Result(status, status.value, expected, text, extras=source, confidence=conf)
def confirm_iud_expulsion_rad(document: Document, expected=None): for status, text in determine_iud_expulsion_rad(document): yield Result(status, status.value, expected, text)
def confirm_difficult_insertion(document: Document, expected=None): for status, text in determine_difficult_insertion(document): logging.debug(f'{status}: {text}') if status.value in [1, 2, 3, 4, 5, 6, 7, 8]: yield Result(status, status.value, expected, text)
def confirm_iud_removal(document: Document, expected=None): for value, text in determine_iud_removal(document): if value.value in [1, 2, 3, 4, 5]: yield Result(value, value.value, expected, text)