def test_process_label_in_node(self): """Make sure we don't highlight definitions that are being defined in this paragraph.""" tree = Node(children=[ Node("Defining secret phrase.", label=['AB', 'a']), Node("Has secret phrase. Then some other content", label=['AB', 'b']) ], label=['AB']) t = Terms(tree) t.scoped_terms = {('AB', ): [Ref("secret phrase", "AB-a", 9)]} # Term is defined in the first child self.assertEqual([], t.process(tree.children[0])) self.assertEqual(1, len(t.process(tree.children[1])))
def test_process_label_in_node(self): """Make sure we don't highlight definitions that are being defined in this paragraph.""" tree = Node(children=[ Node("Defining secret phrase.", label=['AB', 'a']), Node("Has secret phrase. Then some other content", label=['AB', 'b']) ], label=['AB']) t = Terms(tree) t.scoped_terms = { ('AB',): [Ref("secret phrase", "AB-a", (9, 22))] } # Term is defined in the first child self.assertEqual([], t.process(tree.children[0])) self.assertEqual(1, len(t.process(tree.children[1])))
def test_process(self): """The process() method should both find terms in the requested node and order them by term name""" t = Terms( Node(children=[ Node("ABC5", children=[Node("child")], label=['ref1']), Node("AABBCC5", label=['ref2']), Node("ABC3", label=['ref3']), Node("AAA3", label=['ref4']), Node("ABCABC3", label=['ref5']), Node("ABCOTHER", label=['ref6']), Node("ZZZOTHER", label=['ref7']), ])) t.scoped_terms = { ("101", "22", "b", "2", "ii"): [Ref("abc", "ref1", 1), Ref("aabbcc", "ref2", 2)], ("101", "22", "b"): [ Ref("abc", "ref3", 3), Ref("aaa", "ref4", 4), Ref("abcabc", "ref5", 5) ], ("101", "22", "b", "2", "iii"): [Ref("abc", "ref6", 6), Ref("zzz", "ref7", 7)] } # Check that the return value is correct layer_el = t.process( Node("This has abc, aabbcc, aaa, abcabc, and zzz", label=["101", "22", "b", "2", "ii"])) self.assertEqual( [el['ref'] for el in layer_el], ['aaa:ref4', 'aabbcc:ref2', 'abc:ref1', 'abcabc:ref5'])
def test_process(self): """The process() method should both find terms in the requested node and order them by term name""" t = Terms(Node(children=[ Node("ABC5", children=[Node("child")], label=['ref1']), Node("AABBCC5", label=['ref2']), Node("ABC3", label=['ref3']), Node("AAA3", label=['ref4']), Node("ABCABC3", label=['ref5']), Node("ABCOTHER", label=['ref6']), Node("ZZZOTHER", label=['ref7']), ])) t.scoped_terms = { ("101", "22", "b", "2", "ii"): [ Ref("abc", "ref1", 1), Ref("aabbcc", "ref2", 2)], ("101", "22", "b"): [ Ref("abc", "ref3", 3), Ref("aaa", "ref4", 4), Ref("abcabc", "ref5", 5)], ("101", "22", "b", "2", "iii"): [ Ref("abc", "ref6", 6), Ref("zzz", "ref7", 7)]} # Check that the return value is correct layer_el = t.process(Node( "This has abc, aabbcc, aaa, abcabc, and zzz", label=["101", "22", "b", "2", "ii"])) self.assertEqual( [el['ref'] for el in layer_el], ['aaa:ref4', 'aabbcc:ref2', 'abc:ref1', 'abcabc:ref5'])
def test_process(self): t = Terms( Node(children=[ Node("ABC5", children=[Node("child")], label=['ref1']), Node("AABBCC5", label=['ref2']), Node("ABC3", label=['ref3']), Node("AAA3", label=['ref4']), Node("ABCABC3", label=['ref5']), Node("ABCOTHER", label=['ref6']), Node("ZZZOTHER", label=['ref7']), ])) t.scoped_terms = { ("101", "22", "b", "2", "ii"): [Ref("abc", "ref1", (1, 2)), Ref("aabbcc", "ref2", (2, 3))], ("101", "22", "b"): [ Ref("abc", "ref3", (3, 4)), Ref("aaa", "ref4", (4, 5)), Ref("abcabc", "ref5", (5, 6)) ], ("101", "22", "b", "2", "iii"): [Ref("abc", "ref6", (6, 7)), Ref("zzz", "ref7", (7, 8))] } # Check that the return value is correct layer_el = t.process( Node("This has abc, aabbcc, aaa, abcabc, and zzz", label=["101", "22", "b", "2", "ii"])) self.assertEqual(4, len(layer_el)) found = [False, False, False, False] for ref_obj in layer_el: if ref_obj['ref'] == 'abc:ref1': found[0] = True if ref_obj['ref'] == 'aabbcc:ref2': found[1] = True if ref_obj['ref'] == 'aaa:ref4': found[2] = True if ref_obj['ref'] == 'abcabc:ref5': found[3] = True self.assertEqual([True, True, True, True], found)
def test_process(self): t = Terms(Node(children=[ Node("ABC5", children=[Node("child")], label=['ref1']), Node("AABBCC5", label=['ref2']), Node("ABC3", label=['ref3']), Node("AAA3", label=['ref4']), Node("ABCABC3", label=['ref5']), Node("ABCOTHER", label=['ref6']), Node("ZZZOTHER", label=['ref7']), ])) t.scoped_terms = { ("101", "22", "b", "2", "ii"): [ Ref("abc", "ref1", (1,2)), Ref("aabbcc", "ref2", (2,3))], ("101", "22", "b"): [ Ref("abc", "ref3", (3,4)), Ref("aaa", "ref4", (4,5)), Ref("abcabc", "ref5", (5,6))], ("101", "22", "b", "2", "iii"): [ Ref("abc", "ref6", (6,7)), Ref("zzz", "ref7", (7,8))] } # Check that the return value is correct layer_el = t.process(Node( "This has abc, aabbcc, aaa, abcabc, and zzz", label=["101", "22", "b", "2", "ii"])) self.assertEqual(4, len(layer_el)) found = [False, False, False, False] for ref_obj in layer_el: if ref_obj['ref'] == 'abc:ref1': found[0] = True if ref_obj['ref'] == 'aabbcc:ref2': found[1] = True if ref_obj['ref'] == 'aaa:ref4': found[2] = True if ref_obj['ref'] == 'abcabc:ref5': found[3] = True self.assertEqual([True, True, True, True], found)