Exemplo n.º 1
0
 def __init__(self, language='de'):
     self._parser = EnglishParser(language)
     self.map = {
         'und': 'AND',
         'oder': 'OR',
         'nahe': 'NEAR',
         'nicht': 'NOT',
     }
     self.map_keys = self.map.keys()
Exemplo n.º 2
0
class GermanParser:

    implements(IParser)

    def __init__(self, language='de'):
        self._parser = EnglishParser(language)
        self.map = {
            'und': 'AND',
            'oder': 'OR',
            'nahe': 'NEAR',
            'nicht': 'NOT',
        }
        self.map_keys = self.map.keys()

    def getLanguage(self):
        return self._parser.getLanguage()

    def parse(self, query):
        words = query.split(' ')

        lst = []
        inside_quotes = False
        for w in words:

            if '"' in w:
                if inside_quotes:
                    inside_quotes = False
                else:
                    inside_quotes = True

            if not inside_quotes:
                if w.lower() in self.map_keys:
                    w = self.map[w.lower()]
                elif '::' in w:

                    for k, v in self.map.items():
                        x = '::' + k
                        if x.lower() in w.lower():
                            w = w.replace(x, '::' + v)
                            w = w.replace(x.upper(), '::' + v)
                            break

            lst.append(w)

        query = ' '.join(lst)
        return self._parser.parse(query)