728x90
import nltk
from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet
from nltk.tokenize import word_tokenize
class Chatbot:
def __init__(self):
self.lemmatizer = WordNetLemmatizer()
def get_wordnet_pos(self, word):
tag = nltk.pos_tag([word])[0][1][0].upper()
tag_dict = {"J": wordnet.ADJ,
"N": wordnet.NOUN,
"V": wordnet.VERB,
"R": wordnet.ADV}
return tag_dict.get(tag, wordnet.NOUN)
def lemmatize_sentence(self, sentence):
lemmatized_sentence = []
for word, tag in nltk.pos_tag(word_tokenize(sentence)):
lemmatized_sentence.append(self.lemmatizer.lemmatize(word, self.get_wordnet_pos(word)))
return " ".join(lemmatized_sentence)
def get_response(self, sentence):
lemmatized_sentence = self.lemmatize_sentence(sentence)
# Use NLTK to classify the intent and entities of the sentence
intent = self.classify_intent(lemmatized_sentence)
entities = self.extract_entities(lemmatized_sentence)
# Use the intent and entities to generate a response
return self.generate_response(intent, entities)
728x90
'호그와트' 카테고리의 다른 글
깔끔한 쨰각째각 (0) | 2023.01.28 |
---|---|
너무나 아름다운 논리 (0) | 2023.01.27 |
가나다라마바사 (0) | 2023.01.21 |
오랜만에 아주 쉬운 거 (0) | 2023.01.18 |
파이썬 백준 2484 깔끔한 해결 (0) | 2023.01.17 |