Initial commit
This commit is contained in:
BIN
src/cow-color.png
Normal file
BIN
src/cow-color.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
47
src/masked.py
Executable file
47
src/masked.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Masked wordcloud
|
||||
================
|
||||
|
||||
Using a mask you can generate wordclouds in arbitrary shapes.
|
||||
"""
|
||||
|
||||
import os
|
||||
from os import path
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from wordcloud import STOPWORDS, ImageColorGenerator, WordCloud
|
||||
|
||||
# get data directory (using getcwd() is needed to support running example in generated IPython notebook)
|
||||
d = path.dirname(__file__) if "__file__" in locals() else os.getcwd()
|
||||
|
||||
# Read the whole text.
|
||||
text = open(path.join(d, "work.txt")).read()
|
||||
|
||||
# read the mask image
|
||||
# image from: https://all-free-download.com/free-vector/download/farm-cow-icon-colored-cartoon-sketch_6843157.html
|
||||
image_mask = np.array(Image.open(path.join(d, "cow-color.png")))
|
||||
image_colors = ImageColorGenerator(image_mask)
|
||||
|
||||
stopwords = set(STOPWORDS)
|
||||
stopwords.add("said")
|
||||
|
||||
wc = WordCloud(
|
||||
background_color="white",
|
||||
max_words=750,
|
||||
mask=image_mask,
|
||||
stopwords=stopwords,
|
||||
contour_width=3,
|
||||
color_func=image_colors,
|
||||
height=1080,
|
||||
width=1920,
|
||||
min_word_length=3,
|
||||
)
|
||||
|
||||
# generate word cloud
|
||||
wc.generate(text)
|
||||
|
||||
# store to file
|
||||
wc.to_file(path.join(d, "../cow-wordcloud.png"))
|
34
src/replacements.sed
Normal file
34
src/replacements.sed
Normal file
@ -0,0 +1,34 @@
|
||||
# Remove some HTML and markdown syntax stuff
|
||||
s/<code>//
|
||||
s/<file>//
|
||||
s_</code>__
|
||||
s_</file>__
|
||||
s/^```//
|
||||
s/^```console//
|
||||
/&&/d
|
||||
/|/d
|
||||
/-/d
|
||||
/{/d
|
||||
/^\*/d
|
||||
/^\#$/d
|
||||
/^\$$/d
|
||||
/log/d
|
||||
|
||||
# tease out some convoluted concepts
|
||||
s/^python$/Python/
|
||||
s/\[root/root/
|
||||
s/^Gluster$/GlusterFS/
|
||||
s_HTTP/1.1"_HTTP/1.1_
|
||||
s/[Ee]rror:/error/
|
||||
|
||||
# Anything with a comma or semi-colon at the end of the line
|
||||
s/[,:]$//
|
||||
s/\.$//
|
||||
s/\[Ansible/Ansible/
|
||||
s/^Ansible\?/Ansible/
|
||||
s/^Ansible\]\]/Ansible/
|
||||
s/^ansible$/Ansible/
|
||||
s/answer/Answer/
|
||||
|
||||
# delete blank lines last
|
||||
/^$/d
|
1298
src/stopwords-en.txt
Normal file
1298
src/stopwords-en.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user