def test_limit_scope3(self): """Test that two modifiers of the same type limit the scope of the first modifier.""" doc = nlp("no evidence of CHF, neg for pneumonia") rule = ConTextRule("no evidence of", "DEFINITE_NEGATED_EXISTENCE", "FORWARD") rule2 = ConTextRule("neg for", "DEFINITE_NEGATED_EXISTENCE", "FORWARD") modifier = ConTextModifier(rule, 0, 3, doc) modifier2 = ConTextModifier(rule2, 5, 7, doc) assert modifier.limit_scope(modifier2)
def test_terminate_limit_scope_backward(self): """Test that a 'TERMINATE' modifier will limit the scope of a 'BACKWARD' modifier. """ doc = nlp("Pt has chf but pneumonia is ruled out") rule = ConTextRule("is ruled out", "NEGATED_EXISTENCE", "BACKWARD") modifier = ConTextModifier(rule, 6, 8, doc) rule2 = ConTextRule("but", "TERMINATE", "TERMINATE") modifier2 = ConTextModifier(rule2, 3, 4, doc) assert modifier.limit_scope(modifier2)
def test_terminate_limit_scope_custom(self): """Test that a modifier will be explicitly terminated by a modifier with a category in terminated_by.""" doc = nlp("negative for flu, positive for pneumonia.") rule = ConTextRule("negative for", "NEGATED_EXISTENCE", direction="FORWARD", terminated_by={"POSITIVE_EXISTENCE"}) rule2 = ConTextRule("positive for", "POSITIVE_EXISTENCE", direction="FORWARD") modifier = ConTextModifier(rule, 0, 2, doc) modifier2 = ConTextModifier(rule2, 4, 6, doc) assert modifier.limit_scope(modifier2)
def test_terminate_limit_scope_custom2(self): """Test that a modifier will be explicitly terminated by a modifier with a category in terminated_by.""" doc = nlp("flu is negative, pneumonia is positive.") rule = ConTextRule("negative", "NEGATED_EXISTENCE", direction="BACKWARD") rule2 = ConTextRule("positive", "POSITIVE_EXISTENCE", direction="BACKWARD", terminated_by={"NEGATED_EXISTENCE"}) modifier = ConTextModifier(rule, 2, 3, doc) modifier2 = ConTextModifier(rule2, 6, 7, doc) assert modifier2.limit_scope(modifier)
def test_no_limit_scope_same_category_different_allowed_types(self): """Test that a two ConTextModifiers of the same type but with different allowed types does not limits the scope of the modifier object. """ doc = nlp("no history of travel to Puerto Rico, neg for pneumonia") rule = ConTextRule( "no history of", "DEFINITE_NEGATED_EXISTENCE", "FORWARD", allowed_types={"TRAVEL"}, ) rule2 = ConTextRule( "neg for", "DEFINITE_NEGATED_EXISTENCE", "FORWARD", allowed_types={"CONDITION"}, ) modifier = ConTextModifier(rule, 0, 3, doc) modifier2 = ConTextModifier(rule2, 8, 10, doc) assert not modifier.limit_scope(modifier2)
def test_limit_scope2(self): doc, rule, modifier = self.create_objects() rule2 = ConTextRule("but", "TERMINATE", "TERMINATE") modifier2 = ConTextModifier(rule2, 2, 4, doc) assert not modifier2.limit_scope(modifier)