Ejemplo n.º 1
0
def execute(arguments):
    # Setup the configuration file.
    config = arguments.get('--config-file', None) or os.path.join(
        'example', 'config.json')
    with open(config) as config_file:
        config = json.load(config_file)

    # Setup the schema.
    schema = arguments.get('--schema-file', None) or os.path.join(
        'example', 'schema.json')
    with open(schema) as schema_file:
        schema = json.load(schema_file)

    # Get the input string.
    ra_string = arguments.get('<input>')
    rapt_instance = Rapt(**config)

    try:
        if arguments.get('sql'):
            print(to_sql(rapt_instance, ra_string, schema))
        elif arguments.get('qtree'):
            print(to_qtree(rapt_instance, ra_string, schema))
        elif arguments.get('pdf'):
            qtree = to_qtree(rapt_instance, ra_string, schema)
            qtree_to_pdf(qtree)
            print(qtree)
        elif arguments.get('seq'):
            print(to_sequence(rapt_instance, ra_string, schema))
        elif arguments.get('repl'):
            print(to_repl(rapt_instance, schema, config))
    except Exception as err:
        print('Error: {}'.format(err))
Ejemplo n.º 2
0
    def do_draw(self, line):
        """
        Draw the syntax tree of the most recently executed relational algebra
        statement.

        Requires pdflatex.

        The files created during the pdf generation process are prefixed with
        'out' (e.g. out.pdf). Optionally, a filename (without extension) can
        be provided instead.

        Usage:  draw [filename]
        """
        if self.previous is not None:
            args = shlex.split(line)
            if len(args) == 1:
                qtree = ''.join(self.rapt.to_qtree(self.previous, self.schema))
                qtree_to_pdf(qtree, args[0])