Skip to content

Commit

Permalink
Fixes for shaclRules processing
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Nov 7, 2023
1 parent ba446a7 commit 82e65db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:

if base_url:
if bblock.shaclRules:
bblock.metadata['shaclRules'] = {k: [urljoin(base_url, s) for s in v]
bblock.metadata['shaclRules'] = {k: [urljoin(base_url, str(s)) for s in v]
for k, v in bblock.shaclRules.items()}
if bblock.transforms:
bblock.metadata['transforms'] = []
Expand Down
9 changes: 6 additions & 3 deletions ogc/bblocks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,11 @@ def get_inherited_shacl_rules(self, identifier: str) -> dict[str, set[str | Path
else:
dep_rules = dep.get('shaclRules')
if dep_rules:
for inh_id, inh_rules in dep_rules.items():
rules.setdefault(inh_id, set()).update(inh_rules)
if isinstance(dep_rules, list):
rules.setdefault(dep.get('itemIdentifier'), set()).update(dep_rules)
elif isinstance(dep_rules, dict):
for inh_id, inh_rules in dep_rules.items():
rules.setdefault(inh_id, set()).update(inh_rules)
return rules

def get(self, identifier: str):
Expand Down Expand Up @@ -768,7 +771,7 @@ def walk(subschema, schema_id: str | Path, is_properties: bool = False) -> tuple

schema_version = subschema.pop('$schema', None)
schema_id = subschema.pop('$id', schema_id)
if '$ref' in subschema:
if isinstance(subschema.get('$ref'), str):

ref = f"{schema_url}#/x-defs/{get_ref_mapping(schema_id, subschema.pop('$ref'))}"

Expand Down
2 changes: 1 addition & 1 deletion ogc/bblocks/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,14 @@ def validate_test_resources(bblock: BuildingBlock,
all_shacl_files.append(shacl_file)
shacl_graph.parse(shacl_file, format='turtle')
inherited_shacl_rules[shacl_bblock] = bblock_shacl_files
bblock.metadata['shaclRules'] = inherited_shacl_rules

for sc in bblock.shaclClosures or ():
bblock_shacl_closure.parse(bblock.resolve_file(sc), format='turtle')
except HTTPError as e:
shacl_error = f"Error retrieving {e.url}: {e}"
except Exception as e:
shacl_error = str(e)
bblock.metadata['shaclRules'] = inherited_shacl_rules

if not bblock.tests_dir.is_dir() and not bblock.examples:
return final_result, test_count, report_to_dict(bblock, None, base_url)
Expand Down

0 comments on commit 82e65db

Please sign in to comment.