def __init__(self, name, **kwargs): ChatBot.__init__(self, name=name, **kwargs) self.lp = LanguageProcessor() self.spell_checker = False # FIXME self.discord = False self.authors = [] self.interrupt = 0 self.report = False self.globals = { "emotion": Emotion.neutral, "history": {"total": [0], "user": [0], "types": [0]}, "reversei": { "enabled": False, "uid": None, "type": None, }, "akinator": {"enabled": False, "class": None}, "hangman": {"enabled": False, "class": None}, "adapters": [], "fun": True, "update": False, "last_news": None, "USERNAME": None, "learn": False, "trivia_answer": None, "learn_last_conversation": [], "DEBUG": {}, }
def __init__(self, name, **kwargs): ChatBot.__init__(self, name=name, **kwargs) self.lp = LanguageProcessor() self.spell_checker = False # FIXME self.discord = False self.authors = [] self.interrupt = 0 self.report = False self.globals = { 'emotion': Emotion.neutral, 'history': { 'total': [0], 'user': [0], 'types': [0] }, 'reversei': { 'enabled': False, 'uid': None, 'type': None, }, 'akinator': { 'enabled': False, 'class': None }, 'hangman': { 'enabled': False, 'class': None }, 'adapters': [], 'fun': True, 'update': False, 'last_news': None, 'USERNAME': None, 'learn': False, 'trivia_answer': None, 'learn_last_conversation': [], 'DEBUG': {} }
def reverse(token): """ Reverses the first person pronouns to second person pronouns and vice versa :param token: a nltk.word_tokenize type list :return: a list similar to nltk.word_tokenize """ processed = [] has_am = "am" in token has_is = "are" in token logging.info("Reverse: Received {}".format(token)) interrogation = False for i in token: lps = LanguageProcessor().tokenize(i)[0] if lps.tag_ == "." and lps.lower_ == "?": interrogation = True elif str(lps.tag_).startswith("W"): interrogation = True for i in token: tagged = nltk.pos_tag([i]) if tagged[0][1] == "PRP": if i == "you": if interrogation: processed.append("I") else: processed = processed[:-1] + ["I"] + processed[-1:] elif i.lower() == "i": processed.append("you") elif tagged[0][1] == "VBP": if i == "are": if "I" in processed: processed.append("am") else: processed.append("are") elif i == "am": if "I" in processed: processed.append("am") else: processed.append("are") else: processed.append("are") else: processed.append(i) for j in range(0, len(processed) - 2): if processed[j] == "I" and processed[j + 1] == "are": processed[j + 1] = "am" elif processed[j] == "you" and processed[j + 1] == "am": processed[j + 1] = "are" else: continue for j in range(0, len(processed) - 2): if processed[j] == "I" and processed[j + 1] == "are": processed[j] = "you" elif processed[j] == "you" and processed[j + 1] == "am": processed[j] = "I" else: continue for j in range(0, len(processed) - 2): if processed[j] == "are" and processed[j + 1] == "I": processed[j] = "am" elif processed[j] == "am" and processed[j + 1] == "you": processed[j] = "are" else: continue logging.info("Reverse: Pushing {}".format(processed)) return processed
if os.getenv('SUGAROID_DEBUG') in ('true', 'True'): # set the verbosity verbosity = logging.INFO logging.basicConfig(level=verbosity) try: from PyQt5 import QtCore, QtWidgets # noqa: from PyQt5.QtWidgets import QApplication # noqa: GUI_DEPS = True except (ModuleNotFoundError, ImportError) as e: print("warn: Could not import PyQt5", e) GUI_DEPS = False SPACY_LANG_PROCESSOR = LanguageProcessor() class SugaroidStatement(Statement): """ A modified chatterbot Statement with the additional parameters The Chatterbot Statement did not preserve the capabilities to hold fundamental data such as name of the adapter and emotion of the statemnt passed The emotion was either a <class 'Emotion'> type or NoneType The Adapter was the generic name of the adapter in string type determined by the __gtype__ variable """ def __init__(self, text, in_response_to=None, **kwargs): Statement.__init__(self, text, in_response_to, **kwargs) self.emotion = kwargs.get('emotion', Emotion.neutral) self.adapter = kwargs.get('type_', '')
def reverse(token): """ Reverses the first person pronouns to second person pronouns and vice versa :param token: a nltk.word_tokenize type list :return: a list similar to nltk.word_tokenize """ processed = [] has_am = 'am' in token has_is = 'are' in token logging.info("Reverse: Received {}".format(token)) interrogation = False for i in token: lps = LanguageProcessor().tokenize(i)[0] if lps.tag_ == '.' and lps.lower_ == '?': interrogation = True elif str(lps.tag_).startswith('W'): interrogation = True for i in token: tagged = nltk.pos_tag([i]) if tagged[0][1] == 'PRP': if i == 'you': if interrogation: processed.append('I') else: processed = processed[:-1] + ['I'] + processed[-1:] elif i.lower() == 'i': processed.append('you') elif tagged[0][1] == 'VBP': if i == 'are': if 'I' in processed: processed.append('am') else: processed.append('are') elif i == 'am': if 'I' in processed: processed.append('am') else: processed.append('are') else: processed.append('are') else: processed.append(i) for j in range(0, len(processed) - 2): if processed[j] == 'I' and processed[j + 1] == 'are': processed[j + 1] = 'am' elif processed[j] == 'you' and processed[j + 1] == 'am': processed[j + 1] = 'are' else: continue for j in range(0, len(processed) - 2): if processed[j] == 'I' and processed[j + 1] == 'are': processed[j] = 'you' elif processed[j] == 'you' and processed[j + 1] == 'am': processed[j] = 'I' else: continue for j in range(0, len(processed) - 2): if processed[j] == 'are' and processed[j + 1] == 'I': processed[j] = 'am' elif processed[j] == 'am' and processed[j + 1] == 'you': processed[j] = 'are' else: continue logging.info("Reverse: Pushing {}".format(processed)) return processed
from typing import List, Generator from chatterbot.conversation import Statement from spacy.tokens.doc import Doc from sugaroid.brain.postprocessor import random_response from sugaroid.brain.preprocessors import tokenize from sugaroid.brain.utils import LanguageProcessor lang_processor = LanguageProcessor() class SugaroidStatement(Statement): """ A modified chatterbot Statement with the additional parameters The Chatterbot Statement did not preserve the capabilities to hold fundamental data such as name of the adapter and emotion of the statement passed The emotion was either a <class 'Emotion'> type or NoneType The Adapter was the generic name of the adapter in string type determined by the __gtype__ variable """ def __init__(self, text: str, in_response_to=None, emotion: int = None, **kwargs): super(SugaroidStatement, self).__init__(text, in_response_to, **kwargs) self._doc = None self._simple = None self._words = None self._emotion = emotion self._text = text