Skip to content

Commit

Permalink
uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelo7 committed Apr 27, 2024
1 parent 10b31ce commit 3503427
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
21 changes: 18 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions uploader.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit 3503427

Please sign in to comment.