示例#1
0
文件: gui.py 项目: DiveFish/PythProj
def save_analysis_to_file():
    wr = open(fileName_analysis.get(), "w")
    tagged_file = read_file(directory.get())
    if not tagged_file:
        wr.write("ERROR: Empty file.")
    else:
        sent_length = sent_length_average(tagged_file)
        word_length = word_length_average(tagged_file)
        pron_count = count_pronouns_per_sentence(tagged_file)
        ttr = ttr_tagged_sents(tagged_file)
        wr.write("The average sentence length is "+str(sent_length)+"\n")
        wr.write("The average word length is "+str(word_length)+"\n")
        wr.write("The number of pronouns per number of sentences is "+str(pron_count)+"\n")
        wr.write("The type-token ratio is "+str(ttr)+"\n")
        trad_complexity = (sent_length+word_length)/2
        lex_complexity = (pron_count+(1/ttr))/2
        complexity = (sent_length+word_length+pron_count+(1/ttr))/4
        if complexity < 5:
            wr.write("->> The OVERALL COMPLEXITY of the given text is EASY \n")
        elif 5 <= complexity < 8:
            wr.write("->> The OVERALL COMPLEXITY of the given text is ADVANCED \n")
        else:
            wr.write("->> The OVERALL COMPLEXITY of the given text is DIFFICULT \n")
        wr.write("<-- The TRADITIONAL complexity is "+str(trad_complexity)+"\n")
        wr.write("<-- The LEXICAL complexity is "+str(lex_complexity)+"\n")
    wr.close()
示例#2
0
文件: gui.py 项目: DiveFish/PythProj
def print_analysis():
    tagged_file = read_file(directory.get())
    if not tagged_file:
        print "ERROR: Empty file."
    else:
        sent_length = sent_length_average(tagged_file)
        word_length = word_length_average(tagged_file)
        pron_count = count_pronouns_per_sentence(tagged_file)
        ttr = ttr_tagged_sents(tagged_file)
        print "The average sentence length is "+str(sent_length)
        print "The average word length is "+str(word_length)
        print "The number of pronouns per number of sentences is "+str(pron_count)
        print "The type-token ratio is "+str(ttr)
        trad_complexity = (sent_length+word_length)/2
        lex_complexity = (pron_count+(1/ttr))/2
        complexity = (sent_length+word_length+pron_count+(1/ttr))/4
        if complexity < 5:
            print "\033[1m ->> The overall complexity of the given text is easy \033[0m \n"
        elif 5 <= complexity < 8:
            print "\033[1m ->> The overall complexity of the given text is advanced \033[0m \n"
        else:
            print "\033[1m ->> The overall complexity of the given text is difficult \033[0m \n"
        print "<-- The TRADITIONAL complexity is "+str(trad_complexity)+"\n"
        print "<-- The LEXICAL complexity is "+str(lex_complexity)+"\n"