def test_bootstrapSetsUpClassifierAsExpected(self): ProgrammingBayesianClassifier.bootstrap(TestConfig) self.assertEqual( ZipFileStub.called, [ 'init-trainers.zip-r', 'namelist', 'read-foo.def', 'read-bar.def' ] ) self.assertTrue( ismethod(SimpleBayesStub.Tokenizer) or isfunction(SimpleBayesStub.Tokenizer) ) self.assertIsInstance(registry.get('PP_bayes'), SimpleBayesStub) self.assertEqual( SimpleBayesStub.Languages, { 'foo': 'foo.def-text', 'bar': 'bar.def-text' } )
def test_classifierProducesExpectedResult(self): ProgrammingBayesianClassifier.bootstrap(TestConfig) classifier = ProgrammingBayesianClassifier() result = classifier.classify('echo "Hello World";') self.assertEqual('echo "Hello World";', SimpleBayesStub.data_string) self.assertEqual('FooBar', result)
def test_classifierProducesExpectedResult(self): ProgrammingBayesianClassifier.bootstrap(TestConfig) classifier = ProgrammingBayesianClassifier() result = classifier.classify('echo "Hello World";') self.assertEqual('echo "Hello World";', SimpleBayesStub.data_string) self.assertEqual('FooBar', result)
def test_bootstrapSetsUpClassifierAsExpected(self): ProgrammingBayesianClassifier.bootstrap(TestConfig) self.assertEqual(ZipFileStub.called, [ 'init-trainers.zip-r', 'namelist', 'read-foo.def', 'read-bar.def' ]) self.assertTrue( ismethod(SimpleBayesStub.Tokenizer) or isfunction(SimpleBayesStub.Tokenizer)) self.assertIsInstance(registry.get('PP_bayes'), SimpleBayesStub) self.assertEqual(SimpleBayesStub.Languages, { 'foo': 'foo.def-text', 'bar': 'bar.def-text' })
def bootstrap(config): """Loads tokens from the yaml files on disk""" all_keywords = [] language_keywords = {} directory = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(directory, "languages/*.yaml") for file_path in glob.glob(path): with open(file_path, 'r') as language_file: language = yaml.load(language_file) all_keywords.extend(language['keywords']) language_keywords[language['id']] = language registry.set('PP_all_keywords', set(all_keywords)) registry.set('PP_language_keywords', language_keywords) ProgrammingBayesianClassifier.bootstrap(config)
def bootstrap(config): """ This method is statically called to bootstrap a parser :param config: cahoots config :type config: cahoots.config.BaseConfig """ all_keywords = [] language_keywords = {} directory = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(directory, "languages/*.yaml") for file_path in glob.glob(path): with open(file_path, "r") as language_file: language = yaml.load(language_file) all_keywords.extend(language["keywords"]) language_keywords[language["id"]] = language registry.set("PP_all_keywords", set(all_keywords)) registry.set("PP_language_keywords", language_keywords) ProgrammingBayesianClassifier.bootstrap(config)
def bootstrap(config): """ This method is statically called to bootstrap a parser :param config: cahoots config :type config: cahoots.config.BaseConfig """ all_keywords = [] language_keywords = {} directory = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(directory, "languages/*.yaml") for file_path in glob.glob(path): with open(file_path, 'r') as language_file: language = yaml.load(language_file) all_keywords.extend(language['keywords']) language_keywords[language['id']] = language registry.set('PP_all_keywords', set(all_keywords)) registry.set('PP_language_keywords', language_keywords) ProgrammingBayesianClassifier.bootstrap(config)