diff --git a/entrypoint.py b/entrypoint.py index d36436c..4713387 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -75,6 +75,9 @@ def main() -> None: if reload: print(f"Loading vocabulary {vocab}") load_vocabulary(vocab_config['source'], data, graph) + if "tweaks" in vocab_config: + print(f"Tweaks found for {vocab}. Loading") + load_vocabulary(vocab_config['tweaks'], data, graph, True) if graph in loaded_vocabs: update_timestamp(graph, int(time.time())) else: diff --git a/src/graphdb.py b/src/graphdb.py index 02cb5d7..ab76bd3 100644 --- a/src/graphdb.py +++ b/src/graphdb.py @@ -124,12 +124,13 @@ def get_type(extension: str) -> str: return "application/x-turtle" -def add_vocabulary(graph: TextIO, graph_name: str, extension: str) -> None: +def add_vocabulary(graph: TextIO, graph_name: str, extension: str, append: bool = False) -> None: """ Add a vocabulary to GraphDB :param graph: File :param graph_name: String representing the name of the graph - :param extension: String representing the extension + :param extension: String representing the extension + :param append: Append data instead of replacing :return: """ print(f"Adding vocabulary {graph_name}") @@ -142,7 +143,9 @@ def add_vocabulary(graph: TextIO, graph_name: str, extension: str) -> None: headers = { 'Content-Type': get_type(extension), } - response = requests.put( + method = requests.post if append else requests.put + + response = method( f"{endpoint}/statements", data=content, headers=headers, diff --git a/src/vocabularies.py b/src/vocabularies.py index 179fba5..50f6bc9 100644 --- a/src/vocabularies.py +++ b/src/vocabularies.py @@ -97,16 +97,18 @@ def get_file_from_config(config_data: dict, data_dir: str) -> TextIO: raise InvalidConfigurationException("Unknown type") -def load_vocabulary(source_data: dict, data_dir: str, graph_name: str) -> None: +def load_vocabulary(source_data: dict, data_dir: str, + graph_name: str, append: bool = False) -> None: """ Load a vocabulary using the source data from the yaml. - :param source_data: - :param data_dir: - :param graph_name: + :param source_data: Dict containing the information where to find the vocab. + :param data_dir: Dir containing local files. + :param graph_name: The name of the graph to put the vocabulary into. + :param append: Boolean, when true this doesn't overwrite the graph but appends. :return: """ with get_file_from_config(source_data, data_dir) as vocab_file: - add_vocabulary(vocab_file, graph_name, get_vocab_format(source_data)) + add_vocabulary(vocab_file, graph_name, get_vocab_format(source_data), append) def get_graph(fp: IO) -> str: