How to use the chatterbot.languages function in ChatterBot

To help you get started, we’ve selected a few ChatterBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gunthercox / ChatterBot / tests / test_languages.py View on Github external
def test_classes_have_correct_attributes(self):
        language_classes = languages.get_language_classes()

        for name, obj in language_classes:
            self.assertTrue(inspect.isclass(obj))
            self.assertTrue(hasattr(obj, 'ISO_639'))
            self.assertTrue(hasattr(obj, 'ISO_639_1'))
            self.assertTrue(hasattr(obj, 'ENGLISH_NAME'))
            self.assertEqual(name, obj.ISO_639.upper())

        self.assertEqual(len(language_classes), 402)
github gunthercox / ChatterBot / tests / test_tagging.py View on Github external
def test_tagging_german(self):
        self.tagger = tagging.PosLemmaTagger(
            language=languages.GER
        )

        tagged_text = self.tagger.get_text_index_string(
            'Ich spreche nicht viel Deutsch.'
        )

        self.assertEqual(tagged_text, 'VERB:deutsch')
github gunthercox / ChatterBot / tests / test_tagging.py View on Github external
def test_tagging_english(self):
        self.tagger = tagging.PosLemmaTagger(
            language=languages.ENG
        )

        tagged_text = self.tagger.get_text_index_string(
            'Hello, how are you doing on this awesome day?'
        )

        self.assertEqual(tagged_text, 'INTJ:awesome ADJ:day')
github gunthercox / chatterbot-corpus / tests / test_data.py View on Github external
def test_language_names(self):
        """
        Each language directroy should adhere to the same nameing convention.
        """
        valid_language_names = []
        language_classes = inspect.getmembers(sys.modules[languages.__name__])

        for _name, obj in language_classes:
            if inspect.isclass(obj):
                valid_language_names.append(obj.ENGLISH_NAME.lower())

        for directory_name in os.listdir(DATA_DIRECTORY):
            self.assertIn(directory_name, valid_language_names)
github gunthercox / ChatterBot / tests / test_comparisons.py View on Github external
def setUp(self):
        super().setUp()

        self.compare = comparisons.SpacySimilarity(
            language=languages.ENG
        )
github gunthercox / ChatterBot / chatterbot / storage / storage_adapter.py View on Github external
def __init__(self, *args, **kwargs):
        """
        Initialize common attributes shared by all storage adapters.
        """
        self.logger = kwargs.get('logger', logging.getLogger(__name__))

        self.tagger = PosHypernymTagger(language=kwargs.get(
            'tagger_language', languages.ENG
        ))
github gunthercox / ChatterBot / chatterbot / logic / mathematical_evaluation.py View on Github external
def __init__(self, chatbot, **kwargs):
        super().__init__(chatbot, **kwargs)

        self.language = kwargs.get('language', languages.ENG)
        self.cache = {}
github gunthercox / ChatterBot / chatterbot / storage / storage_adapter.py View on Github external
def __init__(self, *args, **kwargs):
        """
        Initialize common attributes shared by all storage adapters.

        :param str tagger_language: The language that the tagger uses to remove stopwords.
        """
        self.logger = kwargs.get('logger', logging.getLogger(__name__))

        Tagger = kwargs.get('tagger', PosLemmaTagger)

        self.tagger = Tagger(language=kwargs.get(
            'tagger_language', languages.ENG
        ))
github gunthercox / ChatterBot / chatterbot / logic / unit_conversion.py View on Github external
def __init__(self, chatbot, **kwargs):
        super().__init__(chatbot, **kwargs)
        from pint import UnitRegistry

        self.language = kwargs.get('language', languages.ENG)
        self.cache = {}
        self.patterns = [
            (
                re.compile(r'''
                   (([Hh]ow\s+many)\s+
                   (?P\S+)\s+ # meter, celsius, hours
                   ((are)*\s*in)\s+
                   (?P([+-]?\d+(?:\.\d+)?)|(a|an)|(%s[-\s]?)+)\s+
                   (?P\S+)\s*) # meter, celsius, hours
                   ''' % (parsing.numbers),
                    (re.VERBOSE | re.IGNORECASE)
                ),
                lambda m: self.handle_matches(m)
            ),
            (
                re.compile(r'''
github gunthercox / ChatterBot / chatterbot / tagging.py View on Github external
def __init__(self, language=None):
        import spacy

        self.language = language or languages.ENG

        self.punctuation_table = str.maketrans(dict.fromkeys(string.punctuation))

        self.nlp = spacy.load(self.language.ISO_639_1.lower())