Skip to content

Commit

Permalink
Merge pull request #245 from RDFLib/david/members-flattened-and-focus…
Browse files Browse the repository at this point in the history
…-node-decl

Simplify prez:members declaration; add prez:FocusNode class to focus nodes
  • Loading branch information
lalewis1 committed Jul 24, 2024
2 parents 78fda68 + 281b16f commit ea539b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 1 addition & 3 deletions prez/services/link_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ async def add_links_to_graph_and_cache(
links_ids_graph_cache.quads((uri, PREZ["members"], None, uri))
)
if not existing_members_link:
members_bn = BNode()
quads.append((uri, PREZ["members"], members_bn, uri))
quads.append((members_bn, PREZ["link"], Literal(members_link), uri))
quads.append((uri, PREZ["members"], Literal(members_link), uri))
for quad in quads:
graph.add(quad[:3])
links_ids_graph_cache.add(quad)
Expand Down
12 changes: 11 additions & 1 deletion prez/services/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.responses import PlainTextResponse
from rdflib import URIRef, Literal
from rdflib.namespace import RDF
from sparql_grammar_pydantic import IRI, Var
from sparql_grammar_pydantic import IRI, Var, TriplesSameSubject

from prez.cache import endpoints_graph_cache
from prez.reference_data.prez_ns import PREZ, ALTREXT, ONT
Expand Down Expand Up @@ -54,6 +54,16 @@ async def listing_function(
if profile_nodeshape.tss_list:
construct_tss_list.extend(profile_nodeshape.tss_list)

# add focus node declaration if it's an annotated mediatype
if "anot+" in pmts.selected["mediatype"]:
construct_tss_list.append(
TriplesSameSubject.from_spo(
subject=profile_nodeshape.focus_node,
predicate=IRI(value="https://prez.dev/type"),
object=IRI(value="https://prez.dev/FocusNode"),
)
)

queries = []
main_query = PrezQueryConstructor(
construct_tss_list=construct_tss_list,
Expand Down
20 changes: 14 additions & 6 deletions prez/services/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time

from fastapi.responses import PlainTextResponse
from sparql_grammar_pydantic import TriplesSameSubject, IRI

from prez.models.query_params import QueryParams
from prez.reference_data.prez_ns import ALTREXT, ONT
Expand All @@ -16,11 +17,11 @@


async def object_function(
data_repo,
system_repo,
endpoint_structure,
pmts,
profile_nodeshape,
data_repo,
system_repo,
endpoint_structure,
pmts,
profile_nodeshape,
):
if pmts.selected["profile"] == ALTREXT["alt-profile"]:
none_keys = [
Expand Down Expand Up @@ -49,7 +50,14 @@ async def object_function(
original_endpoint_type=ONT["ObjectEndpoint"],
**none_kwargs,
)

if "anot+" in pmts.selected["mediatype"]:
profile_nodeshape.tss_list.append(
TriplesSameSubject.from_spo(
subject=profile_nodeshape.focus_node,
predicate=IRI(value="https://prez.dev/type"),
object=IRI(value="https://prez.dev/FocusNode"),
)
)
query = PrezQueryConstructor(
profile_triples=profile_nodeshape.tssp_list,
profile_gpnt=profile_nodeshape.gpnt_list,
Expand Down

0 comments on commit ea539b1

Please sign in to comment.