Skip to content

Commit

Permalink
fix(rdf): inject schema:identifier (#99)
Browse files Browse the repository at this point in the history
* fix(rdf): inject schema:identifier

* chore: add comment NOTE on linkml rdf dumper workaround
  • Loading branch information
cmdoret authored Aug 12, 2024
1 parent 8692a5d commit 6b9c2e3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion modos/helpers/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,29 @@ def instance_to_graph(instance) -> Graph:
p.prefix_prefix: URIRef(p.prefix_reference)
for p in load_prefixmap().values()
}
return rdflib_dumper.as_rdf_graph(
g = rdflib_dumper.as_rdf_graph(
instance,
prefix_map=prefixes,
schemaview=load_schema(),
)
# NOTE: This is a hack to get around the fact that the linkml's
# rdf dumper does not iunclude schema:identifier in the graph.
# Patch schema -> http://schema.org (rdflib's default is https)
g.bind("schema", "http://schema.org/", replace=True)
try:
id_slot = (
load_schema().get_identifier_slot(type(instance).__name__).slot_uri
)
g.add(
(
URIRef(instance.id),
g.namespace_manager.expand_curie(str(id_slot)),
URIRef(instance.id),
)
)
except AttributeError:
pass
return g


def get_slot_range(slot_name: str) -> str:
Expand Down

0 comments on commit 6b9c2e3

Please sign in to comment.