iolanta 2.1.10__py3-none-any.whl → 2.1.12__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.
iolanta/parse_quads.py CHANGED
@@ -1,6 +1,5 @@
1
1
  import dataclasses
2
2
  import hashlib
3
- from types import MappingProxyType
4
3
  from typing import Iterable, Optional
5
4
  from urllib.parse import unquote
6
5
 
@@ -11,11 +10,7 @@ from rdflib.term import Node
11
10
  from iolanta.errors import UnresolvedIRI
12
11
  from iolanta.models import Quad
13
12
  from iolanta.namespaces import IOLANTA, META
14
-
15
- NORMALIZE_TERMS_MAP = MappingProxyType({
16
- URIRef(_url := 'http://www.w3.org/2002/07/owl'): URIRef(f'{_url}#'),
17
- URIRef(_url := 'http://www.w3.org/2000/01/rdf-schema'): URIRef(f'{_url}#'),
18
- })
13
+ from iolanta.sparqlspace.redirects import apply_redirect
19
14
 
20
15
 
21
16
  def parse_term( # noqa: C901
@@ -35,8 +30,8 @@ def parse_term( # noqa: C901
35
30
  if term_type == 'literal':
36
31
  language = term.get('language')
37
32
 
38
- if datatype := term.get('datatype'):
39
- datatype = URIRef(datatype)
33
+ datatype_raw = term.get('datatype')
34
+ datatype = URIRef(datatype_raw) if datatype_raw else None
40
35
 
41
36
  if language and datatype:
42
37
  datatype = None
@@ -89,7 +84,7 @@ def _parse_quads_per_subgraph(
89
84
  )
90
85
 
91
86
 
92
- def parse_quads(
87
+ def parse_quads( # noqa: WPS210
93
88
  quads_document,
94
89
  graph: URIRef,
95
90
  blank_node_prefix: str = '',
@@ -132,12 +127,20 @@ def parse_quads(
132
127
  )
133
128
 
134
129
  for quad in quads: # noqa: WPS526
135
- yield quad.replace(
136
- subgraph_names | NORMALIZE_TERMS_MAP | {
137
- # To enable nanopub rendering
138
- URIRef('http://purl.org/nanopub/temp/np/'): graph,
139
- },
140
- ).normalize()
130
+ # Build replacement map with subgraph names and nanopub temp namespace
131
+ replacement_map = subgraph_names | {
132
+ # To enable nanopub rendering
133
+ URIRef('http://purl.org/nanopub/temp/np/'): graph,
134
+ }
135
+
136
+ # Apply redirects to all URIRefs in the replacement map
137
+ normalized_replacement_map = {
138
+ apply_redirect(key) if isinstance(key, URIRef) else key:
139
+ apply_redirect(value_node) if isinstance(value_node, URIRef) else value_node # noqa: WPS110
140
+ for key, value_node in replacement_map.items()
141
+ }
142
+
143
+ yield quad.replace(normalized_replacement_map).normalize()
141
144
 
142
145
 
143
146
  def raise_if_term_is_qname(term_value: str):