Example #1
0
def ingest_data_driver(config_path: Path, base_url: Url,
                       data_graphs: Optional[List[Url]],
                       triple_store: Optional[Url], clear: bool) -> None:
    """Use an import.yaml file to ingest multiple CSV files into the data graph."""
    with open(config_path, 'r', encoding='utf-8') as config_file:
        config = yaml.safe_load(config_file)
        validate(config, INGEST_CSV_CONFIG_SCHEMA)

    steps = config['ingestion-steps']

    if data_graphs is not None:
        data_graph = data_graphs[0]
    elif 'data-graph' in config:
        data_graph = config['data-graph']
    else:
        logger.warning("Defaulting data-graph to %s", DEFAULT_DATA_GRAPH)
        data_graph = DEFAULT_DATA_GRAPH

    base_path = config_path.parent

    if data_graphs is not None:
        extra_data_graphs = data_graphs[1:]
    elif 'extra-data-graphs' in config:
        extra_data_graphs = config['extra-data-graphs']
    else:
        extra_data_graphs = []

    conn = sparql_connection(base_url, data_graph, extra_data_graphs,
                             triple_store)

    if clear:
        clear_graph(conn)

    for step in steps:
        if 'owl' in step:
            owl_file = step['owl']
            print(f'Ingesting {str_highlight(str(owl_file)): <40}', end="")
            try:
                semtk3.upload_owl(base_path / owl_file, conn, "rack", "rack",
                                  semtk3.SEMTK3_CONN_DATA)
            except Exception as e:
                print(str_bad(' FAIL'))
                raise e
            print(str_good(' OK'))
        elif 'csv' in step:
            ingest_csv(conn, step['nodegroup'], base_path / step['csv'])
Example #2
0
 def go() -> None:
     return semtk3.upload_owl(owl_file, conn, "rack", "rack")