X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;ds=sidebyside;f=rec10%2Ftrunk%2Fsrc%2Fauto_rec.py;h=5e4b8d5e35def0590a18583f6044169fd29c7adb;hb=12414a3ba81d93316e351ab51aa49bb71cf42f60;hp=f8728a52c76102af8dd0acf2720504b355e690b2;hpb=6e33eea27f09d6a76e2a73e7a7137a2c6ca56120;p=rec10%2Frec10-git.git diff --git a/rec10/trunk/src/auto_rec.py b/rec10/trunk/src/auto_rec.py index f8728a5..5e4b8d5 100644 --- a/rec10/trunk/src/auto_rec.py +++ b/rec10/trunk/src/auto_rec.py @@ -1,37 +1,85 @@ #!/usr/bin/python # coding: UTF-8 # Rec10 TS Recording Tools -# Copyright (C) 2009 Yukikaze +# Copyright (C) 2009-2011 Yukikaze import n_gram import rec10d -def get_db_key(key,chtxt): - return rec10d.rec10db.select_by_key_bayeskey(key, chtxt) -def change_db_epg(chtxt,beforenum,newnum): - rec10d.rec10db.change_ratio_all_reduce_bayeskey(chtxt, beforenum, newnum) -def change_db_num(chtxt,recaddnum,alladdnum): - 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 get_db_num(chtxt): - return get_db_key("NUM", chtxt) -def update_recall(chtxt,titles,descs,newnum): +def getDBKey(key,chtxt): + return rec10d.rec10db.select_by_key_in_auto_bayes_key(key, chtxt) +def changeDBEpg(chtxt,beforenum,newnum): + rec10d.rec10db.change_ratio_all_reduce_in_auto_bayes_key(chtxt, beforenum, newnum) +def changeDBNum(chtxt,recaddnum,alladdnum): + """ + add num.(Not change) + """ + rec10d.rec10db.add_num_in_auto_bayes_key(chtxt, recaddnum,alladdnum) +def changeDBRatioRec(key,chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_rec_in_auto_bayes_key(key, chtxt, beforenum, addnum) +def changeDBRatioMultiRec(chtxt,beforenum,list): + rec10d.rec10db.change_multi_ratio_rec_in_auto_bayes_key(chtxt, beforenum, list) +def changeDBReduceRatioRec(chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_rec_reduce_in_auto_bayes_key(chtxt, beforenum, addnum) +def changeDBRatioAll(key,chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_all_in_auto_bayes_key(key, chtxt, beforenum, addnum) +def changeDBRatioMultiAll(chtxt,beforenum,list): + rec10d.rec10db.change_multi_ratio_all_in_auto_bayes_key(chtxt,beforenum, list) +def getDBNum(chtxt): + ret=getDBKey("NUM", chtxt) + if len(ret)<3: + rec10d.rec10db.add_in_auto_bayes_key("NUM", chtxt, 1,1) + ret=getDBKey("NUM", chtxt) + return ret +def updateRecall(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) - change_db_epg(chtxt, bnum, newnum) -def add_key(chtxt,title,desc): - title=" "+title+" " - desc=" "+desc+" " + noun=n_gram.getNounQuadGram(str1) + bnum=getDBNum(chtxt)[3] + if bnum<1: + bnum=100 + changeDBRatioMultiAll(chtxt, bnum,noun) + changeDBEpg(chtxt, bnum, newnum) + changeDBNum(chtxt, 0, newnum) +def addKey(chtxt,title,desc): + title=u" "+title+u" " + desc=u" "+desc+u" " str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。 - noun=n_gram.get_noun_quad_gram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。 - for i,j in noun.items(): - change_db_ratio_rec(i,chtxt,bnum,j) - change_db_num(chtxt, 1, 0) - + noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。 + bnum=getDBNum(chtxt)[2] + if bnum<1: + bnum=1 + changeDBRatioMultiRec(chtxt, bnum, noun) + changeDBNum(chtxt,1,0) + changeDBReduceRatioRec(chtxt, bnum,1) +def calcKey(chtxt,title,desc): + """ + """ + title=u" "+title+u" " + desc=u" "+desc+u" " + str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。 + noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。 + tnum=1 + nump=0 + for key,num in noun.items(): + pp=getDBKey(key,chtxt) + pp2=getDBKey(key,"ALL") + if len(pp)>3: + tarec=0 + taall=0 + if len(pp2)>3: + tarec=pp2[2] + taall=pp2[3] + trec=pp[2] + tall=pp[3] + + tnum=tnum+1 + p=(1000*trec+5)/(1000*tall+5) + p=p*p*100 + p2=(1000*tarec+5)/(1000*taall+5) + p2=p2*100 + nump=nump+p+p2 + return int(nump/tnum)