对于如何使用Python绘制Fry图和Raygor图的可读性,您有什么建议吗?目的:两个可读性公式都将在图表上直观地绘制等级。两条平行线之间的数字表示美国的年级水平,例如:https://readabilityformulas.com/freetests/fry-graph.php
以下代码用于计算公式:
import textstat
# raygor
raygor_of_keys = dict()
raygor_of_keys_to_ignore = dict()
from_y = 27
for y in range(3, 6):
for x in range(6, from_y):
raygor_of_keys_to_ignore[f"{y}:{x}"] = 0
from_y = from_y - 8
to_y = 44
for y in range(7, 29):
to_y = to_y - 1
for x in reversed(range(to_y, 45)):
raygor_of_keys_to_ignore[f"{y}:{x}"] = 0
raygor_number = 3
for y in range(3, 29):
if y % 2 == 0:
raygor_number = raygor_number + 1
for x in range(6, 45):
the_key = f"{y}:{x}"
if raygor_of_keys_to_ignore.get(the_key) == 0:
continue
raygor_of_keys[the_key] = raygor_number
def get_value_from_raygor_graph(y_value, x_value):
return raygor_of_keys.get(f"{y_value}:{x_value}", 0) * 2
# fry
fry_of_keys = dict()
fry_of_keys_to_ignore = dict()
from_y = 128
for y in range(2, 5):
for x in range(108, from_y):
fry_of_keys_to_ignore[f"{y}:{x}"] = 0
from_y = from_y - 8
to_y = 172
for y in range(7, 26):
to_y = to_y - 2
for x in reversed(range(to_y, 173)):
fry_of_keys_to_ignore[f"{y}:{x}"] = 0
fry_number = 1
for y in reversed(range(2, 26)):
if y % 2 == 0:
fry_number = fry_number + 1
for x in range(108, 173):
the_key = f"{y}:{x}"
if fry_of_keys_to_ignore.get(the_key) == 0:
continue
fry_of_keys[the_key] = fry_number
def get_value_from_fry_graph(y_value, x_value):
return fry_of_keys.get(f"{y_value}:{x_value}", 0)
def count_raygor_readability(data_list):
sentence_numbers = 0
words_count_bigger_six = 0
# computation
words_count = 0
for sentence in data_list:
sentence_numbers = sentence_numbers + 1
words_count = words_count + textstat.lexicon_count(sentence)
words_count_bigger_six = words_count_bigger_six + len([1 for n in sentence.split() if len(n) > 6])
if words_count >= 50:
break
# computation
words_count = 0
for sentence in reversed(data_list):
sentence_numbers = sentence_numbers + 1
words_count = words_count + textstat.lexicon_count(sentence)
words_count_bigger_six = words_count_bigger_six + len([1 for n in sentence.split() if len(n) > 6])
if words_count >= 50:
break
return get_value_from_raygor_graph(sentence_numbers, words_count_bigger_six)
def count_fry_readability(data_list):
sentence_numbers = 0
syllables_numbers = 0
# computation
words_count = 0
for sentence in data_list:
sentence_numbers = sentence_numbers + 1
syllables_numbers = syllables_numbers + textstat.syllable_count(sentence)
words_count = words_count + textstat.lexicon_count(sentence)
if words_count >= 150:
break
# computation
words_count = 0
for sentence in reversed(data_list):
sentence_numbers = sentence_numbers + 1
syllables_numbers = syllables_numbers + textstat.syllable_count(sentence)
words_count = words_count + textstat.lexicon_count(sentence)
if words_count >= 150:
break
avg_sentence_numbers = round(sentence_numbers / 3)
avg_syllables_numbers = round(syllables_numbers / 3)
return get_value_from_fry_graph(avg_sentence_numbers, avg_syllables_numbers)
text=" Your list is now clean enough that you can begin analyzing its contents in meaningful ways. Counting the frequency of specific words in the list can provide illustrative data. Python has an easy way to count frequencies, but it requires the use of a new type of variable: the dictionary. Before you begin working with a dictionary, consider the processes used to calculate frequencies in a list."
raygorReadability=count_raygor_readability(text)
fryReadability=count_fry_readability(text)
fryReadability
谢谢Sergey,我已经更新了链接。此外,我还试图策划它。但是,我在yticks有问题。刻度标签之间的间距不相等。以下代码用于绘制图Raygor Graph
相关问题 更多 >
编程相关推荐