Exemple #1
0
 def test_no_types(self):
     """Test that not specifying allowed_types or excluded_types will modify all targets."""
     doc = self.create_target_type_examples()
     item = ConTextItem(
         "no history of travel to",
         category="DEFINITE_NEGATED_EXISTENCE",
         rule="FORWARD",
     )
     tag_object = TagObject(item, 0, 5, doc)
     tag_object.set_scope()
     travel, condition = doc.ents  # "puerto rico", "pneumonia"
     assert tag_object.modifies(travel) is True
     assert tag_object.modifies(condition) is True
Exemple #2
0
    def test_overlapping_target(self):
        """Test that a modifier will not modify a target if it is
        in the same span as the modifier.
        """
        doc = nlp("Pt presents for r/o of pneumonia.")
        item = ConTextItem("r/o", "UNCERTAIN", rule="BIDIRECTIONAL")
        tag_object = TagObject(item, 3, 4, doc)
        target = Span(doc, 3, 4, "TEST")

        assert tag_object.modifies(target) is False
Exemple #3
0
    def test_on_modifies_false(self):
        def on_modifies(target, modifier, span_between):
            return False

        item = ConTextItem("no evidence of",
                           "NEGATED_EXISTENCE",
                           on_modifies=on_modifies)
        doc = nlp("There is no evidence of pneumonia or chf.")
        doc.ents = (doc[5:6], doc[7:8])
        tag = TagObject(item, 2, 5, doc)

        assert tag.modifies(doc.ents[0]) is False
Exemple #4
0
    def test_on_modifies_arg_types(self):
        def check_arg_types(target, modifier, span_between):
            for arg in (target, modifier, span_between):
                if not isinstance(arg, spacy.tokens.Span):
                    return False
            return True

        item = ConTextItem("no evidence of",
                           "NEGATED_EXISTENCE",
                           on_modifies=check_arg_types)
        doc = nlp("There is no evidence of pneumonia or chf.")
        doc.ents = (doc[5:6], doc[7:8])
        tag = TagObject(item, 2, 5, doc)

        assert tag.modifies(doc.ents[0]) is True
Exemple #5
0
    def test_max_scope_none(self):
        """Test that if max_scope is not None it will reduce the range
        of text which is modified.
        """
        doc = self.create_num_target_examples()
        assert len(doc.ents) == 3
        item = ConTextItem("vs",
                           category="UNCERTAIN",
                           rule="BIDIRECTIONAL",
                           max_scope=None)
        tag_object = TagObject(item, 5, 6, doc)

        for target in doc.ents:
            if tag_object.modifies(target):
                tag_object.modify(target)
        assert tag_object.num_targets == 3
Exemple #6
0
    def test_on_modifies_arg_values(self):
        def check_arg_types(target, modifier, span_between):
            if target.lower_ != "chf":
                return False
            if modifier.lower_ != "no evidence of":
                return False
            if span_between.lower_ != "pneumonia or":
                return False
            return True

        item = ConTextItem("no evidence of",
                           "NEGATED_EXISTENCE",
                           on_modifies=check_arg_types)
        doc = nlp("There is no evidence of pneumonia or chf.")
        doc.ents = (doc[5:6], doc[7:8])
        tag = TagObject(item, 2, 5, doc)

        assert tag.modifies(doc.ents[1]) is True