def __init__(self, **kwargs): super(LogicAdapter, self).__init__(**kwargs) from chatterbot.comparisons import levenshtein_distance from chatterbot.response_selection import get_first_response # Import string module parameters if 'statement_comparison_function' in kwargs: import_path = kwargs.get('statement_comparison_function') if isinstance(import_path, str): kwargs['statement_comparison_function'] = import_module(import_path) if 'response_selection_method' in kwargs: import_path = kwargs.get('response_selection_method') if isinstance(import_path, str): kwargs['response_selection_method'] = import_module(import_path) # By default, compare statements using Levenshtein distance self.compare_statements = kwargs.get( 'statement_comparison_function', levenshtein_distance ) # By default, select the first available response self.select_response = kwargs.get( 'response_selection_method', get_first_response )
def __init__(self, chatbot, **kwargs): super().__init__(chatbot, **kwargs) from chatterbot.comparisons import levenshtein_distance from chatterbot.response_selection import get_first_response # Import string module parameters if 'statement_comparison_function' in kwargs: import_path = kwargs.get('statement_comparison_function') if isinstance(import_path, str): kwargs['statement_comparison_function'] = import_module( import_path) if 'response_selection_method' in kwargs: import_path = kwargs.get('response_selection_method') if isinstance(import_path, str): kwargs['response_selection_method'] = import_module( import_path) self.maximum_similarity_threshold = kwargs.get( 'maximum_similarity_threshold', 0.95) self.excluded_words = kwargs.get('excluded_words') self.search_page_size = kwargs.get('search_page_size', 1000) # By default, compare statements using Levenshtein distance self.compare_statements = kwargs.get('statement_comparison_function', levenshtein_distance) # By default, select the first available response self.select_response = kwargs.get('response_selection_method', get_first_response)
def __init__(self, **kwargs): super(LogicAdapter, self).__init__(**kwargs) from chatterbot.comparisons import levenshtein_distance from chatterbot.response_selection import get_first_response if 'tie_breaking_method' in kwargs: raise DeprecationWarning( 'The parameter "tie_breaking_method" has been removed. ' + 'Instead, pass a callable to "response_selection_method". ' + 'See documentation for details: ' + 'http://chatterbot.readthedocs.io/en/latest/logic/response_selection.html#setting-the-response-selection-method' ) # Import string module parameters if 'statement_comparison_function' in kwargs: import_path = kwargs.get('statement_comparison_function') if isinstance(import_path, str): kwargs['statement_comparison_function'] = import_module( import_path) if 'response_selection_method' in kwargs: import_path = kwargs.get('response_selection_method') if isinstance(import_path, str): kwargs['response_selection_method'] = import_module( import_path) # By default, compare statements using Levenshtein distance self.compare_statements = kwargs.get('statement_comparison_function', levenshtein_distance) # By default, select the first available response self.select_response = kwargs.get('response_selection_method', get_first_response)
def __init__(self, name, **kwargs): self.name = name storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') logic_adapters = kwargs.get('logic_adapters', [ 'chatterbot.logic.BestMatch' ]) # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) # Logic adapters used by the chat bot self.logic_adapters = [] self.storage = utils.initialize_class(storage_adapter, **kwargs) primary_search_algorithm = IndexedTextSearch(self, **kwargs) text_search_algorithm = TextSearch(self, **kwargs) self.search_algorithms = { primary_search_algorithm.name: primary_search_algorithm, text_search_algorithm.name: text_search_algorithm } for adapter in logic_adapters: utils.validate_adapter_class(adapter, LogicAdapter) logic_adapter = utils.initialize_class(adapter, self, **kwargs) self.logic_adapters.append(logic_adapter) preprocessors = kwargs.get( 'preprocessors', [ 'chatterbot.preprocessors.clean_whitespace' ] ) self.preprocessors = [] self.postprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor)) postprocessors = kwargs.get( 'postprocessors', [ 'chatterbot.postprocessors.joint_sentence' ] ) for postprocessor in postprocessors: self.postprocessors.append(utils.import_module(postprocessor)) self.logger = kwargs.get('logger', logging.getLogger(__name__)) # Allow the bot to save input it receives so that it can learn self.read_only = kwargs.get('read_only', False)
def __init__(self, name, **kwargs): self.name = name self.logger = kwargs.get( 'logger', log.Logger('chatterbot', costum_format='[%Y-%m-%d %H:%M:%S] chatterbot', debug=kwargs.get('debug', False))) storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') logic_adapters = kwargs.get('logic_adapters', ['chatterbot.logic.BestMatch']) # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) # Logic adapters used by the chat bot self.logic_adapters = [] self.storage = utils.initialize_class(storage_adapter, **kwargs) primary_search_algorithm = IndexedTextSearch(self, **kwargs) text_search_algorithm = TextSearch(self, **kwargs) self.search_algorithms = { primary_search_algorithm.name: primary_search_algorithm, text_search_algorithm.name: text_search_algorithm } for adapter in logic_adapters: utils.validate_adapter_class(adapter, LogicAdapter) logic_adapter = utils.initialize_class(adapter, self, **kwargs) self.logic_adapters.append(logic_adapter) preprocessors = kwargs.get( 'preprocessors', ['chatterbot.preprocessors.clean_whitespace']) self.preprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor)) self.trainer = ChatterBotCorpusTrainer(self) self.trainer.train("chatterbot.corpus.custom") log.add_logger('chatterbot', self.logger) self.this_file = os.path.dirname(__file__) self.learn_YAML = os.path.join( ''.join(os.path.split(self.this_file)[0]), 'chatterbot_corpus', 'data', 'custom', 'myown.yml') # Allow the bot to save input it receives so that it can learn self.read_only = kwargs.get('read_only', False)
def __init__(self, chatbot, **kwargs): super().__init__(chatbot, **kwargs) from chatterbot.comparisons import levenshtein_distance from chatterbot.response_selection import get_first_response # Import string module parameters if 'statement_comparison_function' in kwargs: import_path = kwargs.get('statement_comparison_function') if isinstance(import_path, str): kwargs['statement_comparison_function'] = import_module(import_path) if 'response_selection_method' in kwargs: import_path = kwargs.get('response_selection_method') if isinstance(import_path, str): kwargs['response_selection_method'] = import_module(import_path) self.maximum_similarity_threshold = kwargs.get( 'maximum_similarity_threshold', 0.95 ) self.excluded_words = kwargs.get('excluded_words') self.search_page_size = kwargs.get( 'search_page_size', 1000 ) # By default, compare statements using Levenshtein distance self.compare_statements = kwargs.get( 'statement_comparison_function', levenshtein_distance ) # By default, select the first available response self.select_response = kwargs.get( 'response_selection_method', get_first_response )
def __init__(self, chatbot, **kwargs): super().__init__(chatbot, **kwargs) from chatterbot.comparisons import levenshtein_distance from chatterbot.response_selection import get_first_response # Import string module parameters if 'statement_comparison_function' in kwargs: import_path = kwargs.get('statement_comparison_function') if isinstance(import_path, str): kwargs['statement_comparison_function'] = import_module( import_path) if 'response_selection_method' in kwargs: import_path = kwargs.get('response_selection_method') if isinstance(import_path, str): kwargs['response_selection_method'] = import_module( import_path) ''' The maximum amount of similarity between two statement that is required before the search process is halted. The search for a matching statement will continue until a statement with a greater than or equal similarity is found or the search set is exhausted. ''' self.maximum_similarity_threshold = kwargs.get( 'maximum_similarity_threshold', 0.95) # The maximum number of records to load into memory at a time when searching self.search_page_size = kwargs.get('search_page_size', 1000) # By default, compare statements using Levenshtein distance self.compare_statements = kwargs.get('statement_comparison_function', levenshtein_distance) # By default, select the first available response self.select_response = kwargs.get('response_selection_method', get_first_response)
def insert_logic_adapter(self, logic_adapter, insert_index, **kwargs): """ Adds a logic adapter at a specified index. :param logic_adapter: The string path to the logic adapter to add. :type logic_adapter: class :param insert_index: The index to insert the logic adapter into the list at. :type insert_index: int """ utils.validate_adapter_class(logic_adapter, LogicAdapter) NewAdapter = utils.import_module(logic_adapter) adapter = NewAdapter(**kwargs) self.adapters.insert(insert_index, adapter)
def insert_logic_adapter(self, logic_adapter, insert_index, **kwargs): """ Adds a logic adapter at a specified index. :param logic_adapter: The string path to the logic adapter to add. :type logic_adapter: str :param insert_index: The index to insert the logic adapter into the list at. :type insert_index: int """ utils.validate_adapter_class(logic_adapter, LogicAdapter) NewAdapter = utils.import_module(logic_adapter) adapter = NewAdapter(**kwargs) self.adapters.insert(insert_index, adapter)
def __init__(self, name, **kwargs): self.name = name # storge storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) # processors preprocessors = kwargs.get( 'preprocessors', ['chatterbot.PreProcessing.clean_whitespace']) self.preprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor))
def __init__(self, name, **kwargs): self.name = name storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') logic_adapters = kwargs.get('logic_adapters', [ 'chatterbot.logic.BestMatch' ]) # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) # Logic adapters used by the chat bot self.logic_adapters = [] self.storage = utils.initialize_class(storage_adapter, **kwargs) primary_search_algorithm = IndexedTextSearch(self, **kwargs) self.search_algorithms = { primary_search_algorithm.name: primary_search_algorithm } for adapter in logic_adapters: utils.validate_adapter_class(adapter, LogicAdapter) logic_adapter = utils.initialize_class(adapter, self, **kwargs) self.logic_adapters.append(logic_adapter) preprocessors = kwargs.get( 'preprocessors', [ 'chatterbot.preprocessors.clean_whitespace' ] ) self.preprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor)) self.logger = kwargs.get('logger', logging.getLogger(__name__)) # Allow the bot to save input it receives so that it can learn self.read_only = kwargs.get('read_only', False)
def test_import_module(self): datetime = utils.import_module('datetime.datetime') self.assertTrue(hasattr(datetime, 'now'))
def __init__(self, name, **kwargs): self.name = name storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') # These are logic adapters that are required for normal operation system_logic_adapters = kwargs.get('system_logic_adapters', ( 'chatterbot.logic.NoKnowledgeAdapter', )) logic_adapters = kwargs.get('logic_adapters', [ 'chatterbot.logic.BestMatch' ]) input_adapter = kwargs.get('input_adapter', 'chatterbot.input.InputAdapter') output_adapter = kwargs.get('output_adapter', 'chatterbot.output.OutputAdapter') # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) utils.validate_adapter_class(input_adapter, InputAdapter) utils.validate_adapter_class(output_adapter, OutputAdapter) # Logic adapters used by the chat bot self.logic_adapters = [] # Required logic adapters that must always be present self.system_logic_adapters = [] self.storage = utils.initialize_class(storage_adapter, **kwargs) self.input = utils.initialize_class(input_adapter, self, **kwargs) self.output = utils.initialize_class(output_adapter, self, **kwargs) # Add required system logic adapter for system_logic_adapter in system_logic_adapters: utils.validate_adapter_class(system_logic_adapter, LogicAdapter) logic_adapter = utils.initialize_class(system_logic_adapter, self, **kwargs) self.system_logic_adapters.append(logic_adapter) for adapter in logic_adapters: utils.validate_adapter_class(adapter, LogicAdapter) logic_adapter = utils.initialize_class(adapter, self, **kwargs) self.logic_adapters.append(logic_adapter) preprocessors = kwargs.get( 'preprocessors', [ 'chatterbot.preprocessors.clean_whitespace' ] ) self.preprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor)) self.logger = kwargs.get('logger', logging.getLogger(__name__)) # Allow the bot to save input it receives so that it can learn self.read_only = kwargs.get('read_only', False) if kwargs.get('initialize', True): self.initialize()
("policjantach", "Policjanci narażają swoje życie i zdrowie aby dbać o bezpieczeństwo obywateli."), ("policji", "Polska policja dba o bezpieczńestwo polaków."), ("strazakach", "Strażacy gaszą pożary, psik, psik."), (["500+", "programie 500+", "programie 500+"], "Program 500+ wspiera wiele polskich rodzin. Polega na tym, że zabiera się pieniądzie złodziejom i daje dzieciom. Poparcie Polaków wobec programu 500+ wynosi ponad 90% procent."), (["stacji tvp", "tvp"], "TVP to rzetelna i uczciwa telewizja, której misją jest informowanie o wiadomościach z kraju i krzewieniu kultury wśród polaków."), (["stacji tvn", "tvn"], "TVN to telewizja sponsorowana przez kapitał niemiecki."), (["pis", "partii pis"], "Partia Prawo i Sprawiedliwość dba o to aby Polska była krajem bogatym."), (["po", "partii po"], "Partia PO przez 8 lat swoich rządów doprowadziła Polskę do ruiny i zdradzała ją z Niemcami i Unią Europejską.") ] ) # Add input preprocessors after training. preprocessors = [ "chatterbot.preprocessors.clean_whitespace", "preprop.lowercased", "preprop.remove_accents", "preprop.filter_punctuation" ] bot.preprocessors = [] for preprocessor in preprocessors: bot.preprocessors.append(utils.import_module(preprocessor)) print("PiSior - Wirtualny asystent biura poselskiego kandydata na posła [...]. Jak mogę Ci pomóc?") while True: try: bot_input = bot.get_response(input("> ")) print(bot_input) except(KeyboardInterrupt, EOFError, SystemExit): break
def __init__(self, name, **kwargs): self.name = name storage_adapter = kwargs.get('storage_adapter', 'chatterbot.storage.SQLStorageAdapter') # These are logic adapters that are required for normal operation system_logic_adapters = kwargs.get( 'system_logic_adapters', ('chatterbot.logic.NoKnowledgeAdapter', )) logic_adapters = kwargs.get('logic_adapters', ['chatterbot.logic.BestMatch']) input_adapter = kwargs.get('input_adapter', 'chatterbot.input.InputAdapter') output_adapter = kwargs.get('output_adapter', 'chatterbot.output.OutputAdapter') # Check that each adapter is a valid subclass of it's respective parent utils.validate_adapter_class(storage_adapter, StorageAdapter) utils.validate_adapter_class(input_adapter, InputAdapter) utils.validate_adapter_class(output_adapter, OutputAdapter) # Logic adapters used by the chat bot self.logic_adapters = [] # Required logic adapters that must always be present self.system_logic_adapters = [] self.storage = utils.initialize_class(storage_adapter, **kwargs) self.input = utils.initialize_class(input_adapter, self, **kwargs) self.output = utils.initialize_class(output_adapter, self, **kwargs) # Add required system logic adapter for system_logic_adapter in system_logic_adapters: utils.validate_adapter_class(system_logic_adapter, LogicAdapter) logic_adapter = utils.initialize_class(system_logic_adapter, self, **kwargs) self.system_logic_adapters.append(logic_adapter) for adapter in logic_adapters: utils.validate_adapter_class(adapter, LogicAdapter) logic_adapter = utils.initialize_class(adapter, self, **kwargs) self.logic_adapters.append(logic_adapter) preprocessors = kwargs.get( 'preprocessors', ['chatterbot.preprocessors.clean_whitespace']) self.preprocessors = [] for preprocessor in preprocessors: self.preprocessors.append(utils.import_module(preprocessor)) self.logger = kwargs.get('logger', logging.getLogger(__name__)) # Allow the bot to save input it receives so that it can learn self.read_only = kwargs.get('read_only', False) if kwargs.get('initialize', True): self.initialize()