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

fixes

Location:
atomisator/filters
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • atomisator/filters/BayesCore/classifier.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 
     
    6363        # XXX this will be cached 
    6464        probabilities = self._buildWordProbabilities() 
     65 
    6566        res = {} 
    6667        for category_name in probabilities: 
  • atomisator/filters/BayesCore/storage.py

    r97 r102  
    2525    def __init__(self, sqluri): 
    2626        self._words, self._catwords = self._get_mapper(sqluri) 
     27        self._sqluri = sqluri 
     28 
    2729        try: 
    2830            self._words.create() 
  • 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 
  • atomisator/filters/BayesCore/tokenizer/normalized.fr.txt

    r97 r102  
    22# will probably get TextIndexNG normalizer 
    33# collection next 
    4 # and be fine-tuned later 
    5 é e 
    6 è e 
    7 à a 
    8 ç c 
    9 ù u 
     4# and be fine-tuned later 
     5é e 
     6Ú e 
     7à a 
     8ç c 
     9ù u 
    1010# to be completed 
  • atomisator/filters/BayesCore/tokenizer/normalized.txt

    r97 r102  
    22# will probably get TextIndexNG normalizer 
    33# collection next 
    4 # and be fine-tuned later 
    5 é e 
    6 è e 
    7 à a 
    8 ç c 
    9 ù u 
     4# and be fine-tuned later 
     5é e 
     6Ú e 
     7à a 
     8ç c 
     9ù u 
    1010# to be completed 
  • atomisator/filters/bayes.py

    r99 r102  
    4949SQLURI = 'sqlite:///filters/BayesCore/data/bayes.db' 
    5050 
    51 def bayesian(entry, entries): 
     51def bayesian(entry, entries, sqluri=None): 
    5252    """uses bayesian inference over entries""" 
    5353    content = entry['content'].encode('utf8') 
     
    5959 
    6060    data = '%s %s' % (content, title) 
    61     classifier = BayesClassifier(LANG, SQLStorage(SQLURI), AllFilters()) 
     61 
     62    if sqluri is None: 
     63        sqluri = SQLURI 
     64 
     65    classifier = BayesClassifier(LANG, SQLStorage(sqluri), AllFilters()) 
    6266 
    6367    # let's test the entry 
     
    6771        return True 
    6872 
     73 
    6974    return  result[0][0] == 'nojunk' 
    7075 
    7176register_filter(bayesian) 
    7277 
    73 def bayesian_learn(entry): 
     78def bayesian_learn(entry, sqluri=None, answer=None): 
    7479    """uses bayesian inference over entries""" 
    7580    content = entry['content'].encode('utf8') 
     
    8085        title = '' 
    8186 
    82     print 'title : %s' % title 
     87 
     88    if sqluri is None: 
     89        sqluri = SQLURI 
    8390 
    8491    data = '%s %s' % (content, title) 
    85     classifier = BayesClassifier(LANG, SQLStorage(SQLURI), AllFilters()) 
    8692 
    87     res = raw_input("Interesting (type 'm' for more) ? (y/n)  ") 
    88     res = res.strip().lower() 
     93    classifier = BayesClassifier(LANG, SQLStorage(sqluri), AllFilters()) 
    8994 
    90     if res == 'm': 
    91         print content 
    92         res = raw_input("Interesting ? (y/n)  ") 
     95    if answer is None: 
     96        print 'title : %s' % title 
    9397 
     98        res = raw_input("Interesting (type 'm' for more) ? (y/n)  ") 
     99        answer = res.strip().lower() 
    94100 
    95     print 'Learning...' 
    96     if res.strip().lower() in ('y', 'yes'): 
     101        if answer == 'm': 
     102            print content 
     103            answer = raw_input("Interesting ? (y/n)  ") 
     104 
     105        print 'Learning...' 
     106 
     107    if answer.strip().lower() in ('y', 'yes'): 
    97108        classifier.learn(data, 'nojunk') 
    98109    else: