Skip to content

Commit

Permalink
Merge pull request #119 from RDFLib/edmond/catalog-listing
Browse files Browse the repository at this point in the history
Catalog object resource listing table metadata
  • Loading branch information
edmondchuc authored Jun 1, 2023
2 parents 98854a1 + af84be2 commit 73fa143
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 60 deletions.
15 changes: 14 additions & 1 deletion prez/reference_data/profiles/catprez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX prez: <https://prez.dev/>
PREFIX prof: <http://www.w3.org/ns/dx/prof/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
Expand Down Expand Up @@ -54,7 +55,19 @@ prez:CatPrezProfile
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass dcat:Catalog ;
altr-ext:outboundChildren dcterms:hasPart
altr-ext:outboundChildren dcterms:hasPart ;
sh:sequencePath (
dcterms:hasPart
dcterms:issued
) ;
sh:sequencePath (
dcterms:hasPart
dcterms:creator
) ;
sh:sequencePath (
dcterms:hasPart
dcterms:publisher
) ;
]
.

Expand Down
32 changes: 23 additions & 9 deletions prez/sparql/objects_listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def generate_listing_construct(
# item to a variable if it's a top level listing (this will utilise "class based" listing, where objects are listed
# based on them being an instance of a class), else use the URI of the "parent" off of which members will be listed.
# TODO collapse this to an inline expression below; include change in both object and listing queries
sequence_construct, sequence_construct_where = generate_sequence_construct(sequence_predicates, uri_or_tl_item)
sequence_construct, sequence_construct_where = generate_sequence_construct(
sequence_predicates, uri_or_tl_item
)
query = dedent(
f"""
PREFIX dcterms: <http://purl.org/dc/terms/>
Expand Down Expand Up @@ -159,25 +161,35 @@ def generate_item_construct(focus_item, profile: URIRef):
uri_or_search_item = "?search_result_uri"
else:
uri_or_search_item = f"<{focus_item.uri}>"

sequence_construct, sequence_construct_where = generate_sequence_construct(
sequence_predicates, uri_or_search_item
)

construct_query = dedent(
f""" PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prez: <https://prez.dev/>
CONSTRUCT {{
{f'{search_query_construct()} {chr(10)}' if search_query else ""}\
\t{uri_or_search_item} ?p ?o1 .
{generate_sequence_construct(f"{uri_or_search_item}", sequence_predicates) if sequence_predicates else ""}
{sequence_construct}
{f'{chr(9)}?s ?inbound_p {uri_or_search_item} .' if inverse_predicates else ""}
{generate_bnode_construct(bnode_depth)} \
\n}}
WHERE {{
{{ {f'{focus_item.populated_query}' if search_query else ""} }}
{uri_or_search_item} ?p ?o1 . {chr(10)} \
{f'OPTIONAL {{ {generate_sequence_construct(uri_or_search_item, sequence_predicates)} }}' if sequence_predicates else chr(10)} \
{f'?s ?inbound_p {uri_or_search_item}{chr(10)}' if inverse_predicates else chr(10)} \
{generate_include_predicates(include_predicates)} \
{generate_inverse_predicates(inverse_predicates)} \
{generate_bnode_select(bnode_depth)}
{{
{uri_or_search_item} ?p ?o1 . {chr(10)} \
{f'?s ?inbound_p {uri_or_search_item}{chr(10)}' if inverse_predicates else chr(10)} \
{generate_include_predicates(include_predicates)} \
{generate_inverse_predicates(inverse_predicates)} \
{generate_bnode_select(bnode_depth)}\
}}
UNION {{
{sequence_construct_where}\
}}
}}
"""
)
Expand Down Expand Up @@ -296,7 +308,9 @@ def _generate_sequence_construct(object_uri, sequence_predicates, path_n=0):
return ""


def generate_sequence_construct(sequence_predicates: list[list[URIRef]], uri_or_tl_item: str) -> tuple[str, str]:
def generate_sequence_construct(
sequence_predicates: list[list[URIRef]], uri_or_tl_item: str
) -> tuple[str, str]:
sequence_construct = ""
sequence_construct_where = ""
if sequence_predicates:
Expand Down
4 changes: 1 addition & 3 deletions tests/catprez/test_endpoints_catprez.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from time import sleep

import pytest
from rdflib import Graph, URIRef, RDFS, RDF, DCAT
from rdflib import Graph, URIRef, RDF, DCAT

PREZ_DIR = os.getenv("PREZ_DIR")
LOCAL_SPARQL_STORE = os.getenv("LOCAL_SPARQL_STORE")
Expand Down Expand Up @@ -51,7 +51,6 @@ def a_resource_link(cp_test_client, a_catalog_link):
return link


# @pytest.mark.xfail
def test_catalog_anot(cp_test_client, a_catalog_link):
with cp_test_client as client:
r = client.get(f"{a_catalog_link}?_mediatype=text/anot+turtle")
Expand All @@ -65,7 +64,6 @@ def test_catalog_anot(cp_test_client, a_catalog_link):
)


# @pytest.mark.xfail
def test_resource_anot(cp_test_client, a_resource_link):
with cp_test_client as client:
r = client.get(f"{a_resource_link}?_mediatype=text/anot+turtle")
Expand Down
54 changes: 33 additions & 21 deletions tests/data/catprez/expected_responses/catalog_anot.ttl
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix ns1: <https://prez.dev/> .
@prefix ns2: <http://www.w3.org/ns/prov#> .
@prefix ns3: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ns1: <https://prez.dev/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

ns3:identifier rdfs:label "Identifier"@en .
dcterms:identifier
rdfs:label "Identifier"@en ;
.

<https://w3id.org/idn/dataset/agents> a dcat:Catalog ;
ns3:created "2022-08-15"^^xsd:date ;
ns3:description """The Indigenous Data Network's catalogue of Agents. This catalogue contains instances of Agents - People and Organisations - related to the holding of indigenous data. This includes non-indigenous Agents
<https://w3id.org/idn/dataset/agents>
a dcat:Catalog ;
dcterms:created "2022-08-15"^^xsd:date ;
dcterms:description """The Indigenous Data Network's catalogue of Agents. This catalogue contains instances of Agents - People and Organisations - related to the holding of indigenous data. This includes non-indigenous Agents
This catalogue extends on standard Agent information to include properties useful to understand the indigeneity of Agents: whether they are or not, or how much they are, indigenous"""@en ;
ns3:hasPart <https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa> ;
ns3:identifier "idnac"^^xsd:token ;
ns3:modified "2022-08-15"^^xsd:date ;
ns3:title "IDN Agents Catalogue" ;
ns2:qualifiedAttribution [ dcat:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/author>,
<http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian>,
dcterms:hasPart <https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa> ;
dcterms:identifier "idnac"^^xsd:token ;
dcterms:modified "2022-08-15"^^xsd:date ;
dcterms:title "IDN Agents Catalogue" ;
prov:qualifiedAttribution [
dcat:hadRole
<http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/author> ,
<http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian> ,
<http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/owner> ;
ns2:agent <https://linked.data.gov.au/org/idn> ] .
prov:agent <https://linked.data.gov.au/org/idn>
] ;
.

<https://linked.data.gov.au/org/idn> rdfs:label "Indigenous Data Network" .
<https://linked.data.gov.au/org/idn>
rdfs:label "Indigenous Data Network" ;
.

<https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa> ns3:description """This study contains time series of data of the Annual Aboriginal Census for Australia, Australian Capital Territory, New South Wales, Northern Territory, Queensland, South Australia, Tasmania, Victoria and Western Australia from 1921 to 1944.
<https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa>
dcterms:description """This study contains time series of data of the Annual Aboriginal Census for Australia, Australian Capital Territory, New South Wales, Northern Territory, Queensland, South Australia, Tasmania, Victoria and Western Australia from 1921 to 1944.
Special care notice:
Aboriginal and Torres Strait Islander people, researchers and other users should be aware that material in this dataset may contain material that is considered offensive. The data has been retained in its original format because it represents an evidential record of language, beliefs or other cultural situations at a point in time.""" ;
ns3:title "Annual Aboriginal Census,1921-1944 - South Australia" ;
ns1:link "/c/catalogs/dtst:agents/dtsts:au.edu.anu.ada.ddi.20002-sa" .
dcterms:issued "2011-07-22"^^xsd:date ;
dcterms:title "Annual Aboriginal Census,1921-1944 - South Australia" ;
ns1:link "/c/catalogs/dtst:agents/dtsts:au.edu.anu.ada.ddi.20002-sa" ;
.
65 changes: 39 additions & 26 deletions tests/data/catprez/expected_responses/resource_anot.ttl
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
@prefix ns1: <https://example.com/> .
@prefix ns2: <http://www.w3.org/ns/prov#> .
@prefix ns3: <http://purl.org/dc/terms/> .
@prefix ns4: <http://www.w3.org/ns/dcat#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ns1: <https://example.com/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

ns3:identifier rdfs:label "Identifier"@en .
dcterms:identifier
rdfs:label "Identifier"@en ;
.

<https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa> a ns4:Resource ;
ns3:accessRights <https://linked.data.gov.au/def/data-access-rights/metadata-only> ;
ns3:description """This study contains time series of data of the Annual Aboriginal Census for Australia, Australian Capital Territory, New South Wales, Northern Territory, Queensland, South Australia, Tasmania, Victoria and Western Australia from 1921 to 1944.
<https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa>
a dcat:Resource ;
dcterms:accessRights <https://linked.data.gov.au/def/data-access-rights/metadata-only> ;
dcterms:description """This study contains time series of data of the Annual Aboriginal Census for Australia, Australian Capital Territory, New South Wales, Northern Territory, Queensland, South Australia, Tasmania, Victoria and Western Australia from 1921 to 1944.
Special care notice:
Aboriginal and Torres Strait Islander people, researchers and other users should be aware that material in this dataset may contain material that is considered offensive. The data has been retained in its original format because it represents an evidential record of language, beliefs or other cultural situations at a point in time.""" ;
ns3:identifier "AAC-SA"^^xsd:token ;
ns3:issued "2011-07-22"^^xsd:date ;
ns3:license "All Rights Reserved" ;
ns3:rights "Copyright © 2011, The Australian National University. All rights reserved." ;
ns3:spatial <https://linked.data.gov.au/dataset/asgsed3/STE/4>,
dcterms:identifier "AAC-SA"^^xsd:token ;
dcterms:issued "2011-07-22"^^xsd:date ;
dcterms:license "All Rights Reserved" ;
dcterms:rights "Copyright © 2011, The Australian National University. All rights reserved." ;
dcterms:spatial
<https://linked.data.gov.au/dataset/asgsed3/STE/4> ,
<https://linked.data.gov.au/dataset/asgsed3/STE/7> ;
ns3:temporal "1921-1944" ;
ns3:title "Annual Aboriginal Census,1921-1944 - South Australia" ;
ns4:accessURL "https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa"^^xsd:anyURI ;
ns4:theme <https://w3id.org/idn/def/idn-th/subject>,
dcterms:temporal "1921-1944" ;
dcterms:title "Annual Aboriginal Census,1921-1944 - South Australia" ;
dcat:accessURL "https://www.atsida.edu.au/archive/datasets/au.edu.anu.ada.ddi.20002-sa"^^xsd:anyURI ;
dcat:theme
<https://w3id.org/idn/def/idn-th/subject> ,
<https://w3id.org/idn/def/indigeneity/about-indigenous-people> ;
ns2:qualifiedAttribution [ ns4:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/originator> ;
ns2:agent "Gordon Briscoe, Len Smith" ],
[ ns4:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/rightsHolder> ;
ns2:agent <https://linked.data.gov.au/org/anu> ],
[ ns4:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian> ;
ns2:agent "ATSIDA.1" ] ;
prov:qualifiedAttribution
[
dcat:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/originator> ;
prov:agent "Gordon Briscoe, Len Smith"
] ,
[
dcat:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/rightsHolder> ;
prov:agent <https://linked.data.gov.au/org/anu>
] ,
[
dcat:hadRole <http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian> ;
prov:agent "ATSIDA.1"
] ;
ns1:home "https://www.atsida.edu.au/" ;
ns1:notes "The Annual Aboriginal Census is considered as a significant official source of Aboriginal population statistics. It was conducted annually in June from 1921 to 1944, exempting the war years between 1941 and 1944 in each State and Territory. The 1944 census was incomplete with New South Wales not taking part at all. Enumeration of Aboriginal populations was poor and difficulties in classification occurred. The Census was a collaboration of the Commonwealth Bureau of Census and Statistics who initiated the study, State and Territory Statisticians, the Protector of Aborigines, and local police officers who conducted the enumeration. The Annual Aboriginal Census is also referred to as the Annual Census of Aborigines and Police Census." .
ns1:notes "The Annual Aboriginal Census is considered as a significant official source of Aboriginal population statistics. It was conducted annually in June from 1921 to 1944, exempting the war years between 1941 and 1944 in each State and Territory. The 1944 census was incomplete with New South Wales not taking part at all. Enumeration of Aboriginal populations was poor and difficulties in classification occurred. The Census was a collaboration of the Commonwealth Bureau of Census and Statistics who initiated the study, State and Territory Statisticians, the Protector of Aborigines, and local police officers who conducted the enumeration. The Annual Aboriginal Census is also referred to as the Annual Census of Aborigines and Police Census." ;
.

0 comments on commit 73fa143

Please sign in to comment.