OSDN Git Service

0d21b1890a26d18683d2ca4548918e6f048626ae
[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_in_auto_bayes_key(key, chtxt)
9 def change_db_epg(chtxt,beforenum,newnum):
10     rec10d.rec10db.change_ratio_all_reduce_in_auto_bayes_key(chtxt, beforenum, newnum)
11 def change_db_num(chtxt,recaddnum,alladdnum):
12     """
13     add num.(Not change)
14     """
15     rec10d.rec10db.add_num_in_auto_bayes_key(chtxt, recaddnum,alladdnum)
16 def change_db_ratio_rec(key,chtxt,beforenum,addnum):
17     rec10d.rec10db.change_ratio_rec_in_auto_bayes_key(key, chtxt, beforenum, addnum)
18 def change_db_ratio_rec_many(chtxt,beforenum,list):
19     rec10d.rec10db.change_multi_ratio_rec_in_auto_bayes_key(chtxt, beforenum, list)
20 def change_db_reduce_ratio_rec(chtxt,beforenum,addnum):
21     rec10d.rec10db.change_ratio_rec_reduce_in_auto_bayes_key(chtxt, beforenum, addnum)
22 def change_db_ratio_all(key,chtxt,beforenum,addnum):
23     rec10d.rec10db.change_ratio_all_in_auto_bayes_key(key, chtxt, beforenum, addnum)
24 def change_db_ratio_all_many(chtxt,beforenum,list):
25     rec10d.rec10db.change_multi_ratio_all_in_auto_bayes_key(chtxt,beforenum, list)
26 def get_db_num(chtxt):
27     ret=get_db_key("NUM", chtxt)
28     if len(ret)<3:
29         rec10d.rec10db.add_in_auto_bayes_key("NUM", chtxt, 1,1)
30         ret=get_db_key("NUM", chtxt)
31     return ret
32 def update_recall(chtxt,titles,descs,newnum):
33     """
34     update recall
35     """
36     titles=" "+titles+" "
37     descs=" "+descs+" "
38     str1=titles*2+descs+titles*2
39     noun=n_gram.get_noun_quad_gram(str1)
40     bnum=get_db_num(chtxt)[3]
41     if bnum<1:
42         bnum=100
43     change_db_ratio_all_many(chtxt, bnum,noun)
44     change_db_epg(chtxt, bnum, newnum)
45     change_db_num(chtxt, 0, newnum)
46 def add_key(chtxt,title,desc):
47     title=u" "+title+u" "
48     desc=u" "+desc+u" "
49     str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
50     noun=n_gram.get_noun_quad_gram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
51     bnum=get_db_num(chtxt)[2]
52     if bnum<1:
53         bnum=1
54     change_db_ratio_rec_many(chtxt, bnum, noun)
55     change_db_num(chtxt,1,0)
56     change_db_reduce_ratio_rec(chtxt, bnum,1)
57 def calc_key(chtxt,title,desc):
58     """
59
60     """
61     kyoukai=800
62     title=u" "+title+u" "
63     desc=u" "+desc+u" "
64     str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
65     noun=n_gram.get_noun_quad_gram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
66     tnum=1
67     nump=0
68     for key,num in noun.items():
69         pp=get_db_key(key,chtxt)
70         pp2=get_db_key(key,"ALL")
71         if len(pp)>3:
72             trec=pp[2]
73             tall=pp[3]
74             tarec=pp2[2]
75             taall=pp2[3]
76             tnum=tnum+1
77             p=(1000*trec+5)/(1000*tall+5)
78             p=p*p*100
79             p2=(1000*tarec+5)/(1000*taall+5)
80             p2=p2*100
81             nump=nump+p+p2
82     if (nump/tnum)>kyoukai:
83         return 1
84     else:
85         return 0