OSDN Git Service

add dist
[rec10/rec10-git.git] / dist / trunk / rec10 / auto_rec.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 import n_gram
6 import rec10d
7 def getDBKey(key,chtxt):
8     return rec10d.rec10db.select_by_key_in_auto_bayes_key(key, chtxt)
9 def changeDBEpg(chtxt,beforenum,newnum):
10     rec10d.rec10db.change_ratio_all_reduce_in_auto_bayes_key(chtxt, beforenum, newnum)
11 def changeDBNum(chtxt,recaddnum,alladdnum):
12     """
13     add num.(Not change)
14     """
15     rec10d.rec10db.add_num_in_auto_bayes_key(chtxt, recaddnum,alladdnum)
16 def changeDBRatioRec(key,chtxt,beforenum,addnum):
17     rec10d.rec10db.change_ratio_rec_in_auto_bayes_key(key, chtxt, beforenum, addnum)
18 def changeDBRatioMultiRec(chtxt,beforenum,list):
19     rec10d.rec10db.change_multi_ratio_rec_in_auto_bayes_key(chtxt, beforenum, list)
20 def changeDBReduceRatioRec(chtxt,beforenum,addnum):
21     rec10d.rec10db.change_ratio_rec_reduce_in_auto_bayes_key(chtxt, beforenum, addnum)
22 def changeDBRatioAll(key,chtxt,beforenum,addnum):
23     rec10d.rec10db.change_ratio_all_in_auto_bayes_key(key, chtxt, beforenum, addnum)
24 def changeDBRatioMultiAll(chtxt,beforenum,list):
25     rec10d.rec10db.change_multi_ratio_all_in_auto_bayes_key(chtxt,beforenum, list)
26 def getDBNum(chtxt):
27     ret=getDBKey("NUM", chtxt)
28     if len(ret)<3:
29         rec10d.rec10db.add_in_auto_bayes_key("NUM", chtxt, 1,1)
30         ret=getDBKey("NUM", chtxt)
31     return ret
32 def updateRecall(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.getNounQuadGram(str1)
40     bnum=getDBNum(chtxt)[3]
41     if bnum<1:
42         bnum=100
43     changeDBRatioMultiAll(chtxt, bnum,noun)
44     changeDBEpg(chtxt, bnum, newnum)
45     changeDBNum(chtxt, 0, newnum)
46 def addKey(chtxt,title,desc):
47     title=u" "+title+u" "
48     desc=u" "+desc+u" "
49     str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
50     noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
51     bnum=getDBNum(chtxt)[2]
52     if bnum<1:
53         bnum=1
54     changeDBRatioMultiRec(chtxt, bnum, noun)
55     changeDBNum(chtxt,1,0)
56     changeDBReduceRatioRec(chtxt, bnum,1)
57 def calcKey(chtxt,title,desc):
58     """
59
60     """
61     title=u" "+title+u" "
62     desc=u" "+desc+u" "
63     str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
64     noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
65     tnum=1
66     nump=0
67     for key,num in noun.items():
68         pp=getDBKey(key,chtxt)
69         pp2=getDBKey(key,"ALL")
70         if len(pp)>3:
71             tarec=0
72             taall=0
73             if len(pp2)>3:
74                 tarec=pp2[2]
75                 taall=pp2[3]
76             trec=pp[2]
77             tall=pp[3]
78             
79             tnum=tnum+1
80             p=(1000*trec+5)/(1000*tall+5)
81             p=p*p*100
82             p2=(1000*tarec+5)/(1000*taall+5)
83             p2=p2*100
84             nump=nump+p+p2
85     return int(nump/tnum)