def change_db_epg(chtxt,beforenum,newnum):
rec10d.rec10db.change_ratio_all_reduce_bayeskey(chtxt, beforenum, newnum)
def change_db_num(chtxt,recaddnum,alladdnum):
+ """
+ add num.(Not change)
+ """
rec10d.rec10db.add_num_bayeskey(chtxt, recaddnum,alladdnum)
def change_db_ratio_rec(key,chtxt,beforenum,addnum):
rec10d.rec10db.change_ratio_rec_bayeskey(key, chtxt, beforenum, addnum)
def change_db_ratio_all(key,chtxt,beforenum,addnum):
rec10d.rec10db.change_ratio_all_bayeskey(key, chtxt, beforenum, addnum)
+def change_db_ratio_all_many(chtxt,beforenum,list):
+ rec10d.rec10db.change_many_ratio_all_bayeskey(chtxt,beforenum, list)
def get_db_num(chtxt):
- return get_db_key("NUM", chtxt)
+ ret=get_db_key("NUM", chtxt)
+ if len(ret)<3:
+ rec10d.rec10db.add_bayeskey("NUM", chtxt, 1,1)
+ ret=get_db_key("NUM", chtxt)
+ return ret
def update_recall(chtxt,titles,descs,newnum):
+ """
+ update recall
+ """
titles=" "+titles+" "
descs=" "+descs+" "
str1=titles*2+descs+titles*2
noun=n_gram.get_noun_quad_gram(str1)
bnum=get_db_num(chtxt)[2]
- for i,j in noun.items():
- change_db_ratio_all(i,chtxt,bnum,j)
+ if bnum<1:
+ bnum=100
+ change_db_ratio_all_many(chtxt, bnum,noun)
change_db_epg(chtxt, bnum, newnum)
+ change_db_num(chtxt, 0, newnum)
def add_key(chtxt,title,desc):
title=" "+title+" "
desc=" "+desc+" "
for i,j in noun.items():
change_db_ratio_rec(i,chtxt,bnum,j)
change_db_num(chtxt, 1, 0)
+def calc_key(chtxt,title,desc):
+ """
-
+ """
+ kyoukai=600
+ kyoukai_num=30
+ title=" "+title+" "
+ desc=" "+desc+" "
+ str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。
+ noun=n_gram.get_noun_quad_gram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。
+ tnum=0
+ for key,num in noun.items():
+ pp=get_db_key(key,chtxt)
+ trec=pp[2]
+ tall=pp[3]
+ if tall<trec:
+ p=1000*trec/(3*tall+trec)
+ if p>kyoukai:
+ tnum=tnum+1
+ difp=trec-tall+difp*tnum
+ tnum=tnum+1
+ if kyoukai_num<tnum:
+ return 1
+ else:
+ return 0