Source code for sugaroid.brain.whoami

from chatterbot.logic import LogicAdapter
from nltk import pos_tag

from sugaroid.brain.constants import WHO_AM_I, WHO_ARE_YOU, SUGAROID
from sugaroid.brain.ooo import Emotion
from sugaroid.brain.postprocessor import random_response
from sugaroid.brain.preprocessors import normalize
from sugaroid.core.statement import SugaroidStatement
from sugaroid.version import VERSION


[docs]class WhoAdapter(LogicAdapter): """ Handles statements with 'who' as one of the tokens """ def __init__(self, chatbot, **kwargs): super().__init__(chatbot, **kwargs)
[docs] def can_process(self, statement): self.normalized = normalize(str(statement)) self.token = pos_tag(self.normalized) if "who" in self.normalized: return True else: return False
[docs] def process(self, statement, additional_response_selection_parameters=None): confidence = 0.95 # FIXME Creates unusual response if "do you know" in str(statement).lower(): if self.normalized[0] == "do": self.normalized.pop(0) if self.normalized[0] == "you": self.normalized.pop(0) if self.normalized[0] == "know": self.normalized.pop(0) if "i" in self.normalized: response = random_response(WHO_AM_I) elif "you" in self.normalized: if "to" in self.normalized: confidence = 0.5 response = "You!" else: v = VERSION response = "\n{} \n{}. \nBuild: {}".format( SUGAROID[0], random_response(WHO_ARE_YOU), v ) else: response = "check the wiki" confidence = 0 selected_statement = SugaroidStatement(response, chatbot=True) selected_statement.confidence = confidence emotion = Emotion.neutral selected_statement.emotion = emotion return selected_statement