Skip to content

Commit cbdd889

Browse files
committed
Ruff reformat files
1 parent 881bd5c commit cbdd889

2 files changed

Lines changed: 44 additions & 33 deletions

File tree

cmem_plugin_base/dataintegration/typed_entities/quads.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# --- RDF Node Types ---
1515

16+
1617
class RdfNode(BaseModel):
1718
"""Abstract base class for an RDF node."""
1819

@@ -32,20 +33,21 @@ class Resource(ConcreteNode):
3233

3334
type: ClassVar[str] = "URI"
3435

35-
value: str # The URI of the resource
36+
value: str # The URI of the resource
3637

3738

3839
class BlankNode(ConcreteNode):
3940
"""Represents an RDF blank node."""
4041

4142
type: ClassVar[str] = "BlankNode"
4243

43-
value: str # Usually the identifier without the '_:' prefix internally
44+
value: str # Usually the identifier without the '_:' prefix internally
4445

4546

4647
class Literal(RdfNode):
4748
"""Abstract base class for an RDF literal."""
4849

50+
4951
class PlainLiteral(Literal):
5052
"""Represents a plain literal without a language tag or datatype."""
5153

@@ -69,7 +71,7 @@ class DataTypeLiteral(Literal):
6971
type: ClassVar[str] = "TypedLiteral"
7072

7173
value: str
72-
data_type: str = "http://www.w3.org/2001/XMLSchema#string" # Default datatype IRI for literals
74+
data_type: str = "http://www.w3.org/2001/XMLSchema#string" # Default datatype IRI for literals
7375

7476

7577
class Quad(BaseModel):
@@ -81,8 +83,9 @@ class Quad(BaseModel):
8183
graph: Resource | None = None
8284

8385

84-
def create_node(type_name: str, value: str,
85-
language: str | None = None, data_type: str | None = None) -> RdfNode:
86+
def create_node(
87+
type_name: str, value: str, language: str | None = None, data_type: str | None = None
88+
) -> RdfNode:
8689
"""Create an RDF node for a given type name."""
8790
match type_name:
8891
case Resource.type:
@@ -102,8 +105,10 @@ def create_node(type_name: str, value: str,
102105
case _:
103106
raise ValueError(f"Unknown type: {type_name}")
104107

108+
105109
# --- RDF Quad Schema ---
106110

111+
107112
class QuadEntitySchema(TypedEntitySchema[Quad]):
108113
"""Entity schema that holds a collection of RDF quads."""
109114

@@ -120,7 +125,7 @@ def __init__(self):
120125
EntityPath(path_uri("quad/objectType")),
121126
EntityPath(path_uri("quad/objectLanguage")),
122127
EntityPath(path_uri("quad/objectDataType")),
123-
EntityPath(path_uri("quad/graph"))
128+
EntityPath(path_uri("quad/graph")),
124129
],
125130
)
126131

@@ -141,14 +146,16 @@ def to_entity(self, quad: Quad) -> Entity:
141146
object_data_type = []
142147

143148
# Generate a UUID-based URI
144-
uri_components = "".join([
145-
quad.subject.value,
146-
quad.predicate.value,
147-
quad.object.value,
148-
object_language[0] if object_language else "",
149-
object_data_type[0] if object_data_type else "",
150-
quad.graph.value if quad.graph else ""
151-
])
149+
uri_components = "".join(
150+
[
151+
quad.subject.value,
152+
quad.predicate.value,
153+
quad.object.value,
154+
object_language[0] if object_language else "",
155+
object_data_type[0] if object_data_type else "",
156+
quad.graph.value if quad.graph else "",
157+
]
158+
)
152159
uri = f"urn:uuid:{uuid.uuid5(uuid.NAMESPACE_DNS, uri_components)}"
153160

154161
# Build entity
@@ -162,7 +169,7 @@ def to_entity(self, quad: Quad) -> Entity:
162169
[quad.object.type],
163170
object_language,
164171
object_data_type,
165-
[quad.graph.value] if quad.graph else []
172+
[quad.graph.value] if quad.graph else [],
166173
],
167174
)
168175

@@ -210,7 +217,8 @@ def from_entity(self, entity: Entity) -> Quad:
210217

211218
# Build the Quad
212219
return Quad(
213-
subject=cast(ConcreteNode, subject),
220+
subject=cast("ConcreteNode", subject),
214221
predicate=predicate,
215222
object=object_value,
216-
graph=graph)
223+
graph=graph,
224+
)

tests/typed_entities/test_quads.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test for RDF quads."""
2+
23
import copy
34
import unittest
45
from collections.abc import Sequence
@@ -38,30 +39,32 @@ def test_quads(self) -> None:
3839
# Creat quads with all supported node types
3940
quads = [
4041
Quad(
41-
subject = Resource(value="urn:instance:person1"),
42-
predicate = Resource(value="urn:instance:hasCity"),
43-
object = Resource(value="urn:instance:city1")
42+
subject=Resource(value="urn:instance:person1"),
43+
predicate=Resource(value="urn:instance:hasCity"),
44+
object=Resource(value="urn:instance:city1"),
4445
),
4546
Quad(
46-
subject = Resource(value="urn:instance:person2"),
47-
predicate = Resource(value="urn:instance:hasCity"),
48-
object = PlainLiteral(value="Berlin")
47+
subject=Resource(value="urn:instance:person2"),
48+
predicate=Resource(value="urn:instance:hasCity"),
49+
object=PlainLiteral(value="Berlin"),
4950
),
5051
Quad(
51-
subject = Resource(value="urn:instance:person3"),
52-
predicate = Resource(value="urn:instance:hasCity"),
53-
object = LanguageLiteral(value="Berlin", language="en")
52+
subject=Resource(value="urn:instance:person3"),
53+
predicate=Resource(value="urn:instance:hasCity"),
54+
object=LanguageLiteral(value="Berlin", language="en"),
5455
),
5556
Quad(
56-
subject = Resource(value="urn:instance:person4"),
57-
predicate = Resource(value="urn:instance:age"),
58-
object = DataTypeLiteral(value="29", data_type="http://www.w3.org/2001/XMLSchema#int")
57+
subject=Resource(value="urn:instance:person4"),
58+
predicate=Resource(value="urn:instance:age"),
59+
object=DataTypeLiteral(
60+
value="29", data_type="http://www.w3.org/2001/XMLSchema#int"
61+
),
5962
),
6063
Quad(
61-
subject = BlankNode(value="person5"),
62-
predicate = Resource(value="urn:instance:hasCity"),
63-
object = BlankNode(value="city1")
64-
)
64+
subject=BlankNode(value="person5"),
65+
predicate=Resource(value="urn:instance:hasCity"),
66+
object=BlankNode(value="city1"),
67+
),
6568
]
6669

6770
# Execute operator

0 commit comments

Comments
 (0)