Ejemplo n.º 1
0
def cal_words_entirety(filename):
    string = getfilestr(filename)
    lentotal = len(string)
    letterdic = NGram(string,1).table
    worddic = WFreq(filename).get_word_frequency()

    entirety = Entirety(letterdic,worddic,lentotal)
    table = copy.deepcopy(worddic)
    for key in table:
        table[key] = entirety.cal_entirety(key) + math.log(worddic[key]/lentotal)
    
    return table
Ejemplo n.º 2
0
def cal_ngram_entirety(filename,n):
    string = getfilestr(filename)
    lentotal = len(string)
    letterdic = NGram(string,1).table
    worddic = NGram(string,n).table

    entirety = Entirety(letterdic,worddic,lentotal)
    table = copy.deepcopy(worddic)
    for key in table:
        table[key] = entirety.cal_entirety(key) + math.log(worddic[key]/lentotal)
    
    return table