Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def load(self, path):
        driver = ogr.GetDriverByName("OpenFileGDB")

        if not is_readable(path):
            raise Exception(
                "Wrong permissions or file not found: {}".format(path))

        try:
            self._gdb = driver.Open(path, 0)
        except Exception as e:
            print(e)
Ejemplo n.º 4
0
def import_graph(filename, schema):
    if not is_readable(filename):
        raise Exception(
            "File missing or wrong permissions: {}".format(filename))

    graph = read(filename)
    namespace, gtype = default_namespace_of(graph)
    database = _determine_database(namespace)

    if database not in schema.schema.keys():
        raise Exception(
            "Database not contained in mapping: {}".format(database))

    return {'graph': graph, 'type': gtype, 'name': database}
Ejemplo n.º 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)
Ejemplo n.º 6
0
def import_graphs(source, target, schema):
    for filename in [source, target]:
        if not is_readable(filename):
            raise Exception("File missing or wrong permissions: {}".format(filename))

    source_graph = read(source)
    target_graph = read(target)

    source_namespace, source_type = default_namespace_of(source_graph)
    target_namespace, target_type = default_namespace_of(target_graph)

    linker = _determine_type(source_type, target_type)
    databases = _determine_databases(source_namespace, target_namespace)

    for _,v in databases.items():
        if v not in schema:
            raise Exception("Database not contained in mapping: {}".format(v))

    return { 'source_graph': source_graph,
             'target_graph': target_graph,
             'source_name': databases['source'],
             'target_name': databases['target'],
             'linker': linker }
Ejemplo n.º 7
0
    def __init__(self, path):
        self.logger = logging.getLogger(__name__)

        if is_readable(path):
            self.load_schema(path)
Ejemplo n.º 8
0
def _run_gdb(args, datatypes_map):
    if not is_readable(args.gdb):
        return {}
    gdb = GeoDataBase(args.gdb)

    return (generate_gdb(gdb, datatypes_map), 'kerngis')
Ejemplo n.º 9
0
def _check_paths(graphs):
    for graph in graphs:
        if not is_readable(graph):
            raise Exception(
                "File missing or wrong permissions: {}".format(graph))