def test_calculate_offsets_exclusions(self):
     applicable_terms = [('act', 'a')]
     text = "This text defines the 'fudge act'"
     t = Terms(None)
     self.assertEqual([], 
             t.calculate_offsets(text, applicable_terms, [(23,32)]))
     self.assertEqual([('act', 'a', [(29,32)])],
             t.calculate_offsets(text, applicable_terms, [(1,5)]))
Exemple #2
0
 def test_calculate_offsets_exclusions(self):
     applicable_terms = [('act', 'a')]
     text = "This text defines the 'fudge act'"
     t = Terms(None)
     self.assertEqual([],
                      t.calculate_offsets(text, applicable_terms,
                                          [(23, 32)]))
     self.assertEqual([('act', 'a', [(29, 32)])],
                      t.calculate_offsets(text, applicable_terms, [(1, 5)]))
Exemple #3
0
 def test_calculate_offsets_word_part(self):
     """If a defined term is part of another word, don't include it"""
     applicable_terms = [('act', 'a')]
     text = "I am about to act on this transaction."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     self.assertEqual(1, len(matches[0][2]))
 def test_calculate_offsets_word_part(self):
     """If a defined term is part of another word, don't include it"""
     applicable_terms = [('act', 'a')]
     text = "I am about to act on this transaction."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     self.assertEqual(1, len(matches[0][2]))
Exemple #5
0
 def test_calculate_offsets_overlap(self):
     applicable_terms = [('mad cow disease', 'mc'), ('goes mad', 'gm')]
     text = 'There goes mad cow disease'
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     _, ref, offsets = matches[0]
     self.assertEqual('mc', ref)
     self.assertEqual('mad cow disease', text[offsets[0][0]:offsets[0][1]])
Exemple #6
0
 def test_calculate_offsets_lexical_container(self):
     applicable_terms = [('access device', 'a'), ('device', 'd')]
     text = "This access device is fantastic!"
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     _, ref, offsets = matches[0]
     self.assertEqual('a', ref)
     self.assertEqual([(5, 18)], offsets)
 def test_calculate_offsets_overlap(self):
     applicable_terms = [('mad cow disease', 'mc'), ('goes mad', 'gm')]
     text = 'There goes mad cow disease'
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     _, ref, offsets = matches[0]
     self.assertEqual('mc', ref)
     self.assertEqual('mad cow disease', text[offsets[0][0]:offsets[0][1]])
 def test_calculate_offsets_lexical_container(self):
     applicable_terms = [('access device', 'a'), ('device', 'd')]
     text = "This access device is fantastic!"
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(1, len(matches))
     _, ref, offsets = matches[0]
     self.assertEqual('a', ref)
     self.assertEqual([(5, 18)], offsets)
Exemple #9
0
 def test_calculate_offsets(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     six.assertCountEqual(self, matches, [('rock band', 'a', [(10, 19)]),
                                          ('band', 'b', [(30, 34)]),
                                          ('drum', 'c', [(42, 46),
                                                         (55, 59)])])
 def test_calculate_offsets(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertItemsEqual(matches, [
         ('rock band', 'a', [(10, 19)]),
         ('band', 'b', [(30, 34)]),
         ('drum', 'c', [(42, 46), (55, 59)])])
Exemple #11
0
 def test_calculate_offsets_pluralized1(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     text += " Many bands. "
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertItemsEqual(matches, [
         ('rock band', 'a', [(10, 19)]),
         ('band', 'b', [(30, 34)]),
         ('bands', 'b', [(66, 71)]),
         ('drum', 'c', [(42, 46), (55, 59)])])
 def test_calculate_offsets_pluralized1(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     text += " Many bands. "
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     six.assertCountEqual(
         self,
         matches,
         [('rock band', 'a', [(10, 19)]),
          ('band', 'b', [(30, 34)]),
          ('bands', 'b', [(66, 71)]),
          ('drum', 'c', [(42, 46), (55, 59)])])
 def test_calculate_offsets(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(3, len(matches))
     found = [False, False, False]
     for _, ref, offsets in matches:
         if ref == 'a' and offsets == [(10, 19)]:
             found[0] = True
         if ref == 'b' and offsets == [(30, 34)]:
             found[1] = True
         if ref == 'c' and offsets == [(42, 46), (55, 59)]:
             found[2] = True
     self.assertEqual([True, True, True], found)
 def test_calculate_offsets(self):
     applicable_terms = [('rock band', 'a'), ('band', 'b'), ('drum', 'c'),
                         ('other thing', 'd')]
     text = "I am in a rock band. That's a band with a drum, a rock drum."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(3, len(matches))
     found = [False, False, False]
     for _, ref, offsets in matches:
         if ref == 'a' and offsets == [(10, 19)]:
             found[0] = True
         if ref == 'b' and offsets == [(30, 34)]:
             found[1] = True
         if ref == 'c' and offsets == [(42, 46), (55, 59)]:
             found[2] = True
     self.assertEqual([True, True, True], found)
Exemple #15
0
 def test_calculate_offsets_singularized(self):
     applicable_terms = [('activities', 'a'), ('other thing', 'd')]
     text = "activity, activities."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(2, len(matches))
 def test_calculate_offsets_pluralized2(self):
     applicable_terms = [('activity', 'a'), ('other thing', 'd')]
     text = "activity, activities."
     t = Terms(None)
     matches = t.calculate_offsets(text, applicable_terms)
     self.assertEqual(2, len(matches))