def test_empty_phrases(self): # Make sure an empty phrase list doesn't result in matching everything phrases = [] text = 'In Lake View East today, a Lake View man...' tag = phrase_tagger(phrases) self.assertEqual(tag(text), 'In Lake View East today, a Lake View man...')
def tag_data(data): phrases = [p['name'] for p in field.lookup_set.values('name')] classes.extend(['locationdetected', 'field-%s' % index]) pre = '<a href="#" class="%s" field="%s-input">' % (' '.join(classes), field.name) post = '</a>' tag_phrases = phrase_tagger(phrases, pre, post) return tag_phrases(data)
def test_double_matching(self): # Make sure matching behaves as greedily as possible places = ['Lake View', 'Lake View East'] text = 'In Lake View East today, a Lake View man...' tag = phrase_tagger(places) self.assertEqual( tag(text), 'In <span>Lake View East</span> today, a <span>Lake View</span> man...' )
def test_matched_phrases_middle__loose(self): # DO tag things already tagged if paranoid=False. phrases = ['South Chicago'] text = 'on the <addr>7400 block of South Chicago Ave</addr>...' tag = phrase_tagger(phrases, pre='<addr>', post='</addr>', paranoid=False) self.assertEqual( tag(text), 'on the <addr>7400 block of <addr>South Chicago</addr> Ave</addr>...' )
def test_matched_phrases_middle(self): # Don't try to re-highlight things that have already been highlighted phrases = ['South Chicago'] text = 'on the <addr>7400 block of South Chicago Ave</addr>...' tag = phrase_tagger(phrases, pre='<addr>', post='</addr>') self.assertEqual(tag(text), text)
def test_double_matching(self): # Make sure matching behaves as greedily as possible places = ['Lake View', 'Lake View East'] text = 'In Lake View East today, a Lake View man...' tag = phrase_tagger(places) self.assertEqual(tag(text), 'In <span>Lake View East</span> today, a <span>Lake View</span> man...')
def test_matched_phrases_end(self): # Don't try to re-highlight things that have already been highlighted phrases = ["South Chicago"] text = "on the <addr>7400 block of South Chicago</addr>..." tag = phrase_tagger(phrases, pre="<addr>", post="</addr>") self.assertEqual(tag(text), text)