Skip to content

Commit

Permalink
restructure Catprez Endpoints and add annotation listings to root end…
Browse files Browse the repository at this point in the history
…point (#164)

* restructure Catprez Endpoints
add annotation listings to root endpoint /

* blacked code

* Test passes locally - xfail pending change to pyoxigraph testing
  • Loading branch information
recalcitrantsupplant authored Nov 8, 2023
1 parent 3c7c915 commit 91ede3c
Show file tree
Hide file tree
Showing 28 changed files with 1,520 additions and 244 deletions.
8 changes: 8 additions & 0 deletions dev/dev-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def setup():
"application/octet-stream",
),
),
(
"myfile17",
(
"agents.ttl",
open("tests/data/catprez/input/pd_democat.ttl", "rb"),
"application/octet-stream",
),
),
(
"myfile16",
(
Expand Down
21 changes: 0 additions & 21 deletions prez/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,6 @@ async def app_shutdown():
await async_client.aclose()


@app.get("/", summary="Home page", tags=["Prez"])
async def index(request: Request):
"""Returns the following information about the API"""
# TODO connegp on request. don't need profiles for this
from prez.cache import (
prez_system_graph,
tbox_cache,
) # importing at module level will get the empty graph before it's populated

prez_system_graph.add(
(
URIRef(settings.system_uri),
PREZ.currentTBOXCacheSize,
Literal(len(tbox_cache)),
)
)
return await return_rdf(
prez_system_graph, mediatype="text/anot+turtle", profile_headers={}
)


def _get_sparql_service_description(request, format):
"""Return an RDF description of PROMS' read only SPARQL endpoint in a requested format
:param rdf_fmt: 'turtle', 'n3', 'xml', 'json-ld'
Expand Down
9 changes: 4 additions & 5 deletions prez/models/profiles_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rdflib import URIRef, PROF, Namespace

from prez.cache import profiles_graph_cache
from prez.config import settings
from prez.services.curie_functions import get_uri_for_curie_id, get_curie_id_for_uri
from prez.services.model_methods import get_classes

Expand Down Expand Up @@ -38,9 +39,7 @@ def populate(cls, values):
r = profiles_graph_cache.query(q)
if len(r.bindings) > 0:
values["classes"] = frozenset([prof.get("class") for prof in r.bindings])

values["label"] = profiles_graph_cache.value(
URIRef(values["uri"]),
URIRef("http://www.w3.org/ns/dx/conneg/altr-ext#hasLabelPredicate"),
)
label = values.get("label")
if not label:
values["label"] = settings.label_predicates[0]
return values
4 changes: 3 additions & 1 deletion prez/models/search_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class SearchMethod(BaseModel):
def __hash__(self):
return hash(self.uri)

def populate_query(self, term, limit, offset, focus_to_filter, filter_to_focus, predicates):
def populate_query(
self, term, limit, offset, focus_to_filter, filter_to_focus, predicates
):
self.populated_query = self.template_query.substitute(
{
"TERM": term,
Expand Down
20 changes: 16 additions & 4 deletions prez/reference_data/endpoints/catprez_endpoints.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,34 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

endpoint:catalog-listing a ont:Endpoint ;
endpoint:catprez-home a ont:Endpoint ;
ont:endpointTemplate "/c" ;
.

endpoint:catalog-listing a ont:ListingEndpoint ;
ont:deliversClasses prez:CatalogList ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
ont:baseClass dcat:Catalog ;
ont:endpointTemplate "/c/catalogs" ;
.

endpoint:catalog a ont:Endpoint ;
endpoint:catalog a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:catalog-listing ;
ont:deliversClasses dcat:Catalog ;
ont:endpointTemplate "/c/catalogs/$object" ;
.

endpoint:resource a ont:Endpoint ;
endpoint:resource-listing a ont:ListingEndpoint ;
ont:parentEndpoint endpoint:catalog ;
ont:deliversClasses prez:ResourceList ;
ont:baseClass dcat:Resource ;
ont:endpointTemplate "/c/catalogs/$parent_1/resources" ;
ont:ParentToFocusRelation dcterms:hasPart ;
.

endpoint:resource a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:resource-listing ;
ont:deliversClasses dcat:Resource ;
ont:endpointTemplate "/c/catalogs/$parent_1/$object" ;
ont:endpointTemplate "/c/catalogs/$parent_1/resources/$object" ;
ont:ParentToFocusRelation dcterms:hasPart ;
.
5 changes: 5 additions & 0 deletions prez/reference_data/endpoints/profiles_endpoints.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

endpoint:profiles-home a ont:Endpoint ;
ont:endpointTemplate "/profiles" ;
.


endpoint:profiles-listing a ont:Endpoint ;
ont:deliversClasses prez:ProfilesList ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
Expand Down
19 changes: 12 additions & 7 deletions prez/reference_data/endpoints/spaceprez_endpoints.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,47 @@ PREFIX prez: <https://prez.dev/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

endpoint:dataset-listing a ont:Endpoint ;
endpoint:spaceprez-home a ont:Endpoint ;
ont:endpointTemplate "/s" ;
.

endpoint:dataset-listing a ont:ListingEndpoint ;
ont:deliversClasses prez:DatasetList ;
ont:baseClass dcat:Dataset ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
ont:endpointTemplate "/s/datasets" ;
.

endpoint:dataset a ont:Endpoint ;
endpoint:dataset a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:dataset-listing ;
ont:deliversClasses dcat:Dataset ;
ont:endpointTemplate "/s/datasets/$object" ;
ont:FocustoChildRelation rdfs:member ;
.

endpoint:feature-collection-listing a ont:Endpoint ;
endpoint:feature-collection-listing a ont:ListingEndpoint ;
ont:parentEndpoint endpoint:dataset ;
ont:baseClass geo:FeatureCollection ;
ont:deliversClasses prez:FeatureCollectionList ;
ont:endpointTemplate "/s/datasets/$parent_1/collections" ;
ont:ParentToFocusRelation rdfs:member ;
.

endpoint:feature-collection a ont:Endpoint ;
endpoint:feature-collection a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:feature-collection-listing ;
ont:deliversClasses geo:FeatureCollection ;
ont:endpointTemplate "/s/datasets/$parent_1/collections/$object" ;
ont:ParentToFocusRelation rdfs:member ;
.

endpoint:feature-listing a ont:Endpoint ;
endpoint:feature-listing a ont:ListingEndpoint ;
ont:parentEndpoint endpoint:feature-collection ;
ont:baseClass geo:Feature ;
ont:deliversClasses prez:FeatureList ;
ont:endpointTemplate "/s/datasets/$parent_2/collections/$parent_1/items" ;
ont:ParentToFocusRelation rdfs:member ;
.

endpoint:feature a ont:Endpoint ;
endpoint:feature a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:feature-listing ;
ont:deliversClasses geo:Feature ;
ont:endpointTemplate "/s/datasets/$parent_2/collections/$parent_1/items/$object" ;
Expand Down
18 changes: 11 additions & 7 deletions prez/reference_data/endpoints/vocprez_endpoints.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,44 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

endpoint:collection-listing a ont:Endpoint ;
endpoint:vocprez-home a ont:Endpoint ;
ont:endpointTemplate "/v" ;
.

endpoint:collection-listing a ont:ListingEndpoint ;
ont:deliversClasses prez:VocPrezCollectionList ;
ont:baseClass skos:Collection ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
ont:endpointTemplate "/v/collection" ;
.

endpoint:collection a ont:Endpoint ;
ont:parentEndpoint endpoint:collection ;
endpoint:collection a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:collection-listing ;
ont:deliversClasses skos:Collection ;
ont:endpointTemplate "/v/collection/$object" ;
.

endpoint:collection-concept a ont:Endpoint ;
endpoint:collection-concept a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:collection ;
ont:deliversClasses skos:Concept ;
ont:endpointTemplate "/v/collection/$parent_1/$object" ;
ont:ParentToFocusRelation skos:member ;
.

endpoint:vocabs-listing a ont:Endpoint ;
endpoint:vocabs-listing a ont:ListingEndpoint ;
ont:deliversClasses prez:SchemesList ;
ont:baseClass skos:ConceptScheme ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
ont:endpointTemplate "/v/vocab" ;
.

endpoint:vocab a ont:Endpoint ;
endpoint:vocab a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:vocabs-listing ;
ont:deliversClasses skos:ConceptScheme ;
ont:endpointTemplate "/v/vocab/$object" ;
.

endpoint:vocab-concept a ont:Endpoint ;
endpoint:vocab-concept a ont:ObjectEndpoint ;
ont:parentEndpoint endpoint:vocab ;
ont:deliversClasses skos:Concept ;
ont:endpointTemplate "/v/vocab/$parent_1/$object" ;
Expand Down
26 changes: 13 additions & 13 deletions prez/reference_data/profiles/catprez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ prez:CatPrezProfile
a sh:NodeShape ;
sh:targetClass dcat:Resource ;
altr-ext:hasDefaultProfile <https://www.w3.org/TR/vocab-dcat/>
] , [
a sh:NodeShape ;
sh:targetClass prez:ResourceList ;
altr-ext:hasDefaultProfile <https://www.w3.org/TR/vocab-dcat/>
]
.

Expand All @@ -45,7 +49,8 @@ prez:CatPrezProfile
dcat:Catalog ,
dcat:Dataset ,
dcat:Resource ,
prez:CatalogList ;
prez:CatalogList ,
prez:ResourceList ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/ld+json" ,
Expand All @@ -55,19 +60,14 @@ prez:CatPrezProfile
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass dcat:Catalog ;
altr-ext:exclude dcterms:hasPart ;
altr-ext:focusToChild dcterms:hasPart ;
] ,
[
a sh:NodeShape ;
sh:targetClass prez:ResourceList ;
altr-ext:focusToChild dcterms:hasPart ;
sh:sequencePath (
dcterms:hasPart
dcterms:issued
) ;
sh:sequencePath (
dcterms:hasPart
dcterms:creator
) ;
sh:sequencePath (
dcterms:hasPart
dcterms:publisher
) ;
altr-ext:relativeProperties dcterms:issued , dcterms:creator , dcterms:publisher ;
]
.

Expand Down
2 changes: 0 additions & 2 deletions prez/reference_data/profiles/prez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ prez:profiles
dcterms:title "Profiles" ;
dcterms:description "List of profiles" ;
dcterms:identifier "profiles"^^xsd:token ;
altr-ext:hasLabelPredicate dcterms:title ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/json" ,
Expand All @@ -100,7 +99,6 @@ prez:profiles
dcterms:description "A very basic data model that lists the members of container objects only, i.e. not their other properties" ;
dcterms:identifier "mem"^^xsd:token ;
dcterms:title "Members" ;
altr-ext:hasLabelPredicate dcterms:title ;
altr-ext:constrainsClass prez:DatasetList ,
prez:FeatureCollectionList ,
prez:FeatureList ,
Expand Down
2 changes: 0 additions & 2 deletions prez/reference_data/profiles/spaceprez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ prez:SpacePrezProfile
dcterms:description "The OGC API Features specifies the behavior of Web APIs that provide access to features in a dataset in a manner independent of the underlying data store." ;
dcterms:identifier "oai"^^xsd:token ;
dcterms:title "OGC API Features" ;
altr-ext:hasLabelPredicate dcterms:title ;
altr-ext:constrainsClass
dcat:Dataset ,
geo:FeatureCollection ,
Expand Down Expand Up @@ -113,7 +112,6 @@ prez:SpacePrezProfile
dcterms:description "Dataset Catalog Vocabulary (DCAT) is a W3C-authored RDF vocabulary designed to facilitate interoperability between data catalogs" ;
dcterms:identifier "dcat"^^xsd:token ;
dcterms:title "DCAT" ;
altr-ext:hasLabelPredicate dcterms:title ;
altr-ext:constrainsClass
dcat:Catalog ,
dcat:Dataset ,
Expand Down
1 change: 0 additions & 1 deletion prez/reference_data/profiles/vocprez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ prez:VocPrezProfile
dcterms:description "This is a profile of the taxonomy data model SKOS - i.e. SKOS with additional constraints." ;
dcterms:identifier "vocpub"^^xsd:token ;
dcterms:title "VocPub" ;
altr-ext:hasLabelPredicate skos:prefLabel ;
altr-ext:otherAnnotationProps schema:color, reg:status ;
altr-ext:constrainsClass
skos:ConceptScheme ,
Expand Down
18 changes: 17 additions & 1 deletion prez/routers/catprez.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from starlette.responses import PlainTextResponse

from prez.routers.object import listing_function, item_function
from prez.services.curie_functions import get_uri_for_curie_id

router = APIRouter(tags=["CatPrez"])

Expand All @@ -25,7 +26,22 @@ async def catalog_list(


@router.get(
"/c/catalogs/{catalog_curie}/{resource_curie}",
"/c/catalogs/{catalog_curie}/resources",
summary="List Resources",
name="https://prez.dev/endpoint/catprez/resource-listing",
)
async def resource_list(
request: Request,
catalog_curie: str,
page: Optional[int] = 1,
per_page: Optional[int] = 20,
):
catalog_uri = get_uri_for_curie_id(catalog_curie)
return await listing_function(request, page, per_page, uri=catalog_uri)


@router.get(
"/c/catalogs/{catalog_curie}/resources/{resource_curie}",
summary="Get Resource",
name="https://prez.dev/endpoint/catprez/resource",
)
Expand Down
Loading

0 comments on commit 91ede3c

Please sign in to comment.