def assert_finds_result(self, tagged_text, parent_title, *refs):
     """Given the tags and a title for a parent node, verify that the
     provided references are found"""
     parent = Node(label=['1000', '1'], title=parent_title)
     node = Node(re.sub(r"<[^>]*>", "", tagged_text))  # removes tags
     node.tagged_text = tagged_text
     results = def_finders.DefinitionKeyterm(parent).find(node)
     self.assertEqual(len(results), len(refs))
     for expected, actual in zip(refs, results):
         self.assertEqual(expected.term, actual.term)
         self.assertEqual(expected.start, actual.start)
Esempio n. 2
0
    def node_definitions(self, node, stack=None):
        """Find defined terms in this node's text."""
        references = []
        stack = stack or ParentStack()
        for finder in (def_finders.ExplicitIncludes(),
                       def_finders.SmartQuotes(stack),
                       def_finders.ScopeMatch(self.scope_finder),
                       def_finders.XMLTermMeans(references),
                       def_finders.DefinitionKeyterm(stack.parent_of(node))):
            # Note that `extend` is very important as XMLTermMeans uses the
            # list reference
            references.extend(finder.find(node))

        references = [r for r in references if len(r.term) <= MAX_TERM_LENGTH]

        return ([r for r in references if not self.is_exclusion(r.term, node)],
                [r for r in references if self.is_exclusion(r.term, node)])