def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Programming", 0) self.all_keywords = registry.get("PP_all_keywords") self.language_keywords = registry.get("PP_language_keywords")
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Programming", 0) self.all_keywords = registry.get('PP_all_keywords') self.language_keywords = registry.get('PP_language_keywords')
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Measurement", 100) self.units = registry.get('MP_units') self.systems = registry.get('MP_systems') self.preposition_parser = registry.get('MP_preposition_parser') self.measurement_parser = registry.get('MP_measurement_parser')
class BaseParserTests(unittest.TestCase): """Unit Testing of the BaseParser""" bp = None def setUp(self): BaseParser.bootstrap(TestConfig()) self.bp = BaseParser(TestConfig()) def tearDown(self): self.bp = None def test_parse(self): self.assertRaises(NotImplementedError, self.bp.parse, "") def test_result(self): self.assertIsInstance(self.bp.result(), ParseResult)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Phone", 100)
def __init__(self, config): BaseParser.__init__(self, config, "Fake")
def __init__(self, config): BaseParser.__init__(self, config, "Programming", 0) self.all_keywords = registry.get('PP_all_keywords') self.language_keywords = registry.get('PP_language_keywords')
def __init__(self, config): BaseParser.__init__(self, config, "Equation", 100)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Boolean")
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Landmark", 100)
def __init__(self, config): BaseParser.__init__(self, config, "Postal Code", 100)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Coordinates", 100)
def setUp(self): BaseParser.bootstrap(TestConfig()) self.bp = BaseParser(TestConfig())
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Number", 100) def convert_to_literal(tok, val): """Converts a value to pyparsing caselessliteral""" return CaselessLiteral(tok) \ .setName(tok) \ .setParseAction(replaceWith(val)) self.defined_units = [ ("zero", 0), ("oh", 0), ("zip", 0), ("zilch", 0), ("nada", 0), ("bupkis", 0), ("one", 1), ("two", 2), ("three", 3), ("four", 4), ("five", 5), ("six", 6), ("seven", 7), ("eight", 8), ("nine", 9), ("ten", 10), ("eleven", 11), ("twelve", 12), ("thirteen", 13), ("fourteen", 14), ("fifteen", 15), ("sixteen", 16), ("seventeen", 17), ("eighteen", 18), ("nineteen", 19), ] self.defined_tens = [ ("ten", 10), ("twenty", 20), ("thirty", 30), ("forty", 40), ("fourty", 40), ("fifty", 50), ("sixty", 60), ("seventy", 70), ("eighty", 80), ("ninety", 90), ] self.defined_majors = [ ("thousand", int(1e3)), ("million", int(1e6)), ("billion", int(1e9)), ("trillion", int(1e12)), ("quadrillion", int(1e15)), ("quintillion", int(1e18)), ("sextillion", int(1e21)), ("septillion", int(1e24)), ("octillion", int(1e27)), ("nonillion", int(1e30)), ("decillion", int(1e33)), ("undecillion", int(1e36)), ("duodecillion", int(1e39)), ("tredicillion", int(1e42)), ("quattordecillion", int(1e45)), ("quattuordecillion", int(1e45)), ("quindecillion", int(1e48)), ("sexdecillion", int(1e51)), ("septendecillion", int(1e54)), ("octodecillion", int(1e57)), ("novemdecillion", int(1e60)), ("vigintillion", int(1e63)), ] self.units = Or( [convert_to_literal(s, v) for s, v in self.defined_units]) self.tens = Or( [convert_to_literal(s, v) for s, v in self.defined_tens]) self.hundreds = convert_to_literal("hundred", 100) self.majors = Or( [convert_to_literal(s, v) for s, v in self.defined_majors]) self.word_product = lambda t: functools.reduce(mul, t) self.word_sum = lambda t: sum(t) self.number_partial = ( (((self.units + Optional(self.hundreds)).setParseAction( self.word_product) + Optional(self.tens)).setParseAction( self.word_sum) ^ self.tens) + Optional(self.units)).setParseAction(self.word_sum) self.number_words = OneOrMore( (self.number_partial + Optional(self.majors)).setParseAction( self.word_product)).setParseAction( self.word_sum) + StringEnd() self.number_words.ignore(CaselessLiteral("-")) self.number_words.ignore(CaselessLiteral("and")) self.roman_numerals = [['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]]
def __init__(self, config): BaseParser.__init__(self, config, "Coordinates", 100)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Character", 25)
def __init__(self, config): BaseParser.__init__(self, config, "Character", 25)
def __init__(self, config): BaseParser.__init__(self, config, "URI", 100)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Address", 0)
def __init__(self, config): """ :param config: cahoots config :type config: cahoots.config.BaseConfig """ BaseParser.__init__(self, config, "Postal Code", 100)
def __init__(self, config): BaseParser.__init__(self, config, "Measurement", 100) self.units = registry.get('MP_units') self.systems = registry.get('MP_systems') self.preposition_parser = registry.get('MP_preposition_parser') self.measurement_parser = registry.get('MP_measurement_parser')
def __init__(self, config): BaseParser.__init__(self, config, "Date", 0)
def __init__(self, config): BaseParser.__init__(self, config, "Boolean")
def __init__(self, config): BaseParser.__init__(self, config, "Number", 100) def convert_to_literal(tok, val): """Converts a value to pyparsing caselessliteral""" return CaselessLiteral(tok) \ .setName(tok) \ .setParseAction(replaceWith(val)) self.defined_units = [ ("zero", 0), ("oh", 0), ("zip", 0), ("zilch", 0), ("nada", 0), ("bupkis", 0), ("one", 1), ("two", 2), ("three", 3), ("four", 4), ("five", 5), ("six", 6), ("seven", 7), ("eight", 8), ("nine", 9), ("ten", 10), ("eleven", 11), ("twelve", 12), ("thirteen", 13), ("fourteen", 14), ("fifteen", 15), ("sixteen", 16), ("seventeen", 17), ("eighteen", 18), ("nineteen", 19), ] self.defined_tens = [ ("ten", 10), ("twenty", 20), ("thirty", 30), ("forty", 40), ("fourty", 40), ("fifty", 50), ("sixty", 60), ("seventy", 70), ("eighty", 80), ("ninety", 90), ] self.defined_majors = [ ("thousand", int(1e3)), ("million", int(1e6)), ("billion", int(1e9)), ("trillion", int(1e12)), ("quadrillion", int(1e15)), ("quintillion", int(1e18)), ("sextillion", int(1e21)), ("septillion", int(1e24)), ("octillion", int(1e27)), ("nonillion", int(1e30)), ("decillion", int(1e33)), ("undecillion", int(1e36)), ("duodecillion", int(1e39)), ("tredicillion", int(1e42)), ("quattordecillion", int(1e45)), ("quattuordecillion", int(1e45)), ("quindecillion", int(1e48)), ("sexdecillion", int(1e51)), ("septendecillion", int(1e54)), ("octodecillion", int(1e57)), ("novemdecillion", int(1e60)), ("vigintillion", int(1e63)), ] self.units = Or( [convert_to_literal(s, v) for s, v in self.defined_units] ) self.tens = Or( [convert_to_literal(s, v) for s, v in self.defined_tens] ) self.hundreds = convert_to_literal("hundred", 100) self.majors = Or( [convert_to_literal(s, v) for s, v in self.defined_majors] ) self.word_product = lambda t: functools.reduce(mul, t) self.word_sum = lambda t: sum(t) self.number_partial = ( ( ( ( self.units + Optional(self.hundreds) ).setParseAction(self.word_product) + Optional(self.tens) ).setParseAction(self.word_sum) ^ self.tens ) + Optional(self.units)).setParseAction(self.word_sum) self.number_words = OneOrMore( (self.number_partial + Optional(self.majors)).setParseAction(self.word_product) ).setParseAction(self.word_sum) + StringEnd() self.number_words.ignore(CaselessLiteral("-")) self.number_words.ignore(CaselessLiteral("and")) self.roman_numerals = [ ['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1] ]
def __init__(self, config): BaseParser.__init__(self, config, "Landmark", 100)