Skip to content

Commit

Permalink
Merge branch 'edmond/feature/bgs' into edmond/feature/bgs-redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondchuc committed Aug 7, 2023
2 parents de0697f + 0303b6a commit c06e544
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
56 changes: 21 additions & 35 deletions prez/renderers/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,7 @@ async def return_rdf(graph, mediatype, profile_headers):
return StreamingResponse(content=obj, media_type=mediatype, headers=profile_headers)


async def return_annotated_rdf(
graph: Graph,
profile_headers,
profile,
predicates_for_link_addition: dict,
mediatype="text/anot+turtle",
):
from prez.cache import tbox_cache

non_anot_mediatype = mediatype.replace("anot+", "")

cache = tbox_cache
async def get_annotations_graph(profile, graph, cache):
profile_annotation_props = get_annotation_predicates(profile)
queries_for_uncached, annotations_graph = await get_annotation_properties(
graph, **profile_annotation_props
Expand All @@ -98,36 +87,33 @@ async def return_annotated_rdf(
annotations_graph += anots_from_triplestore
cache += anots_from_triplestore

# TODO: this portion of the code requires refactoring.
# Duplicated fragment code below is required to ensure new predicates and values
# defined in the profiles get added to the `graph` and the labels of those
# values also get added to the `graph`.
return annotations_graph

# start of duplicated code fragment
graph += annotations_graph

profile_annotation_props = get_annotation_predicates(profile)
queries_for_uncached, annotations_graph = await get_annotation_properties(
graph, **profile_annotation_props
)
async def return_annotated_rdf(
graph: Graph,
profile_headers,
profile,
predicates_for_link_addition: dict,
mediatype="text/anot+turtle",
):
from prez.cache import tbox_cache

if queries_for_uncached is None:
anots_from_triplestore = Graph()
else:
anots_from_triplestore = await queries_to_graph([queries_for_uncached])
non_anot_mediatype = mediatype.replace("anot+", "")

if len(anots_from_triplestore) > 1:
annotations_graph += anots_from_triplestore
cache += anots_from_triplestore
# end duplicated code fragment
cache = tbox_cache

previous_triples_count = len(graph)

while True:
graph += await get_annotations_graph(profile, graph, cache)
if len(graph) == previous_triples_count:
break
previous_triples_count = len(graph)

generate_prez_links(graph, predicates_for_link_addition)

obj = io.BytesIO(
(graph + annotations_graph).serialize(
format=non_anot_mediatype, encoding="utf-8"
)
)
obj = io.BytesIO(graph.serialize(format=non_anot_mediatype, encoding="utf-8"))
return StreamingResponse(
content=obj, media_type=non_anot_mediatype, headers=profile_headers
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
ns1:link "/v/collection/brhl-prps:pggd" ;
.

dcterms:description
rdfs:label "Description"@en ;
dcterms:description "Description may include but is not limited to: an abstract, a table of contents, a graphical representation, or a free-text account of the resource."@en ;
.

dcterms:provenance
rdfs:label "Provenance"@en ;
dcterms:description "The statement may include a description of any changes successive custodians made to the resource."@en ;
Expand Down
5 changes: 5 additions & 0 deletions tests/data/vocprez/expected_responses/vocab_listing_anot.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
ns2:link "/v/vocab/def2:borehole-purpose-no-children" ;
.

dcterms:description
rdfs:label "Description"@en ;
dcterms:description "Description may include but is not limited to: an abstract, a table of contents, a graphical representation, or a free-text account of the resource."@en ;
.

dcterms:provenance
rdfs:label "Provenance"@en ;
dcterms:description "The statement may include a description of any changes successive custodians made to the resource."@en ;
Expand Down

0 comments on commit c06e544

Please sign in to comment.