本文整理汇总了Python中wordcloud.STOPWORDS.add方法的典型用法代码示例。如果您正苦于以下问题:Python STOPWORDS.add方法的具体用法?Python STOPWORDS.add怎么用?Python STOPWORDS.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordcloud.STOPWORDS
的用法示例。
在下文中一共展示了STOPWORDS.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wordcloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def wordcloud(datafile):
#remove stop words, the most common words in a language
vectorizer=CountVectorizer(stop_words='english')
for word in vectorizer.get_stop_words():
STOPWORDS.add(word)
STOPWORDS.add("said")
pony_mask = np.array(Image.open("../pinkyB.jpg"))
wc = WordCloud(background_color="black", max_words=2000, mask=pony_mask, stopwords=STOPWORDS)
#init dictionary with the five categories
categoriesSet = set(datafile["Category"])
categoriesDict = dict.fromkeys(categoriesSet,"")
#Conditional Selection
# business = datafile.ix[datafile["Category"]=="Business"]
# print business["Content"].size
#fill index with data from cv
for index, row in datafile.iterrows():
categoriesDict[row["Category"]] += str(row["Content"])
for category, text in categoriesDict.iteritems():
wc.generate(text)
image = wc.to_image()
image.save("../wordcloud/wordcloud_" + category + ".jpg")
return
示例2: wordCloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def wordCloud(text_array,name,keyword=""):
new_text_arr=[]
if keyword is not "":
keyword=keyword.split(" ")[1]
for text in text_array:
if keyword in text:
new_text_arr.append(text)
text_array=new_text_arr
cloud_text=""
for text in text_array:
cloud_text+=text+" "
m_stopwords=['police','traffic','sir']
for word in m_stopwords:
STOPWORDS.add(word)
image_mask = os.path.join(BASE_DIR, 'static/tool/img/nebula.png')
coloring = imread(image_mask)
wordcloud = WordCloud(stopwords=STOPWORDS,background_color="white",mask=coloring,ranks_only=True,max_words=50).generate(cloud_text)
filename=os.path.join(BASE_DIR, 'static/tool/img/'+name+'.png')
image_colors = ImageColorGenerator(coloring)
wordcloud.recolor(color_func=image_colors)
wordcloud.to_file(filename)
data_uri = open(filename, 'rb').read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/png;base64,{0}" style="height:400px;">'.format(data_uri)
layout=wordcloud.layout_
words_colours={}
count=1
for lo in layout:
entry={}
entry['word']=lo[0][0]
color=lo[len(lo)-1]
color=color[4:]
color=color[:-1]
color_split=color.split(',')
color_num=[int(x) for x in color_split]
color_hex='#%02x%02x%02x' % tuple(color_num)
# print color_num
entry['color']=color_hex
words_colours[count]=entry
count+=1
# print words_colours
list_html=""
cap=51
if cap>len(words_colours):
cap=len(words_colours)
for i in range(1,cap):
list_html+='<li class="list-group-item" ><a class="cloud-key-'+name+'" href="#" style="color:'+words_colours[i]['color']+'">'
list_html+="#"+str(i)+" "+words_colours[i]['word']+'</a></li>'
return (img_tag,list_html)
示例3: generateWordCloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def generateWordCloud(text, stop):
d = path.dirname(outputdir)
for w in stop:
STOPWORDS.add(w)
# Generate the wordcloud without the stop words
wordcloud = WordCloud(stopwords=STOPWORDS).generate(text)
# Draw the positioned words to a PNG file.
wordcloud.to_file(path.join(d, 'diabetes-wordcloud.png'))
示例4: cloudplot
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def cloudplot(person):
person = re.sub(r'\+', ' ', person)
text = GetTextRange(Emails, person)
text = rmBoring(rmNonAlpha(text)).decode('ascii', 'ignore')
plt.clf()
d = path.dirname(path.abspath(__file__))
hilcolor = np.array(Image.open(path.join(d, "static/img/hillarylogo.jpg")))
wc = WordCloud(background_color="white", max_words=150, mask=hilcolor,
stopwords=STOPWORDS.add("said"),
max_font_size=80, random_state=42,
relative_scaling = 0.5)
wc.generate(text)
image_colors = ImageColorGenerator(hilcolor)
plt.imshow(wc.recolor(color_func=image_colors))
plt.axis("off")
fig = plt.gcf()
img = StringIO.StringIO()
fig.savefig(img)
img.seek(0)
return send_file(img, mimetype='image/png')
示例5: create_wordcloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def create_wordcloud(posts):
wordcloud_str=' '.join(post['message'] for post in posts) #join all posts together
aces_mask=imread("aces.png") #add aces mask
wc=WordCloud(background_color="BLACK", mask=aces_mask, stopwords=STOPWORDS.add("will")) #don't include the word "will" in the wordcloud
#(not an interesting word and took up a large chunk of the wordcloud)
wc.generate(wordcloud_str)
plt.axis("off")
plt.imshow(wc)
plt.show()
wc.to_file("aces_wordcloud.png")
示例6: generate_wc
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def generate_wc(content):
path = r'fzzqhj.TTF'
bg_pic = imread('mo.png') # 读取一张图片文件
image_colors = ImageColorGenerator(bg_pic) # 从背景图片生成颜色值
wc = WordCloud(font_path=path, background_color="white",
mask=bg_pic,
stopwords=STOPWORDS.add("said"),
max_font_size=40,
color_func=image_colors,
random_state=42)
wc = wc.generate(content)
wc.to_file(c.outputs_pictures_path + 'result.jpg')
示例7: make_word_cloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def make_word_cloud(data):
text = ''
for d in data:
text = text + d[0] + ' '
# Generate a word cloud image
wordcloud = WordCloud(stopwords=STOPWORDS.add('watson')).generate(text)
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
示例8: mainProcess
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def mainProcess(usernames):
print "Processing "+str(len(usernames)-1)+" usernames"
words4=""
loginFacebook(driver)
timeread=time.time()
time0=time.clock()
for username in usernames:
if len(username) is not 0:
username=username.strip()
time1=time.clock()
count, words3 =produce3(username)
module.Database.edit2(username, count, conn)
time2=time.clock()
words4=words4+" "+words3
time3=time.clock()
timeread=time.time()-timeread
print "TOTAL TIME"
print time3-time0
print timeread
more_stopwords =["ja", "aga", "kui", "siis", "tongue", "nii", "ka", "et", "see", "ma","oma","oli", "emoticon", "ei","ning", "seda", "või", "smile", "grin", "Kas", "kes", "veel"]
for more in more_stopwords:
STOPWORDS.add(more)
utf=["Translation", "nüüd", "või", "ära", "Kas"]
for u in utf:
words4=words4.replace(u, "")
wordcloud = WordCloud(stopwords=STOPWORDS).generate(words4)
image = wordcloud.to_image()
image.save("words.png","PNG")
driver.close()
driver.quit
conn.commit()
conn.close()
print "Done"
示例9: create_cloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def create_cloud(word, img, out_path):
# Read the whole text.
# text = open(word_path).read()
text = word.read().decode('utf-8')
# read the mask image
# taken from
# http://www.stencilry.org/stencils/movies/alice%20in%20wonderland/255fk.jpg
alice_mask = np.array(Image.open(img))
# alice_mask = np.array(img_path)
wc = WordCloud(font_path = '华文黑体.ttf' ,background_color="white", max_words=2000, mask=alice_mask,
stopwords=STOPWORDS.add("said"), width=1000, height=2300, ranks_only=True, mode='RGBA')
# generate word cloud
wc.generate(text)
# wc.generate_from_frequencies([()])
# store to file
wc.to_file(out_path)
示例10: WordCloudTopic
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def WordCloudTopic( items , imagePath = None):
# Generate a word cloud image
if imagePath:
alice_coloring = np.array(Image.open(imagePath))
wc = WordCloud(background_color="white", max_words=200, mask=alice_coloring,
stopwords=STOPWORDS.add("said"),
max_font_size=300)
# generate word cloud
wc.generate_from_frequencies(items)
image_colors = ImageColorGenerator(alice_coloring)
plt.imshow(wc.recolor(color_func=image_colors))
else:
wc = WordCloud(background_color="white", max_words=300,
max_font_size=40, random_state=42)
wordcloud = wc.generate_from_frequencies(items)
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
示例11: generate_wc
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def generate_wc(text = "Hello World"):
#if int(time.time()*10)%10 in [0]:
d = path.dirname(__file__)
# read the mask image
alice_coloring = np.array(Image.open(path.join(d, '..','static','images',"heart.png")))
wc = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,
stopwords=STOPWORDS.add("said"),
max_font_size=40, random_state=42)
# generate word cloud
wc.generate(text)
# generate word cloud image and save it
filename = "wordcloud.png"
wc.to_file(path.join(d,'..','static','images',filename))
del wc
return filename
示例12: main
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def main():
parser = argparse.ArgumentParser(description='Generate word cloud')
parser.add_argument('artist', help='Artist to be searched')
args = parser.parse_args()
artist = string_to_url(args.artist)
#artist = "Gaslight Anthem"
api_url = "http://lyrics.wikia.com/api.php?func=getArtist&artist=%s&fmt=realjson" % (artist, )
data = json.load(urllib2.urlopen(api_url))
art_data = data['albums']
songs_by_album = [album['songs'] for album in art_data]
songs = sum(songs_by_album, [])
lyrics = ""
for song in songs:
song = song.strip(bad_chars)
lyrics += get_lyrics(string_to_url(song), artist)
wc = WordCloud(background_color="white", max_words=2000,stopwords=STOPWORDS.add("said"))
if not args.sum:
wc.generate(lyrics)
wc.to_file("%s_%s.png" %(artist,song,))
示例13: wordcloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def wordcloud(wordSource):
#writes origional catagory list to text file
d = os.path.dirname(__file__)
file = open("catagory.txt", 'w')
for item in wordSource:
file.write("%s\n" % item)
thefile = open(os.path.join(d, "catagory.txt")).read()
#adds words to exclude list
STOPWORDS.add("chronic")
STOPWORDS.add("disease")
STOPWORDS.add("obstructive")
STOPWORDS.add("status")
# generate word cloud
wordcloud = WordCloud(stopwords=STOPWORDS,
background_color="white",
width = 650,
height = 250).generate_from_text(thefile)
#re-colers and saves wordcloud as png
wordcloud.recolor(color_func=grey_color_func, random_state=3)
wordcloud.to_file("wordcloud.png")
示例14: cloud_word_with_mask
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def cloud_word_with_mask(file_name):
text = open(file_name).read()
# read the mask / color image
# amazon_coloring = imread('amazon-logo_grey.png')
wc = WordCloud(background_color="white", max_words=200, #mask=amazon_coloring,
stopwords=STOPWORDS.add("said"),
max_font_size=200, random_state=42, width=1800, height=1000)
# generate word cloud
wc.generate(text)
# create coloring from image
# image_colors = ImageColorGenerator(amazon_coloring)
# recolor wordcloud and show
# we could also give color_func=image_colors directly in the constructor
# plt.imshow(wc.recolor(color_func=image_colors))
plt.figure()
plt.imshow(wc)
plt.axis("off")
# plt.show()
plt.savefig(file_name.split('.')[0] + '.png')
示例15: generateWordcloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import add [as 别名]
def generateWordcloud(wordlist, outfile, title, nwords=100):
"""
:param wordlist: words in a list
:param outfile: name of the output file to which to store the figure
:param title: title of the figure
:param nwords: maximum number of words to plot
:return: None
"""
# generate word cloud
wc = WordCloudSMN(background_color="white", max_words=nwords,
width=800, height=400,
stopwords=STOPWORDS.add("looking"),
max_font_size=80, random_state=42)
wc.generate_SMN(wordlist)
# generate the figure
plt.figure(figsize=(16, 16))
plt.title(title)
plt.imshow(wc)
plt.axis("off")
plt.savefig(outfile)
plt.close()