Skip to content

Commit

Permalink
fixed some imports
Browse files Browse the repository at this point in the history
  • Loading branch information
principle105 committed Sep 8, 2022
1 parent 7817c3e commit 4041f85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ pip install thomasthechatbot
## Basic Usage

```py
from ttc import Chatbot, Context
from ttc.utils import download_nltk_data
from ttc import Chatbot, Context, download_nltk_data

# Only needs to be run once (can be removed after first run)
download_nltk_data()

# Creating the context
ctx = Context()

# Initializing the chatbot
chatbot = Chatbot()

talk = True
Expand Down
1 change: 1 addition & 0 deletions ttc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .chatbot import *
from .utils import *
12 changes: 8 additions & 4 deletions ttc/chatbot/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@

import contractions
from nltk import pos_tag, word_tokenize
from nltk.corpus import stopwords, wordnet
from nltk.stem.wordnet import WordNetLemmatizer

if TYPE_CHECKING:
from .context import Context

# Constants
DEFAULT_STORAGE_PATH = "storage"
STOP_WORDS = set(stopwords.words("english"))


def _load_json_file(path: str, name: str) -> dict:
Expand Down Expand Up @@ -238,6 +235,9 @@ def __init__(
mesh_association: float = 0.6,
):

from nltk.corpus import stopwords
from nltk.stem.wordnet import WordNetLemmatizer

# The path to the storage directory
self.path = path or DEFAULT_STORAGE_PATH

Expand All @@ -255,7 +255,11 @@ def __init__(
self.tag_map = self.create_tag_map()
self.wl = WordNetLemmatizer()

self.all_stop_words = set(stopwords.words("english"))

def create_tag_map(self):
from nltk.corpus import wordnet

tag_map = defaultdict(lambda: wordnet.NOUN)
tag_map["J"] = wordnet.ADJ
tag_map["V"] = wordnet.VERB
Expand Down Expand Up @@ -284,7 +288,7 @@ def separate_tokens(self, raw_tokens: list):

# Separating stop words
for w in self.lemmatize_tokens(raw_tokens):
if w in STOP_WORDS:
if w in self.all_stop_words:
stop_words.add(w)
else:
# Stemming helps with matching key words
Expand Down

0 comments on commit 4041f85

Please sign in to comment.