Exemplo n.º 1
0
 def _match(self, search_terms, content, operator):
     content = content.lower()
     content = Tools.strReplace(content, self.REPL_MAP)
     word_list = content.split(' ')
     word_list = [Tools.chop(w, '#') for w in word_list]
     search_terms = [s.lower().encode('unicode_escape') for s in search_terms]
     match = False
     matches = list()
     for st in search_terms:
         search_str = st.replace('*', str())
         # search if search term contains a whitespace
         if ' ' in st:
             regexp = re.compile(r'({0})'.format(st), re.I)
             match = True if len(re.findall(regexp, content)) > 0 else False
         # search if wildcard search in the end
         elif st.endswith('*'):
             match_list = [x for x in word_list if x.startswith(search_str)]
             match = True if len(match_list) > 0 else False
         # search if wildcard search in front
         elif st.startswith('*'):
             match_list = [x for x in word_list if x.endswith(search_str)]
             match = True if len(match_list) > 0 else False
         # search if exact match is true
         elif self.exact_match:
             match = True if search_str in word_list else False
         # search with exact match is false
         else:
             match = True if search_str in str(word_list) else False
         matches.append(match)
     match = all(matches) if operator == 'AND' else any(matches)
     return match
Exemplo n.º 2
0
 def normalizeFilename(self, filename):
     self.CHAR_REPLACEMENT_MAP.update(self.UMLAUT_REPL_MAP)
     return Tools.strReplace(filename, self.CHAR_REPLACEMENT_MAP, lowercase=False)