Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Les principaux changements sont dans le dossier `build`
- Loading branch information
1 parent
04f8b8f
commit 8166e22
Showing
12 changed files
with
921 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
Sys.setenv(HUGO_IGNOREERRORS = "error-remote-getjson", | ||
HUGO_BASEURL = "/", | ||
#HUGO_BASEURL = "https://linogaliana-teaching.netlify.app/", | ||
HUGO_RELATIVEURLS = "false", | ||
BLOGDOWN_POST_RELREF = "true", | ||
BLOGDOWN_SERVING_DIR = here::here()) | ||
|
||
cmd = blogdown:::find_hugo() | ||
cmd_args = c("--themesDir themes", "-t github.com")#, "--gc")#, "--minify") | ||
system2(cmd, cmd_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,67 @@ | ||
import glob | ||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
import wordcloud | ||
import numpy as np | ||
import PIL | ||
import io | ||
import requests | ||
import random | ||
import re | ||
|
||
list_files = glob.glob("./content/course/**/*.Rmd", recursive=True) | ||
import nltk | ||
from nltk.corpus import stopwords | ||
nltk.download('stopwords') | ||
stop_words = set(stopwords.words('french')) | ||
|
||
filename = list_files[0] | ||
list_files = glob.glob("./temp/course/**/*.Rmd", recursive=True) | ||
|
||
with open(filename, encoding='utf-8') as f: | ||
content = f.readlines() | ||
|
||
book_mask = np.array(PIL.Image.open("./build/python_black.png")) | ||
|
||
|
||
def read_file(filename): | ||
with open(filename, 'r', encoding='utf-8') as f: | ||
text = f.readlines() | ||
f.close() | ||
new_text = " ".join([line for line in text]) | ||
s = new_text | ||
return s | ||
|
||
def grey_color_func(word, font_size, position, orientation, random_state=None, | ||
**kwargs): | ||
return "hsl(0, 0%%, %d%%)" % random.randint(60, 100) | ||
|
||
def make_wordcloud(corpus): | ||
wc = wordcloud.WordCloud(mask=book_mask, max_words=2000, margin=10, contour_width=3, contour_color='white') | ||
wc.generate(corpus).recolor(color_func=grey_color_func, random_state=3) | ||
return wc | ||
|
||
def keep_text_within_shortword(shortcode): | ||
return re.sub(re.compile("(\{\{).*(\}\}\\n)|(\\n\{\{).*(\}\})"),"",shortcode) | ||
|
||
def clean_file(text): | ||
text = " ".join(text).lower() | ||
s = keep_text_within_shortword(text) | ||
# REMOVE R CHUNKS ------ | ||
s = re.sub(r'(?s)(```\{r)(.*?)(```)', "", s) | ||
s = re.sub(r'`', '', s) | ||
return s | ||
|
||
list_content = [read_file(fl) for fl in list_files] | ||
|
||
corpus = clean_file(text = list_content) | ||
|
||
corpus = corpus.split(" ") | ||
corpus = [w for w in corpus if not w in stop_words] | ||
#corpus = [word for word in corpus if word.isalpha()] | ||
corpus = " ".join(corpus) | ||
|
||
fig = plt.figure() | ||
|
||
plt.imshow(make_wordcloud(corpus), interpolation='bilinear') | ||
plt.axis("off") | ||
plt.tight_layout() | ||
plt.savefig('./content/home/word.png', bbox_inches='tight', pad_inches = 0, dpi=199) | ||
|
||
|
||
content |
Oops, something went wrong.