示例#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...')
示例#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)
示例#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)
示例#4
0
文件: tests.py 项目: slinkp/openblock
 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...'
     )
示例#5
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>...'
         )
示例#6
0
文件: tests.py 项目: slinkp/openblock
 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>...'
     )
示例#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)
示例#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...')
示例#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...')
示例#10
0
文件: tests.py 项目: slinkp/openblock
 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)
示例#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)