def test_is_exclusion(self):
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
    def test_is_exclusion(self):
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', (0, 0))]}
        self.assertFalse(t.is_exclusion('ex', n))
Exemplo n.º 3
0
 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'])
Exemplo n.º 5
0
 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])))
Exemplo n.º 6
0
    def test_is_exclusion(self):
        """There are certain indicators that a definition _should not_ be
        considered the definition of that term. For example, exclusions to a
        general definition should not replace the original. We can also
        explicitly ignore chunks of text when finding definitions.."""
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('ex', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111', ): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        settings.IGNORE_DEFINITIONS_IN['1111'] = ['phrase with abc in it']
        self.assertFalse(t.is_exclusion('abc', n))
        n.text = "Now the node has a phrase with abc in it, doesn't it?"
        self.assertTrue(t.is_exclusion('abc', n))
 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_is_exclusion(self):
        """There are certain indicators that a definition _should not_ be
        considered the definition of that term. For example, exclusions to a
        general definition should not replace the original. We can also
        explicitly ignore chunks of text when finding definitions.."""
        t = Terms(None)
        n = Node('ex ex ex', label=['1111', '2'])
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('ex', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))
        n.text = u'Something something the term “ex” does not include potato'
        self.assertTrue(t.is_exclusion('ex', n))

        t.scoped_terms = {('1111',): [Ref('abc', '1', 0)]}
        self.assertFalse(t.is_exclusion('ex', n))

        settings.IGNORE_DEFINITIONS_IN['1111'] = ['phrase with abc in it']
        self.assertFalse(t.is_exclusion('abc', n))
        n.text = "Now the node has a phrase with abc in it, doesn't it?"
        self.assertTrue(t.is_exclusion('abc', n))
 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)