Beispiel #1
0
 def _add_emapa_highlights(self, terms, termSearch):
     """
     add term_highlight and synonym_highlight to each term in terms
     """
     
     # prepare search tokens for highlighting
     termSearchTokens = splitSemicolonInput(termSearch)
                 
     # prepare term_highlight and synonym_highlight
     #    only set synonym_highlight if there is no highlight
     #    on the term
     for term in terms:
         setattr(term, "term_highlight", "")
         setattr(term, "synonym_highlight", "")
         
         term.term_highlight = highlightEMAPA(term.term, termSearchTokens)
         
         # if term could not be highlighted, try synonyms
         if '<mark>' not in term.term_highlight:
             for synonym in term.synonyms:
             
                 # try to highlight each synonym
                 synonym_highlight = highlightEMAPA(synonym.synonym, termSearchTokens)
                 
                 if '<mark>' in synonym_highlight:
                     # set first synonym match and exit
                     term.synonym_highlight = synonym_highlight
                     break
Beispiel #2
0
 def test_highlight_insensitive_ends(self):
     hl = highlightEMAPA("testing TEST", ["%test"])
     expected = "testing %s" % (self.expectedHighlight("TEST"))
     self.assertEquals(expected, hl) 
Beispiel #3
0
 def test_highlight_insensitive_begins(self):
     hl = highlightEMAPA("Testing test", ["test%"])
     expected = "%sing test" % (self.expectedHighlight("Test"))
     self.assertEquals(expected, hl) 
Beispiel #4
0
 def test_highlight_mixed_tokens_different_order(self):
     hl = highlightEMAPA("testing test2", ["%test2%", "testing test2"])
     expected = "testing %s" % (self.expectedHighlight("test2"))
     self.assertEquals(expected, hl)
Beispiel #5
0
 def test_highlight_mixed_tokens(self):
     hl = highlightEMAPA("testing test2", ["testing test2", "%test2%"])
     expected = self.expectedHighlight("testing test2")
     self.assertEquals(expected, hl)
Beispiel #6
0
 def test_highlight_wildcard_contains_match(self):
     hl = highlightEMAPA("testing test", ["%test%"])
     expected = "%sing %s" % (self.expectedHighlight("test"), self.expectedHighlight("test"))
     self.assertEquals(expected, hl)
Beispiel #7
0
 def test_highlight_wildcard_ends_match(self):
     hl = highlightEMAPA("testing test", ["%test"])
     expected = "testing %s" % self.expectedHighlight("test")
     self.assertEquals(expected, hl)
Beispiel #8
0
 def test_highlight_wildcard_begins_match(self):
     hl = highlightEMAPA("testing test", ["test%"])
     expected = "%sing test" % self.expectedHighlight("test")
     self.assertEquals(expected, hl)
Beispiel #9
0
 def test_highlight_multi_word_match(self):
     hl = highlightEMAPA("testing test", ["testing test"])
     expected = self.expectedHighlight("testing test")
     self.assertEquals(expected, hl)
Beispiel #10
0
 def test_highlight_empty(self):
     self.assertEquals("test", highlightEMAPA("test",[""]))