Skip to content

Commit

Permalink
update subgraph deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
MBueschelberger committed Mar 1, 2024
1 parent 27c6cb3 commit 10edf40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dsms/knowledge/sparql_interface/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def create(self, graph: "Graph", repository: str = "knowledge") -> None:

def delete(self, identifier: str, repository: str = "knowledge") -> None:
"""Delete a subgraph in the DSMS"""
_delete_subgraph(identifier, self._dsms.config.encoding, repository)
_delete_subgraph(identifier, repository)

def get(
self,
identifier: str,
repository: str = "knowledge",
is_kitem_id: bool = False,
) -> None:
) -> "Graph":
"""Get a subgraph from the DSMS"""
_get_subgraph(identifier, repository, is_kitem_id)
return _get_subgraph(identifier, repository, is_kitem_id)
15 changes: 9 additions & 6 deletions dsms/knowledge/sparql_interface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _sparql_query(query: str, repository: str) -> "Dict[str, Any]":
\n
`{query}`"""
) from excep
return response["results"]["bindings"]
return response


def _sparql_update(
Expand Down Expand Up @@ -60,7 +60,6 @@ def _get_file_or_pathlike(
f"or a file-like object."
)
files = {"file": file_or_pathlike}
print(files)
return files


Expand All @@ -86,7 +85,7 @@ def _add_rdf(
)


def _delete_subgraph(identifier: str, encoding: str, repository: str) -> None:
def _delete_subgraph(identifier: str, repository: str) -> None:
"""Get subgraph related to a certain dataset id."""
query = f"""
DELETE {{
Expand All @@ -100,7 +99,11 @@ def _delete_subgraph(identifier: str, encoding: str, repository: str) -> None:
GRAPH ?g {{ ?s ?p ?o . }}
}}
}}"""
_sparql_update(query, encoding, repository)
response = _sparql_query(query, repository)
if not response.get("boolean"):
raise RuntimeError(
f"Deleteing subgraph was not successful: {response}"
)


def _create_subgraph(graph: Graph, encoding: str, respository: str) -> None:
Expand All @@ -113,7 +116,7 @@ def _create_subgraph(graph: Graph, encoding: str, respository: str) -> None:

def _update_subgraph(graph: Graph, encoding: str, repository: str) -> None:
"""Update the subgraph in the remote backend"""
_delete_subgraph(graph.identifier, encoding, repository)
_delete_subgraph(graph.identifier, repository)
_create_subgraph(graph, encoding, repository)


Expand All @@ -134,7 +137,7 @@ def _get_subgraph(
GRAPH ?g {{ ?s ?p ?o . }}
}}
}}"""
data = _sparql_query(query, repository)
data = _sparql_query(query, repository)["results"]["bindings"]

buffer = io.StringIO()
buffer.writelines(
Expand Down

0 comments on commit 10edf40

Please sign in to comment.