Skip to content

Commit 67b6527

Browse files
committed
Deprecate rdfData in favor of resources with role 'data'
- Add 'resources' property to bblock.schema.yaml with role, ref, format, conformsTo, and title fields; clarify it is for resources that don't fit dedicated properties like schema/ontology/ldContext - Mark rdfData as deprecated (schema + warning at load time); convert any rdfData entries to resources automatically for backward compatibility - Auto-discover data.ttl and add it as a resource if not already present - Resolve resources[].ref paths with base_url in postprocess.py - Remove dead rdf_data / rdf_data_paths code (the loaded graph was never used) - register-context.yaml already updated with resources JSON-LD context
1 parent d9ddc99 commit 67b6527

4 files changed

Lines changed: 82 additions & 22 deletions

File tree

ogc/bblocks/models.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,26 @@ def __init__(self, identifier: str, metadata_file: Path,
124124
if not self.transforms_path.is_file() and (alt_tp := fp / 'transforms.yml').is_file():
125125
self.transforms_path = alt_tp
126126

127-
self.rdf_data_paths: list[PathOrUrl] | PathOrUrl = self._find_path_or_url('rdfData', ('data.ttl',))
128-
if not isinstance(self.rdf_data_paths, list):
129-
self.rdf_data_paths = [self.rdf_data_paths]
127+
if 'rdfData' in self.metadata:
128+
logger.warning("Building block %s: 'rdfData' is deprecated; use 'resources' with role 'data' instead",
129+
identifier)
130+
rdf_data_values = self.metadata.pop('rdfData')
131+
if isinstance(rdf_data_values, str):
132+
rdf_data_values = [rdf_data_values]
133+
resources = self.metadata.setdefault('resources', [])
134+
for ref in rdf_data_values:
135+
resources.append({'role': 'data', 'ref': ref, 'format': 'text/turtle'})
136+
137+
data_ttl = fp / 'data.ttl'
138+
if data_ttl.is_file():
139+
resources = self.metadata.setdefault('resources', [])
140+
existing_data_refs = {
141+
(fp / r['ref']).resolve() if not is_url(r.get('ref', '')) else None
142+
for r in resources
143+
if r.get('role') == 'data' and r.get('ref')
144+
}
145+
if data_ttl.resolve() not in existing_data_refs:
146+
resources.append({'role': 'data', 'ref': 'data.ttl', 'format': 'text/turtle'})
130147

131148
self.remote_cache_dir = self.annotated_path / 'remote_cache'
132149

@@ -333,17 +350,6 @@ def transforms(self) -> list:
333350
self._lazy_properties['transforms'] = transforms
334351
return self._lazy_properties['transforms']
335352

336-
@property
337-
def rdf_data(self) -> Graph | None:
338-
if 'rdf_data' not in self._lazy_properties:
339-
rdf_data = None
340-
if self.rdf_data_paths:
341-
rdf_data = Graph()
342-
for rdf_data_path in self.rdf_data_paths:
343-
rdf_data.parse(rdf_data_path.value)
344-
self._lazy_properties['rdf_data'] = rdf_data
345-
return self._lazy_properties['rdf_data']
346-
347353
def get_extra_test_resources(self) -> Generator[dict, None, None]:
348354
extra_tests_file = self.files_path / 'tests.yaml'
349355
try:

ogc/bblocks/postprocess.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
186186
base_url, cwd if base_url else output_file_root
187187
) + '/'
188188

189-
if bblock.rdf_data_paths:
190-
bblock.metadata['rdfData'] = [
191-
p.with_base_url(base_url, cwd if base_url else output_file_root)
192-
for p in bblock.rdf_data_paths if p.is_file()
193-
]
189+
for resource in bblock.metadata.get('resources', []):
190+
ref = resource.get('ref')
191+
if ref and not is_url(ref):
192+
resource['ref'] = PathOrUrl(bblock.files_path / ref).with_base_url(
193+
base_url, cwd if base_url else output_file_root
194+
)
194195

195196
if not light:
196197
if not steps or 'tests' in steps:

ogc/bblocks/register-context.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,25 @@ context:
162162
rdfType:
163163
'@id': rdfs:subClassOf
164164
'@type': '@id'
165+
resources:
166+
'@id': prof:hasResource
167+
'@context':
168+
role:
169+
'@id': prof:hasRole
170+
'@type': '@id'
171+
constraints: role:constraints
172+
example: role:example
173+
guidance: role:guidance
174+
mapping: role:mapping
175+
schema: role:schema
176+
specification: role:specification
177+
validation: role:validation
178+
vocabulary: role:vocabulary
179+
data: role:data
180+
ref:
181+
'@id': 'prof:hasArtifact'
182+
'@type': '@id'
183+
format: dct:format
184+
conformsTo:
185+
'@id': dct:conformsTo
186+
'@type': '@id'

ogc/bblocks/schemas/bblock.schema.yaml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,42 @@ properties:
235235
semanticUplift:
236236
description: Deprecated - configuration should go in semantic-uplift.yaml
237237
not: true
238+
resources:
239+
description: |
240+
List of external resources associated with this Building Block
241+
that don't fit in other dedicated properties (e.g. schema, ontology, ldContext).
242+
type: array
243+
items:
244+
type: object
245+
required: [role, ref, format]
246+
properties:
247+
title:
248+
description: Human-readable title for the resource.
249+
type: string
250+
role:
251+
description: Role or relationship of this resource to the Building Block. Can be a well-known role name or a URI.
252+
oneOf:
253+
- enum: [constraints, example, guidance, mapping, schema, specification, validation, vocabulary, data]
254+
- type: string
255+
format: uri
256+
pattern: ^https?://.*
257+
ref:
258+
description: |
259+
File name (relative to the Building Block directory) or URL for the resource.
260+
type: string
261+
format:
262+
description: MIME type for the resource (e.g. application/json, text/turtle).
263+
type: string
264+
pattern: '^\w+/[\w.+\-]+$'
265+
conformsTo:
266+
description: URI of a profile or specification that the resource conforms to.
267+
type: string
268+
pattern: '^[a-zA-Z][a-zA-Z0-9+\-.]*:.+'
238269
rdfData:
239270
description: |
240-
Array of file names (relative to the Building Block directory) or URLs with RDF content for this Building Block,
241-
such as ontology sources, profile descriptions, etc.
242-
If the data file is named `data.ttl`, this property can be omitted.
271+
Deprecated. Use 'resources' with role 'data' instead.
272+
Array of file names (relative to the Building Block directory) or URLs with RDF content for this Building Block.
273+
deprecated: true
243274
type: array
244275
items:
245276
type: string

0 commit comments

Comments
 (0)