dsp-tools 17.0.0.post21__py3-none-any.whl → 17.0.0.post23__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.

Potentially problematic release.


This version of dsp-tools might be problematic. Click here for more details.

@@ -16,6 +16,7 @@ class SHACLValidationReport:
16
16
  class ProjectDataFromApi:
17
17
  all_lists: list[OneList]
18
18
  enabled_licenses: EnabledLicenseIris
19
+ resource_iris_in_db: list[InfoForResourceInDB]
19
20
 
20
21
 
21
22
  @dataclass
@@ -50,3 +51,9 @@ class SHACLListInfo:
50
51
  @dataclass
51
52
  class EnabledLicenseIris:
52
53
  enabled_licenses: list[str]
54
+
55
+
56
+ @dataclass
57
+ class InfoForResourceInDB:
58
+ res_iri: str
59
+ res_type: str
@@ -23,6 +23,7 @@ class RDFGraphs:
23
23
  cardinality_shapes: Graph
24
24
  content_shapes: Graph
25
25
  knora_api: Graph
26
+ resources_in_db_graph: Graph
26
27
 
27
28
 
28
29
  @dataclass
@@ -48,7 +48,10 @@ def _make_one_value(val: RdfLikeValue, res_iri: URIRef) -> Graph:
48
48
  return g
49
49
  if val.knora_type == KnoraValueType.LINK_VALUE:
50
50
  link_val = val.user_facing_value if val.user_facing_value else ""
51
- triple_object: Literal | URIRef = DATA[link_val]
51
+ if link_val.startswith("http://rdfh.ch/"):
52
+ triple_object: Literal | URIRef = URIRef(link_val)
53
+ else:
54
+ triple_object = DATA[link_val]
52
55
  else:
53
56
  triple_object = _make_one_rdflib_object(val.user_facing_value, VALUE_INFO_TRIPLE_OBJECT_TYPE[val.knora_type])
54
57
  g.add((val_iri, prop_type_info.knora_prop, triple_object))
@@ -2,13 +2,18 @@ import importlib.resources
2
2
  from pathlib import Path
3
3
 
4
4
  from loguru import logger
5
+ from rdflib import RDF
5
6
  from rdflib import Graph
7
+ from rdflib import URIRef
6
8
 
7
9
  from dsp_tools.clients.authentication_client import AuthenticationClient
8
10
  from dsp_tools.clients.legal_info_client_live import LegalInfoClientLive
11
+ from dsp_tools.clients.metadata_client import MetadataRetrieval
12
+ from dsp_tools.clients.metadata_client_live import MetadataClientLive
9
13
  from dsp_tools.commands.validate_data.api_clients import ListClient
10
14
  from dsp_tools.commands.validate_data.api_clients import OntologyClient
11
15
  from dsp_tools.commands.validate_data.models.api_responses import EnabledLicenseIris
16
+ from dsp_tools.commands.validate_data.models.api_responses import InfoForResourceInDB
12
17
  from dsp_tools.commands.validate_data.models.api_responses import ListLookup
13
18
  from dsp_tools.commands.validate_data.models.api_responses import OneList
14
19
  from dsp_tools.commands.validate_data.models.api_responses import ProjectDataFromApi
@@ -42,13 +47,13 @@ def prepare_data_for_validation_from_parsed_resource(
42
47
  permission_ids: list[str],
43
48
  auth: AuthenticationClient,
44
49
  shortcode: str,
45
- ) -> tuple[RDFGraphs, set[str]]:
50
+ ) -> tuple[RDFGraphs, set[str], MetadataRetrieval]:
46
51
  used_iris = {x.res_type for x in parsed_resources}
47
- proj_info = _get_project_specific_information_from_api(auth, shortcode)
52
+ proj_info, metadata_retrieval_success = _get_project_specific_information_from_api(auth, shortcode)
48
53
  list_lookup = _make_list_lookup(proj_info.all_lists)
49
54
  data_rdf = _make_data_graph_from_parsed_resources(parsed_resources, authorship_lookup, list_lookup)
50
55
  rdf_graphs = _create_graphs(data_rdf, shortcode, auth, proj_info, permission_ids)
51
- return rdf_graphs, used_iris
56
+ return rdf_graphs, used_iris, metadata_retrieval_success
52
57
 
53
58
 
54
59
  def _make_list_lookup(project_lists: list[OneList]) -> ListLookup:
@@ -60,11 +65,23 @@ def _make_list_lookup(project_lists: list[OneList]) -> ListLookup:
60
65
  return ListLookup(lookup)
61
66
 
62
67
 
63
- def _get_project_specific_information_from_api(auth: AuthenticationClient, shortcode: str) -> ProjectDataFromApi:
68
+ def _get_project_specific_information_from_api(
69
+ auth: AuthenticationClient, shortcode: str
70
+ ) -> tuple[ProjectDataFromApi, MetadataRetrieval]:
64
71
  list_client = ListClient(auth.server, shortcode)
65
72
  all_lists = list_client.get_lists()
66
73
  enabled_licenses = _get_license_iris(shortcode, auth)
67
- return ProjectDataFromApi(all_lists, enabled_licenses)
74
+ retrieval_status, formatted_metadata = _get_metadata_info(auth, shortcode)
75
+ return ProjectDataFromApi(all_lists, enabled_licenses, formatted_metadata), retrieval_status
76
+
77
+
78
+ def _get_metadata_info(
79
+ auth: AuthenticationClient, shortcode: str
80
+ ) -> tuple[MetadataRetrieval, list[InfoForResourceInDB]]:
81
+ metadata_client = MetadataClientLive(auth.server, auth)
82
+ retrieval_status, metadata = metadata_client.get_resource_metadata(shortcode)
83
+ formatted_metadata = [InfoForResourceInDB(x["resourceIri"], x["resourceClassIri"]) for x in metadata]
84
+ return retrieval_status, formatted_metadata
68
85
 
69
86
 
70
87
  def _make_data_graph_from_parsed_resources(
@@ -99,6 +116,8 @@ def _create_graphs(
99
116
  api_card_shapes.parse(str(api_card_path))
100
117
  content_shapes = shapes.content + api_shapes
101
118
  card_shapes = shapes.cardinality + api_card_shapes
119
+ resources_in_db = _make_resource_in_db_graph(proj_info.resource_iris_in_db)
120
+ resources_in_db = _bind_prefixes_to_graph(resources_in_db, onto_iris)
102
121
  data_rdf = _bind_prefixes_to_graph(data_rdf, onto_iris)
103
122
  ontologies = _bind_prefixes_to_graph(ontologies, onto_iris)
104
123
  card_shapes = _bind_prefixes_to_graph(card_shapes, onto_iris)
@@ -110,6 +129,7 @@ def _create_graphs(
110
129
  cardinality_shapes=card_shapes,
111
130
  content_shapes=content_shapes,
112
131
  knora_api=knora_api,
132
+ resources_in_db_graph=resources_in_db,
113
133
  )
114
134
 
115
135
 
@@ -143,3 +163,10 @@ def _get_license_iris(shortcode: str, auth: AuthenticationClient) -> EnabledLice
143
163
  license_info = legal_client.get_licenses_of_a_project()
144
164
  iris = [x["id"] for x in license_info]
145
165
  return EnabledLicenseIris(iris)
166
+
167
+
168
+ def _make_resource_in_db_graph(resources_in_db: list[InfoForResourceInDB]) -> Graph:
169
+ g = Graph()
170
+ for r in resources_in_db:
171
+ g.add((URIRef(r.res_iri), RDF.type, URIRef(r.res_type)))
172
+ return g
@@ -104,7 +104,7 @@ def validate_parsed_resources(
104
104
  config: ValidateDataConfig,
105
105
  auth: AuthenticationClient,
106
106
  ) -> bool:
107
- rdf_graphs, used_iris = prepare_data_for_validation_from_parsed_resource(
107
+ rdf_graphs, used_iris, _ = prepare_data_for_validation_from_parsed_resource(
108
108
  parsed_resources=parsed_resources,
109
109
  authorship_lookup=authorship_lookup,
110
110
  permission_ids=permission_ids,
@@ -82,10 +82,11 @@ def _create_and_write_graphs(rdf_graphs: RDFGraphs, tmp_path: Path) -> None:
82
82
  card_shape_str = rdf_graphs.cardinality_shapes.serialize(format="ttl")
83
83
  content_shape_str = rdf_graphs.content_shapes.serialize(format="ttl")
84
84
  knora_api_str = rdf_graphs.knora_api.serialize(format="ttl")
85
+ res_in_db_str = rdf_graphs.resources_in_db_graph.serialize(format="ttl")
85
86
  turtle_paths_and_graphs = [
86
87
  (tmp_path / CARDINALITY_DATA_TTL, data_str),
87
88
  (tmp_path / CARDINALITY_SHACL_TTL, card_shape_str + ontos_str + knora_api_str),
88
- (tmp_path / CONTENT_DATA_TTL, data_str + ontos_str + knora_api_str),
89
+ (tmp_path / CONTENT_DATA_TTL, data_str + ontos_str + knora_api_str + res_in_db_str),
89
90
  (tmp_path / CONTENT_SHACL_TTL, content_shape_str + ontos_str + knora_api_str),
90
91
  ]
91
92
  for f_path, content in turtle_paths_and_graphs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dsp-tools
3
- Version: 17.0.0.post21
3
+ Version: 17.0.0.post23
4
4
  Summary: DSP-TOOLS is a Python package with a command line interface that helps you interact with a DaSCH service platform (DSP) server.
5
5
  Author: DaSCH - Swiss National Data and Service Center for the Humanities
6
6
  Author-email: DaSCH - Swiss National Data and Service Center for the Humanities <info@dasch.swiss>
@@ -110,14 +110,14 @@ dsp_tools/commands/validate_data/api_clients.py,sha256=8LFiCQMwS22gWXvGo7p4DDtI8
110
110
  dsp_tools/commands/validate_data/constants.py,sha256=Xr9iPYG4kpcgzUSy3ARjKv7dgSuMBVf2R69Uj7trcx0,2509
111
111
  dsp_tools/commands/validate_data/mappers.py,sha256=lA4Zdt2PHb4nvcOTv63oIPTI5Xs-5J2GSr3S1cDlZkM,7749
112
112
  dsp_tools/commands/validate_data/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
113
- dsp_tools/commands/validate_data/models/api_responses.py,sha256=zyEpXPSdd9hmtIC7dG9UBFtKyHhG7ZAtseO3qEZ_XKE,794
113
+ dsp_tools/commands/validate_data/models/api_responses.py,sha256=RrHwxyx1o2j9sVCwZktTTSnRXHeathNmQxk2RBxJ93E,920
114
114
  dsp_tools/commands/validate_data/models/input_problems.py,sha256=WZwM4LitbAuacCQIbwuo3hxaRvbC_iTZYH9lpozMc9I,3221
115
115
  dsp_tools/commands/validate_data/models/rdf_like_data.py,sha256=1TccR7UwC5idgrny6CQoFd-lPGzx7BdI8sorqWxgCv0,3313
116
- dsp_tools/commands/validate_data/models/validation.py,sha256=rMqDWg26Dbd6b9P450lEM6I0zdfbpNmbAUgxdLUsUAg,2263
116
+ dsp_tools/commands/validate_data/models/validation.py,sha256=okYFrLhaSQCGfa8A7gR6Wz-nv0xsmyN5LlNgSqfVfG4,2296
117
117
  dsp_tools/commands/validate_data/prepare_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
118
118
  dsp_tools/commands/validate_data/prepare_data/get_rdf_like_data.py,sha256=sU_VmMAvvNsjKkld6Coc_HJLt32nzXOimvKRxIbte-o,11620
119
- dsp_tools/commands/validate_data/prepare_data/make_data_graph.py,sha256=_PB0-FOys1_L-mRaH86tyZ8eP2OaKukDX9qYvDCThMA,3984
120
- dsp_tools/commands/validate_data/prepare_data/prepare_data.py,sha256=7s6X5BbIpUx1SJpn16BznhXoSyGeFYZJaA8wM0oaJ_I,6500
119
+ dsp_tools/commands/validate_data/prepare_data/make_data_graph.py,sha256=TANm9WA_z-oPGkoMIR2BGZrHtAkizDlnK_5WDVxQRoQ,4098
120
+ dsp_tools/commands/validate_data/prepare_data/prepare_data.py,sha256=2YLNbk4on0Qf6XE89guf168rsiqvSIibPiSG3laQR6A,7832
121
121
  dsp_tools/commands/validate_data/process_validation_report/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
122
122
  dsp_tools/commands/validate_data/process_validation_report/get_user_validation_message.py,sha256=fKYeJa2kVbWbynU56shkz3_HoT7cwsLPQhbmVIcTS28,14623
123
123
  dsp_tools/commands/validate_data/process_validation_report/query_validation_result.py,sha256=ln7zOq0LgkaVIoTNv2O72Z0tK6WX0UrbwAph-n0tD3E,22299
@@ -129,11 +129,11 @@ dsp_tools/commands/validate_data/sparql/construct_shacl.py,sha256=pB8sHn8FiAEiwe
129
129
  dsp_tools/commands/validate_data/sparql/legal_info_shacl.py,sha256=2yhn5HfCJFJpOTB-3XNWfxP1KwW3zKxDfqPdhN_Sazg,1522
130
130
  dsp_tools/commands/validate_data/sparql/value_shacl.py,sha256=iEpBm4X-jARhGQU21VDK2KvOtMCHTXJzpm08Dda7x1w,13068
131
131
  dsp_tools/commands/validate_data/utils.py,sha256=L3kpuhn46x-OHap9RnN9QwUQjFYpkQFlFXzFKQfy5ZE,1990
132
- dsp_tools/commands/validate_data/validate_data.py,sha256=DstcR1Me5oCCjDwCVadkCCSBCvCoktNdfp1o9hugWuM,12905
132
+ dsp_tools/commands/validate_data/validate_data.py,sha256=M7jAzju7NLuCjZikCZk2uvZI00ZRJNvci5Vqfwo2wg0,12908
133
133
  dsp_tools/commands/validate_data/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
134
134
  dsp_tools/commands/validate_data/validation/check_duplicate_files.py,sha256=8HU7GZkTMXj68WrVTXadtQujjEP_MvkOnQb4iVtEHt4,2228
135
135
  dsp_tools/commands/validate_data/validation/check_for_unknown_classes.py,sha256=Vhr1-nJzd3vzlwSoDJTljY-eFMpFLpTEy_zIEZb5MJs,2966
136
- dsp_tools/commands/validate_data/validation/get_validation_report.py,sha256=w9Kj7ETyLzg6Lpnr2qs7ryfxh63kZ54FWVPEetV7ebk,4108
136
+ dsp_tools/commands/validate_data/validation/get_validation_report.py,sha256=jvzFXzyG6bcSNzs6Buj_-NV85g9pwr9spMz_OBG8MQk,4201
137
137
  dsp_tools/commands/validate_data/validation/validate_ontology.py,sha256=R5-aD9cFc4KSLbT_IanhzSibx71uJX_dBBHgkoHtLKY,4783
138
138
  dsp_tools/commands/xmlupload/CLAUDE.md,sha256=EOmh0nPs5ne9iAFCdhG6LHYaYBn4hMkM86G8UfMMsaU,10547
139
139
  dsp_tools/commands/xmlupload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -260,7 +260,7 @@ dsp_tools/xmllib/models/res.py,sha256=c3edvilYZVDmv2O6Z36sSkHXcuKPAJLfWVpStDTMuJ
260
260
  dsp_tools/xmllib/models/root.py,sha256=x8_vrDSJ1pZUJUL8LR460dZe4Cg57G_Hy-Zfr2S29dw,13562
261
261
  dsp_tools/xmllib/value_checkers.py,sha256=Yx3r6_WoZ5Lev8Orp8yDzd03JvP2GBmFNSFT2dzrycM,10712
262
262
  dsp_tools/xmllib/value_converters.py,sha256=WMYS5hd1VlrLLBXnf6pv9yYoPBsv_2MxOO6xv-QsRW4,29218
263
- dsp_tools-17.0.0.post21.dist-info/WHEEL,sha256=M6du7VZflc4UPsGphmOXHANdgk8zessdJG0DBUuoA-U,78
264
- dsp_tools-17.0.0.post21.dist-info/entry_points.txt,sha256=qjRfEbkeAwLU_AE2Q-l4Y9irPNmu4Wna-3bfRp1bqV4,62
265
- dsp_tools-17.0.0.post21.dist-info/METADATA,sha256=c-CiHkhfevQLuSoAyhtEYoAA1CF4nWN8HoR5o7H6e_8,4285
266
- dsp_tools-17.0.0.post21.dist-info/RECORD,,
263
+ dsp_tools-17.0.0.post23.dist-info/WHEEL,sha256=M6du7VZflc4UPsGphmOXHANdgk8zessdJG0DBUuoA-U,78
264
+ dsp_tools-17.0.0.post23.dist-info/entry_points.txt,sha256=qjRfEbkeAwLU_AE2Q-l4Y9irPNmu4Wna-3bfRp1bqV4,62
265
+ dsp_tools-17.0.0.post23.dist-info/METADATA,sha256=xGTjapRxArzlKCmB7ia2yKNgLskGhfZtGNddQhR5iHM,4285
266
+ dsp_tools-17.0.0.post23.dist-info/RECORD,,