OSDN Git Service

implement bayeskey.
[rec10/rec10-git.git] / rec10 / trunk / src / auto_rec.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import n_gram
6 import rec10d
7 def get_db_key(key,chtxt):
8     return rec10d.rec10db.select_by_key_bayeskey(key, chtxt)
9 def change_db_epg(chtxt,beforenum,newnum):
10     rec10d.rec10db.change_ratio_all_reduce_bayeskey(chtxt, beforenum, newnum)
11 def change_db_num(chtxt,recaddnum,alladdnum):
12     rec10d.rec10db.add_num_bayeskey(chtxt, recaddnum,alladdnum)
13 def change_db_ratio_rec(key,chtxt,beforenum,addnum):
14     rec10d.rec10db.change_ratio_rec_bayeskey(key, chtxt, beforenum, addnum)
15 def change_db_ratio_all(key,chtxt,beforenum,addnum):
16     rec10d.rec10db.change_ratio_all_bayeskey(key, chtxt, beforenum, addnum)
17 def get_db_num(chtxt):
18     return get_db_key("NUM", chtxt)
19 def update_recall(chtxt,titles,descs,newnum):
20     titles=" "+titles+" "
21     descs=" "+descs+" "
22     str1=titles*2+descs+titles*2
23     noun=n_gram.get_noun_quad_gram(str1)
24     bnum=get_db_num(chtxt)[2]
25     for i,j in noun.items():
26         change_db_ratio_all(i,chtxt,bnum,j)
27     change_db_epg(chtxt, bnum, newnum)
28 def add_key(chtxt,title,desc):
29     title=" "+title+" "
30     desc=" "+desc+" "
31     str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
32     noun=n_gram.get_noun_quad_gram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
33     for i,j in noun.items():
34         change_db_ratio_rec(i,chtxt,bnum,j)
35     change_db_num(chtxt, 1, 0)
36
37