【发布时间】:2020-11-01 08:33:38
【问题描述】:
def calculate_frequencies(file_contents):
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his", "her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are", "was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with", "from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no", "nor", "too", "very", "can", "will", "just"]
# LEARNER CODE START HERE
dict1=[]
d ={}
for words in file_contents.split():
if words.isalpha() and words.lower() not in uninteresting_words:
dict1.append(words.lower())
for words in dict1:
if words not in d:
d[words] =0
d[words]+=file_contents.split().count(words)
return d
#wordcloud
cloud = WordCloud(width=900,height=500, max_words=1628,relative_scaling=1,normalize_plurals=False)
cloud.generate_from_frequencies(calculate_frequencies)
return cloud.to_array()`enter code here`)
【问题讨论】:
标签: word-cloud