Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify prez:members declaration; add prez:FocusNode class to focus nodes #245

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading