Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix alt profiles SKOS turtle serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascar committed Aug 20, 2024
1 parent 16de2fc commit ce3c0ea
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions vocprez/model/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def _render_skos_rdf(self):
g.bind("dct", DCTERMS)
g.bind("skos", SKOS)

cs = URIRef(self.concept.vocab_uri)
g.bind("cs", cs)
c = URIRef(self.concept.uri)
g.bind("", "/".join(str(c).split("/")[:-1]) + "/")

# Concept SKOS metadata
g.add((
Expand All @@ -79,24 +82,27 @@ def _render_skos_rdf(self):
SKOS.definition,
Literal(self.concept.definition, lang=config.DEFAULT_LANGUAGE)
))
g.add((c, SKOS.inScheme, cs))

if self.concept.related_instances is not None:
for prop in self.concept.related_instances:
if str(prop.value).startswith("http"):
g.add((c, URIRef(prop.uri), URIRef(prop.value)))
else:
g.add((c, URIRef(prop.uri), Literal(prop.value)))
for k, v in self.concept.related_instances.items():
for prop in v:
if str(prop.value).startswith("http"):
g.add((c, URIRef(prop.uri), URIRef(prop.value)))
else:
g.add((c, URIRef(prop.uri), Literal(prop.value)))

if self.concept.other_properties is not None:
for prop in self.concept.other_properties:
if str(prop.value).startswith("http"):
g.add((c, URIRef(prop.uri), URIRef(prop.value)))
else:
g.add((c, URIRef(prop.uri), Literal(prop.value)))
for v in self.concept.other_properties:
for prop in v:
if str(prop.value).startswith("http"):
g.add((c, URIRef(prop.uri), URIRef(prop.value)))
else:
g.add((c, URIRef(prop.uri), Literal(prop.value)))

# serialise in the appropriate RDF format
if self.mediatype in ["application/rdf+json", "application/json"]:
graph_text = g.serialize(format="json-ld")
if self.mediatype in ["application/ld+json", "application/json"]:
graph_text = g.serialize(format="turtle")
else:
graph_text = g.serialize(format=self.mediatype)

Expand Down

0 comments on commit ce3c0ea

Please sign in to comment.