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

fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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: