Example #1
0
def run(args, timestamp):
    pi = ProgressIndicator()

    # load database mapping table
    mapping = SchemaDB(args.database_schema)
    database = mapping.database_name()

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./{}_{}".format(database, timestamp)
    if not is_writable(output_path):
        return

    if args.area is None:
        scope = Area()
    else:
        scope = Area(float(args.area[0]), float(args.area[1]),
                     float(args.area[2]), float(args.area[3]))

    # translate database to RDF
    print("Translating {}...".format(database.upper()))
    pi.start()
    if args.gdb is not None:
        graph = _run_gdb(args.gdb, mapping, scope, timestamp)
    else:
        graph = _run_sql(args.server, database, mapping, scope, timestamp)
    pi.stop()

    # write graph
    print("Writing graph to disk...")
    write(graph, output_path, args.serialization_format)
Example #2
0
def run(args, timestamp):
    pi = ProgressIndicator()

    # load mapping table
    if not is_readable(args.mapping):
        raise Exception("Wrong file permissions: {}".format(args.mapping))
    mapping = SchemaOTL(args.mapping)

    print("Importing referenced graph...")
    pi.start()
    params = import_graph(args.graph, mapping)
    pi.stop()

    print("Generating enrichments...")
    pi.start()
    graph = enrich(mapping, params['name'], params['graph'], timestamp)
    pi.stop()

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./{}-otl{}_{}".format(params['name'],\
                                               "-schema" if params['type'] is OWL.Ontology else "",\
                                               timestamp)
    if not is_writable(output_path):
        return

    # write graph
    print("Writing graph to disk...")
    write(graph, output_path, args.serialization_format)
Example #3
0
def set_logging(args, timestamp):
    log_path = args.log_directory
    if not is_writable(log_path):
        return

    filename = "{}{}.log".format(log_path, timestamp) if log_path.endswith("/") \
                    else "{}/{}.log".format(log_path, timestamp)

    logging.basicConfig(filename=filename,
                        format='%(asctime)s %(levelname)s: %(message)s',
                        level=logging.INFO)

    if args.verbose:
        logging.getLogger().addHandler(logging.StreamHandler())
Example #4
0
def run(args, timestamp):
    pi = ProgressIndicator()

    # load data types mapping table
    datatypes_map_file = args.datatype_schema
    if not is_readable(datatypes_map_file):
        return
    datatypes_map = SchemaDT(datatypes_map_file)

    # load UML if supported
    uml = None
    uml_filename = args.uml
    if uml_filename is not None and is_readable(uml_filename):
        uml = UML()
        uml.parse(uml_filename)

    print("Generating schema...")
    pi.start()

    # determine database
    database = ""
    schema = None
    if args.gdb is not None:
        schema, database = _run_gdb(args, datatypes_map)
    else:
        schema, database = _run_sql(args, datatypes_map, uml)

    pi.stop()

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./{}_{}.json".format(database, timestamp)
    if not is_writable(output_path):
        return

    # inspect resulting schema
    if args.interactive:
        cli(schema)

    # write schema
    print("Writing schema to disk...")
    write(schema, output_path)
Example #5
0
def run(args, timestamp):
    pi = ProgressIndicator()

    # load mapping table
    if not is_readable(args.crossreference_mapping):
        raise Exception("Wrong file permissions: {}".format(args.crossreference_mapping))
    mapping = SchemaXR(args.crossreference_mapping)
    database_pairs = mapping.database_pairs()

    print("Importing referenced graphs...")
    pi.start()
    params = import_graphs(args.source_graph,\
                           args.target_graph,\
                           {db for pair in database_pairs for db in pair})
    pi.stop()

    # generate crossreferences
    print("Generating cross-references...")
    pi.start()
    graph = params['linker'](mapping,\
                             params['source_name'],\
                             params['target_name'],\
                             params['source_graph'],\
                             params['target_graph'],\
                             args.include_backlinks,\
                             timestamp)
    pi.stop()

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./xref_{}-{}{}_{}".format(params['source_name'],\
                                                 params['target_name'],\
                                                 "-schema" if params['linker'] is tbox_link else "",\
                                                 timestamp)
    if not is_writable(output_path):
        return

    # write graph
    print("Writing graph to disk...")
    write(graph, output_path, args.serialization_format)
Example #6
0
def run(args, timestamp):
    # load database mapping table
    mapping = SchemaDB(args.database_schema)

    database = mapping.database_name()

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./{}-schema_{}".format(database, timestamp)
    if not is_writable(output_path):
        return

    # translate database to RDF
    pi = ProgressIndicator()
    print("Translating {}...".format(database.upper()))
    pi.start()
    graph = translate(database, mapping, timestamp)
    pi.stop()

    # write graph
    print("Writing graph to disk...")
    write(graph, output_path, args.serialization_format)
Example #7
0
def run(args, timestamp):
    # validate input paths
    if len(args.graphs) < 2:
        raise Exception("Requires at least 2 input graphs")
    _check_paths(args.graphs)

    # validate output path
    output_path = args.output
    if output_path is None:
        output_path = "./merge_{}".format(timestamp)
    if not is_writable(output_path):
        return

    print("Merging graphs...")
    pi = ProgressIndicator()
    pi.start()
    graph = multiread(args.graphs)
    update_metadata(graph, default_namespace_of(graph)[0], timestamp)
    pi.stop()

    # write graph
    print("Writing graph to disk...")
    write(graph, output_path, args.serialization_format)