Skip to content

Commit d42a292

Browse files
committed
Add semantic-uplift transform type
1 parent b762fc0 commit d42a292

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

ogc/bblocks/schemas/transforms.schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ $defs:
6868
- sparql-update
6969
- json-ld-frame
7070
- jq
71+
- semantic-uplift
7172
- description: Other identifiers are also accepted
7273
$ref: '#/$defs/nonEmptyString'
7374

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
import json
3+
from typing import AnyStr
4+
5+
from ogc.na.util import load_yaml
6+
from rdflib import Graph
7+
8+
from ogc.bblocks.models import TransformMetadata, Transformer
9+
from ogc.na import ingest_json
10+
11+
transform_type = 'semantic-uplift'
12+
13+
default_inputs = [
14+
'application/json',
15+
]
16+
17+
default_outputs = [
18+
'text/turtle',
19+
'rdf/xml',
20+
]
21+
22+
class SemanticUpliftTransformer(Transformer):
23+
24+
def __init__(self):
25+
super().__init__([transform_type], default_inputs, default_outputs)
26+
27+
def do_transform(self, metadata: TransformMetadata) -> AnyStr | None:
28+
uplift_def = load_yaml(content=metadata.transform_content)
29+
uplifted = json.dumps(ingest_json.uplift_json(json.loads(metadata.input_data), uplift_def))
30+
data_graph = Graph().parse(data=uplifted, format='json-ld')
31+
return data_graph.serialize(format=metadata.target_mime_type)

0 commit comments

Comments
 (0)