Beispiel #1
0
 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...')
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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>...'
         )
Beispiel #6
0
 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>...'
     )
Beispiel #7
0
 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)
Beispiel #8
0
 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...')
Beispiel #9
0
 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...')
Beispiel #10
0
 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)
Beispiel #11
0
 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)