rdf4j-python 0.1.1a0__py3-none-any.whl → 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,10 @@
1
1
  from dataclasses import dataclass
2
- from typing import Mapping
3
2
 
4
- from rdflib.term import Identifier, Variable
5
-
6
- from ._base_model import _BaseModel
3
+ import pyoxigraph as og
7
4
 
8
5
 
9
6
  @dataclass
10
- class RepositoryMetadata(_BaseModel):
7
+ class RepositoryMetadata:
11
8
  """
12
9
  Represents a repository metadata RDF4J.
13
10
  """
@@ -19,23 +16,47 @@ class RepositoryMetadata(_BaseModel):
19
16
  writable: bool # Whether the repository is writable
20
17
 
21
18
  def __str__(self):
22
- # Custom string representation for easy printing
19
+ """
20
+ Returns a string representation of the RepositoryMetadata.
21
+
22
+ Returns:
23
+ str: A string representation of the RepositoryMetadata.
24
+ """
23
25
  return f"Repository(id={self.id}, title={self.title}, uri={self.uri})"
24
26
 
25
27
  @classmethod
26
- def from_rdflib_binding(
27
- cls, result: Mapping[Variable, Identifier]
28
+ def from_sparql_query_solution(
29
+ cls, query_solution: og.QuerySolution
28
30
  ) -> "RepositoryMetadata":
29
31
  """
30
- Create a Repository instance from a SPARQL query result
31
- represented as a Mapping from rdflib Variables to Identifiers.
32
+ Create a RepositoryMetadata instance from a SPARQL query result.
33
+
34
+ Args:
35
+ query_solution (og.QuerySolution): The SPARQL query result.
36
+
37
+ Returns:
38
+ RepositoryMetadata: The RepositoryMetadata instance.
39
+
40
+ Raises:
41
+ ValueError: If the query solution is missing required fields.
32
42
  """
33
43
 
34
44
  # Construct and return the Repository object
45
+ if query_solution["id"] is None:
46
+ raise ValueError("id is required")
47
+ if query_solution["uri"] is None:
48
+ raise ValueError("uri is required")
49
+ if query_solution["title"] is None:
50
+ raise ValueError("title is required")
51
+ if query_solution["readable"] is None:
52
+ raise ValueError("readable is required")
53
+ if query_solution["writable"] is None:
54
+ raise ValueError("writable is required")
55
+
35
56
  return cls(
36
- id=_BaseModel.get_literal(result, "id", ""),
37
- uri=_BaseModel.get_uri(result, "uri", ""),
38
- title=_BaseModel.get_literal(result, "title", ""),
39
- readable=_BaseModel.get_literal(result, "readable", False),
40
- writable=_BaseModel.get_literal(result, "writable", False),
57
+ id=query_solution["id"].value,
58
+ uri=query_solution["uri"].value,
59
+ title=query_solution["title"].value,
60
+ readable=bool(query_solution["readable"].value),
61
+ writable=bool(query_solution["writable"].value),
41
62
  )