diff --git a/prez/reference_data/profiles/catprez_default_profiles.ttl b/prez/reference_data/profiles/catprez_default_profiles.ttl index 215befd3..21bcd1b6 100644 --- a/prez/reference_data/profiles/catprez_default_profiles.ttl +++ b/prez/reference_data/profiles/catprez_default_profiles.ttl @@ -5,6 +5,7 @@ PREFIX geo: PREFIX owl: PREFIX prez: PREFIX prof: +PREFIX prov: PREFIX rdf: PREFIX rdfs: PREFIX sh: @@ -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 + ) ; ] . diff --git a/prez/sparql/objects_listings.py b/prez/sparql/objects_listings.py index 00dab07e..8db5e990 100644 --- a/prez/sparql/objects_listings.py +++ b/prez/sparql/objects_listings.py @@ -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: @@ -159,6 +161,11 @@ 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: PREFIX rdfs: @@ -166,18 +173,23 @@ def generate_item_construct(focus_item, profile: URIRef): 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}\ + }} }} """ ) @@ -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: diff --git a/tests/catprez/test_endpoints_catprez.py b/tests/catprez/test_endpoints_catprez.py index aaf0098e..bdefdc08 100644 --- a/tests/catprez/test_endpoints_catprez.py +++ b/tests/catprez/test_endpoints_catprez.py @@ -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") @@ -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") @@ -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") diff --git a/tests/data/catprez/expected_responses/catalog_anot.ttl b/tests/data/catprez/expected_responses/catalog_anot.ttl index 15d0524f..63c8c996 100644 --- a/tests/data/catprez/expected_responses/catalog_anot.ttl +++ b/tests/data/catprez/expected_responses/catalog_anot.ttl @@ -1,31 +1,43 @@ -@prefix dcat: . -@prefix ns1: . -@prefix ns2: . -@prefix ns3: . -@prefix rdfs: . -@prefix xsd: . +PREFIX dcat: +PREFIX dcterms: +PREFIX ns1: +PREFIX prov: +PREFIX rdfs: +PREFIX xsd: -ns3:identifier rdfs:label "Identifier"@en . +dcterms:identifier + rdfs:label "Identifier"@en ; +. - 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 + + 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 ; - ns3:identifier "idnac"^^xsd:token ; - ns3:modified "2022-08-15"^^xsd:date ; - ns3:title "IDN Agents Catalogue" ; - ns2:qualifiedAttribution [ dcat:hadRole , - , + dcterms:hasPart ; + dcterms:identifier "idnac"^^xsd:token ; + dcterms:modified "2022-08-15"^^xsd:date ; + dcterms:title "IDN Agents Catalogue" ; + prov:qualifiedAttribution [ + dcat:hadRole + , + , ; - ns2:agent ] . + prov:agent + ] ; +. - rdfs:label "Indigenous Data Network" . + + rdfs:label "Indigenous Data Network" ; +. - 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. + + 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" ; +. \ No newline at end of file diff --git a/tests/data/catprez/expected_responses/resource_anot.ttl b/tests/data/catprez/expected_responses/resource_anot.ttl index eee95e33..c4995f06 100644 --- a/tests/data/catprez/expected_responses/resource_anot.ttl +++ b/tests/data/catprez/expected_responses/resource_anot.ttl @@ -1,34 +1,47 @@ -@prefix ns1: . -@prefix ns2: . -@prefix ns3: . -@prefix ns4: . -@prefix rdfs: . -@prefix xsd: . +PREFIX dcat: +PREFIX dcterms: +PREFIX ns1: +PREFIX prov: +PREFIX rdfs: +PREFIX xsd: -ns3:identifier rdfs:label "Identifier"@en . +dcterms:identifier + rdfs:label "Identifier"@en ; +. - a ns4:Resource ; - ns3:accessRights ; - 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. + + a dcat:Resource ; + dcterms:accessRights ; + 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 , + 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 + , ; - 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 , + 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 + , ; - ns2:qualifiedAttribution [ ns4:hadRole ; - ns2:agent "Gordon Briscoe, Len Smith" ], - [ ns4:hadRole ; - ns2:agent ], - [ ns4:hadRole ; - ns2:agent "ATSIDA.1" ] ; + prov:qualifiedAttribution + [ + dcat:hadRole ; + prov:agent "Gordon Briscoe, Len Smith" + ] , + [ + dcat:hadRole ; + prov:agent + ] , + [ + dcat:hadRole ; + 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." ; +. \ No newline at end of file