Show
Ignore:
Timestamp:
05/30/07 16:47:14 (20 months ago)
Author:
Tarek Ziad?? <tarek@…>
Message:

fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • atomisator/filters/BayesCore/tokenizer/filters.py

    r97 r102  
    1 # -*- coding: iso-8859-15 -*- 
     1# -*- coding: utf8 -*- 
    22# Copyright (c) 2006 Nuxeo SAS <http://nuxeo.com> 
    3 # Authors : Tarek Ziadé <tziade@nuxeo.com> 
     3# Authors : Tarek Ziadé <tziade@nuxeo.com> 
    44# This program is free software; you can redistribute it and/or modify 
    55# it under the terms of the GNU General Public License version 2 as published 
     
    4343 
    4444    def transform(self, text, options): 
    45         tokenizers = ('splitter', 'stopwords', 'normalizer', 'stemmer') 
     45        tokenizers = ('normalizer', 'splitter', 'stopwords', 'stemmer') 
    4646        return applyFilters(tokenizers, text, options) 
    4747 
     
    6161            self.charset = options['charset'] 
    6262        else: 
    63             self.charset = 'ISO-8859-15' 
     63            self.charset = 'utf8' 
    6464 
    6565    def getFinalState(self, result): 
     
    7676    name = 'splitter' 
    7777 
    78     char_list = ',;:/\'"#?!.-=+_`|()[]{}<>~&§%' 
     78    char_list = ',;:/\'"#?!.-=+_`|()[]{}<>~&§%' 
    7979 
    8080    def getName(self): 
     
    108108                                           Splitter().split(text)]) 
    109109 
    110         text = ''.join([self._cleanChar(char) for char in text]) 
     110        #text = ''.join([self._cleanChar(char) for char in text]) 
     111        text = ' '.join(text) 
     112 
     113        for char in self.char_list: 
     114            text = text.replace(char, ' ') 
    111115 
    112116        result = text.split() 
     
    124128 
    125129    name = 'stopwords' 
     130    treshold = 2 
    126131 
    127132    def getName(self): 
     
    152157        lang = options['lang'] 
    153158        stopwords = self._getStopWords(lang) 
    154         return [word for word in text if word not in stopwords] 
     159        return [word for word in text if (word not in stopwords 
     160                and len(word) > self.treshold)] 
    155161 
    156162registerFilter(StopWords()) 
     
    190196            else: 
    191197                return car 
    192         normalized = [normalized(car) for car in word] 
    193         return ''.join(normalized) 
     198 
     199        #normalized = [normalized(car) for car in word] 
     200        for car in normalizer: 
     201            word = word.replace(car, normalizer[car]) 
     202 
     203        return word 
     204        #''.join(normalized) 
    194205 
    195206    def transform(self, text, options): 
     
    222233 
    223234    name = 'stemmer' 
    224     charset = 'ISO-8859-15' 
     235    charset = 'utf8' 
    225236 
    226237    def getName(self): 
     
    262273        def checktype(element): 
    263274            if isinstance(element, str): 
    264                 return element.decode(charset) 
     275                return element.decode(charset, 'replace') 
    265276            return element 
    266277 
     
    281292 
    282293registerFilter(Stemmer()) 
     294