diff --git a/poetry.lock b/poetry.lock index 618e4e1..cd72208 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "async-timeout" @@ -175,6 +175,9 @@ files = [ {file = "filelock-3.12.3.tar.gz", hash = "sha256:0ecc1dd2ec4672a10c8550a8182f1bd0c0a5088470ecd5a125e45f49472fac3d"}, ] +[package.dependencies] +typing-extensions = {version = ">=4.7.1", markers = "python_version < \"3.11\""} + [package.extras] docs = ["furo (>=2023.7.26)", "sphinx (>=7.1.2)", "sphinx-autodoc-typehints (>=1.24)"] testing = ["covdefaults (>=2.3)", "coverage (>=7.3)", "diff-cover (>=7.7)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-timeout (>=2.1)"] @@ -548,6 +551,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -747,6 +751,17 @@ notebook = ["ipywidgets (>=6)"] slack = ["slack-sdk"] telegram = ["requests"] +[[package]] +name = "typing-extensions" +version = "4.11.0" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"}, + {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"}, +] + [[package]] name = "urllib3" version = "2.0.4" @@ -838,5 +853,5 @@ email = ["email-validator"] [metadata] lock-version = "2.0" -python-versions = "^3.11" -content-hash = "edf8148e450269386da9edc602ba31669b1bb236c5d8a940c61397c86e7d5204" +python-versions = "^3.10" +content-hash = "11c94dcf5a53f56708e3c5519a214c602e1c2009183db44a99419debedad1ec8" diff --git a/pyproject.toml b/pyproject.toml index afdfd97..906ef41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ readme = "README.md" packages = [{include = "edit_sphere"}] [tool.poetry.dependencies] -python = "^3.11" +python = "^3.10" flask = "^2.3.3" sparqlwrapper = "^2.0.0" pyyaml = "^6.0.1" diff --git a/uploader.py b/uploader.py new file mode 100644 index 0000000..a479efe --- /dev/null +++ b/uploader.py @@ -0,0 +1,45 @@ +import os +import argparse +from SPARQLWrapper import SPARQLWrapper, POST + +def load_rdf_file_to_sparql(file_path, sparql_endpoint): + absolute_file_path = os.path.abspath(file_path) + normalized_file_path = absolute_file_path.replace("\\", "/") + file_url = f"file:///{normalized_file_path}" + + sparql = SPARQLWrapper(sparql_endpoint) + sparql.setMethod(POST) + load_query = f"LOAD <{file_url}>" + sparql.setQuery(load_query) + sparql.query() + +parser = argparse.ArgumentParser( + description="Uploads RDF files from a specified directory to a given SPARQL endpoint using SPARQL LOAD." +) +parser.add_argument( + "--directory", + "-d", + type=str, + default="test/meta_subset", + help="Path to the directory containing RDF files.", +) +parser.add_argument( + "--endpoint", + "-e", + type=str, + default="http://localhost:9999/blazegraph/sparql", + help="SPARQL endpoint for the triple store.", +) + +args = parser.parse_args() + +for file_name in os.listdir(args.directory): + file_path = os.path.join(args.directory, file_name) + + if os.path.isfile(file_path): + try: + print(f"Loading {file_name}...") + load_rdf_file_to_sparql(file_path, args.endpoint) + print("Loading completed.") + except Exception as e: + print(f"Error during the loading of {file_name}: {e}") \ No newline at end of file