dkg 8.0.12__py3-none-any.whl → 8.0.13__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.
@@ -6,6 +6,7 @@ from dkg.types import JSONLD, NQuads
6
6
  from pyld import jsonld
7
7
  from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM, ESCAPE_MAP
8
8
  from rdflib import Graph, BNode, URIRef, Literal as RDFLiteral
9
+ from rdflib.exceptions import ParserError as RDFParserError
9
10
  from uuid import uuid4
10
11
  from web3 import Web3
11
12
  import math
@@ -154,29 +155,26 @@ def generate_missing_ids_for_blank_nodes(nquads_list: list[str] | None) -> list[
154
155
 
155
156
  return term # Return IRIs or Literals unchanged
156
157
 
157
- # Create a temporary graph for parsing individual quads
158
- result = []
159
-
160
- # Process each N-Quad string individually to maintain order
161
- for nquad in nquads_list:
162
- if not nquad.strip():
163
- continue
158
+ all_nquads = "\n".join(nquad for nquad in nquads_list if nquad.strip())
164
159
 
165
- # Parse single N-Quad
166
- g = Graph()
167
- g.parse(data=nquad, format="nquads")
160
+ # Create a single Dataset
161
+ g = Graph()
162
+ try:
163
+ g.parse(data=all_nquads, format="nt")
164
+ except RDFParserError:
165
+ raise UnsupportedJSONLD(nquads_list)
168
166
 
169
- # Get the triple and replace blank nodes
170
- for s, p, o in g:
171
- updated_quad = (
172
- replace_blank_node(s),
173
- replace_blank_node(p),
174
- replace_blank_node(o),
175
- )
176
- # Format as N-Quad string
177
- result.append(
178
- f"{updated_quad[0].n3()} {updated_quad[1].n3()} {updated_quad[2].n3()} ."
179
- )
167
+ # Process all quads
168
+ result = []
169
+ for s, p, o in g:
170
+ updated_quad = (
171
+ replace_blank_node(s),
172
+ replace_blank_node(p),
173
+ replace_blank_node(o),
174
+ )
175
+ result.append(
176
+ f"{updated_quad[0].n3()} {updated_quad[1].n3()} {updated_quad[2].n3()} ."
177
+ )
180
178
 
181
179
  return result
182
180
 
@@ -266,3 +264,44 @@ def escape_literal_dict(obj):
266
264
  return escape_literal_string(s=obj)
267
265
  else:
268
266
  return obj
267
+
268
+
269
+ # Used when JSON-LD parsing fails due to quads being passed instead of triples
270
+ class UnsupportedJSONLD(Exception):
271
+ def __init__(self, nquads_list):
272
+ self.nquads_list = nquads_list
273
+ self.message = f"""
274
+ Unsupported JSON-LD input detected
275
+
276
+ After parsing the JSON-LD input, the parser detected creation of new named graphs.
277
+ The DKG does not support custom named graphs.
278
+
279
+ Problematic Quads:
280
+
281
+ {self.find_problematic_quads()}
282
+
283
+ Full Parsed N-Quads Array:
284
+
285
+ {self.format_nquads_list()}
286
+
287
+ """
288
+ super().__init__(self.message)
289
+
290
+ def __str__(self):
291
+ return f"{self.__class__.__name__}: {self.message}"
292
+
293
+ def format_nquads_list(self):
294
+ return "\n".join(nquad.strip() for nquad in self.nquads_list)
295
+
296
+ def find_problematic_quads(self):
297
+ problematic = []
298
+ g = Graph()
299
+ for quad in self.nquads_list:
300
+ if not quad.strip():
301
+ continue
302
+ try:
303
+ g.parse(data=quad, format="nt")
304
+ except RDFParserError:
305
+ problematic.append(quad)
306
+
307
+ return "\n".join(f"{i + 1}. {quad}" for i, quad in enumerate(problematic))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dkg
3
- Version: 8.0.12
3
+ Version: 8.0.13
4
4
  Summary: Python library for interacting with the OriginTrail Decentralized Knowledge Graph
5
5
  License: Apache-2.0
6
6
  Author: Uladzislau Hubar
@@ -68,15 +68,15 @@ dkg/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
68
68
  dkg/utils/blockchain_request.py,sha256=CMz3sNRhfmYirm0-VUK2HTpbRfgc1gtG2SoPIuRYKb0,12446
69
69
  dkg/utils/decorators.py,sha256=uUh0xI9wv1gE6JF44eYEfUPGSFEBLR6Ua5D9Dhc3s10,1566
70
70
  dkg/utils/knowledge_asset_tools.py,sha256=uehOshzaYg03hDU8RSIV_k2mNaASVgqyyErzj6GwBxw,81
71
- dkg/utils/knowledge_collection_tools.py,sha256=hPCFcIdyWDCgfbo5uPQizvfin0hHvEElAYpvKYVDIBs,7951
71
+ dkg/utils/knowledge_collection_tools.py,sha256=6U9lLjoXfsayH_AmicNWtmsQ5xdllhTs-L9DsbPYvlU,8994
72
72
  dkg/utils/merkle.py,sha256=924kloBAnCXydteVtWMj_QLP5CRJf2GbHMZ-lbIK0KE,5141
73
73
  dkg/utils/metadata.py,sha256=483OroYwGNfZ_cCXfH3-xUrZgiR4mjjo9iU_Ie5RYRs,1658
74
74
  dkg/utils/node_request.py,sha256=wppF8Xf0RkuAAcURcYgyjGAdMsXm0L5YEem8wFGE2g8,6517
75
75
  dkg/utils/rdf.py,sha256=AvlcxZEeP58UbaGGvPX_ss69O-tgTXOJ9y9COZqVgkw,2973
76
76
  dkg/utils/string_transformations.py,sha256=eR51fVwTF9QKxEqXo9_1Bfw_k8iQajdXD6rKuTvhs70,972
77
77
  dkg/utils/ual.py,sha256=g7PFyS4Sbwjmwkq-eB20uRULEC2wlPGZr31BVQjs5OQ,1569
78
- dkg-8.0.12.dist-info/LICENSE,sha256=Dr70w2zcW8-jrPGlpTTTlJPL8lR4j2zpDD32tdEFgjY,11375
79
- dkg-8.0.12.dist-info/METADATA,sha256=qoW7Du0ik1jwQC-qkG3nBQgZQLMoRtUrh4FMJXLJzcQ,10821
80
- dkg-8.0.12.dist-info/NOTICE,sha256=Rk5toFR2ZqPwVZ3P_P4wE6U1xCnWR9KD3rNBqfPY7h8,368
81
- dkg-8.0.12.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
82
- dkg-8.0.12.dist-info/RECORD,,
78
+ dkg-8.0.13.dist-info/LICENSE,sha256=Dr70w2zcW8-jrPGlpTTTlJPL8lR4j2zpDD32tdEFgjY,11375
79
+ dkg-8.0.13.dist-info/METADATA,sha256=p4WHsfUDVtn17p--zUboDCgjn2iuEoOPwRfSUc-9xEg,10821
80
+ dkg-8.0.13.dist-info/NOTICE,sha256=Rk5toFR2ZqPwVZ3P_P4wE6U1xCnWR9KD3rNBqfPY7h8,368
81
+ dkg-8.0.13.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
82
+ dkg-8.0.13.dist-info/RECORD,,
File without changes
File without changes
File without changes