Skip to content

Commit

Permalink
added custom stopwords in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-chs committed Oct 18, 2023
1 parent a62aa00 commit 157f02d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"wordcloud": {
"font": "RobotoSlab-Thin",
"colormap": "prism"
"colormap": "prism",
"custom_stopwords": "file, use"
},
"node": {},
"conversation_set": {}
Expand Down
13 changes: 11 additions & 2 deletions controllers/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ def wordcloud_from_text(
**kwargs: Any,
) -> WordCloud:
"""Creates a wordcloud from the given text. Returns a WordCloud object."""
custom_stopwords: list[str] = kwargs.get("stopwords", [])
default_stopwords: set[str] = load_nltk_stopwords()
stop_words: set[str] = default_stopwords.union(set(custom_stopwords))

custom_stopwords: str = kwargs.get("custom_stopwords", "")
custom_stopwords_list: list[str] = (
custom_stopwords.split(sep=",") if custom_stopwords else []
)
custom_stopwords_list = [
word.strip().lower() for word in custom_stopwords_list if word.strip()
]

stop_words: set[str] = default_stopwords.union(set(custom_stopwords_list))

background_color = kwargs.get("background_color", None)
if background_color is None:
mode = kwargs.get("mode", "RGBA")
Expand Down
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ def main() -> None:
wordcloud_folder.mkdir(parents=True, exist_ok=True)

font_path: str = f"assets/fonts/{configs_dict['wordcloud']['font']}.ttf"
colormap = configs_dict["wordcloud"]["colormap"]
colormap: str = configs_dict["wordcloud"]["colormap"]
custom_stopwords: str = configs_dict["wordcloud"]["custom_stopwords"]

generate_all_wordclouds(
conv_set=all_conversations_set,
dir_path=wordcloud_folder,
font_path=font_path,
colormap=colormap,
custom_stopwords=custom_stopwords,
)

print(f"\nDone ✅ ! Check the output 🔡☁️ here : {wordcloud_folder.as_uri()} 🔗\n")
Expand Down
8 changes: 7 additions & 1 deletion views/prompt_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def validate_header(string: str) -> bool:
"""Returns True if the given text is a valid markdown header."""
return (
1 <= string.count(x="#") <= 6
1 <= string.count("#") <= 6
and string.startswith("#")
and string[len(string.split()[0])] == " "
)
Expand Down Expand Up @@ -125,6 +125,12 @@ def prompt_user(default_configs: dict[str, Any]) -> dict[str, Any]:
style=custom_style,
).ask()

user_configs["wordcloud"]["custom_stopwords"] = text(
message="Enter custom stopwords (separated by commas) :",
default=default_configs["wordcloud"]["custom_stopwords"],
style=custom_style,
).ask()

# ------------------ node ---------------------

user_configs["node"] = {}
Expand Down

0 comments on commit 157f02d

Please sign in to comment.