Skip to content

Commit 42b1e5b

Browse files
committed
Support rdfData entries in bblock.json
1 parent 92755a1 commit 42b1e5b

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

ogc/bblocks/models.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,41 @@ def __init__(self, identifier: str, metadata_file: Path,
103103

104104
self.transforms_path = fp / 'transforms.yaml'
105105

106+
self.rdf_data_paths: list[PathOrUrl] = self._find_path_or_url('rdfData', ('data.ttl',))
107+
if not isinstance(self.rdf_data_paths, list):
108+
self.rdf_data_paths = [self.rdf_data_paths]
109+
106110
self.remote_cache_dir = self.annotated_path / 'remote_cache'
107111

108-
def _find_path_or_url(self, metadata_property: str, default_filenames: tuple[str, ...]):
109-
ref = self.metadata.get(metadata_property)
110-
if ref:
111-
if is_url(ref):
112-
result = ref
113-
else:
114-
result = self.files_path.joinpath(ref).resolve()
115-
else:
116-
result = default_filenames[0]
112+
def _find_path_or_url(self, metadata_property: str,
113+
default_filenames: tuple[str, ...]) -> PathOrUrl | list[PathOrUrl] | None:
114+
value = self.metadata.get(metadata_property)
115+
result = []
116+
single = True
117+
if value:
118+
single = isinstance(value, str)
119+
if single:
120+
value = [value]
121+
for ref in value:
122+
if ref:
123+
if is_url(ref):
124+
result.append(ref)
125+
else:
126+
result.append(self.files_path.joinpath(ref).resolve())
127+
128+
if not result:
129+
result = [default_filenames[0]]
117130
for fn in default_filenames:
118131
f = self.files_path / fn
119132
if f.is_file():
120-
result = f
133+
result[0] = f
121134
break
122135

123-
return PathOrUrl(result)
136+
if not result:
137+
return None
138+
139+
result = [PathOrUrl(r) for r in result]
140+
return result[0] if single else result
124141

125142
def __getattr__(self, item):
126143
return self.metadata.get(item)
@@ -257,6 +274,17 @@ def transforms(self) -> list:
257274
self._lazy_properties['transforms'] = transforms
258275
return self._lazy_properties['transforms']
259276

277+
@property
278+
def rdf_data(self) -> Graph | None:
279+
if 'rdf_data' not in self._lazy_properties:
280+
rdf_data = None
281+
if self.rdf_data_paths:
282+
rdf_data = Graph()
283+
for rdf_data_path in self.rdf_data_paths:
284+
rdf_data.parse(rdf_data_path.value)
285+
self._lazy_properties['rdf_data'] = rdf_data
286+
return self._lazy_properties['rdf_data']
287+
260288
def get_extra_test_resources(self) -> Generator[dict, None, None]:
261289
extra_tests_file = self.files_path / 'tests.yaml'
262290
if extra_tests_file.is_file():

ogc/bblocks/postprocess.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
154154
base_url, cwd if base_url else output_file_root
155155
) + '/'
156156

157+
if bblock.rdf_data_paths:
158+
bblock.metadata['rdfData'] = [
159+
p.with_base_url(base_url, cwd if base_url else output_file_root) for p in bblock.rdf_data_paths
160+
]
161+
157162
if not light:
158163
if not steps or 'tests' in steps:
159164
print(f" > Running tests for {bblock.identifier}", file=sys.stderr)

ogc/bblocks/schemas/bblock.schema.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,11 @@ properties:
232232
semanticUplift:
233233
description: Deprecated - configuration should go in semantic-uplift.yaml
234234
not: true
235-
235+
rdfData:
236+
description: |
237+
Array of file names (relative to the Building Block directory) or URLs with RDF content for this Building Block,
238+
such as ontology sources, profile descriptions, etc.
239+
If the data file is named `data.ttl`, this property can be omitted.
240+
type: array
241+
items:
242+
type: string

0 commit comments

Comments
 (0)