Skip to content

Commit

Permalink
Add semantic-uplift transform type
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Oct 21, 2024
1 parent b762fc0 commit d42a292
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions ogc/bblocks/schemas/transforms.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ $defs:
- sparql-update
- json-ld-frame
- jq
- semantic-uplift
- description: Other identifiers are also accepted
$ref: '#/$defs/nonEmptyString'

Expand Down
31 changes: 31 additions & 0 deletions ogc/bblocks/transformers/semantic-uplift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
import json
from typing import AnyStr

from ogc.na.util import load_yaml
from rdflib import Graph

from ogc.bblocks.models import TransformMetadata, Transformer
from ogc.na import ingest_json

transform_type = 'semantic-uplift'

default_inputs = [
'application/json',
]

default_outputs = [
'text/turtle',
'rdf/xml',
]

class SemanticUpliftTransformer(Transformer):

def __init__(self):
super().__init__([transform_type], default_inputs, default_outputs)

def do_transform(self, metadata: TransformMetadata) -> AnyStr | None:
uplift_def = load_yaml(content=metadata.transform_content)
uplifted = json.dumps(ingest_json.uplift_json(json.loads(metadata.input_data), uplift_def))
data_graph = Graph().parse(data=uplifted, format='json-ld')
return data_graph.serialize(format=metadata.target_mime_type)

0 comments on commit d42a292

Please sign in to comment.