Skip to content

Commit

Permalink
Roll out link generation across catprez / vocprez / spaceprez
Browse files Browse the repository at this point in the history
  • Loading branch information
recalcitrantsupplant committed Aug 16, 2023
1 parent bd93347 commit 934b174
Show file tree
Hide file tree
Showing 44 changed files with 402 additions and 1,004 deletions.
6 changes: 0 additions & 6 deletions prez/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
from prez.models.catprez_item import CatalogItem
from prez.models.catprez_listings import CatalogMembers
from prez.models.vocprez_item import VocabItem
from prez.models.vocprez_listings import VocabMembers
from prez.models.spaceprez_item import SpatialItem
from prez.models.spaceprez_listings import SpatialMembers
from prez.models.search_method import SearchMethod
53 changes: 0 additions & 53 deletions prez/models/catprez_item.py

This file was deleted.

28 changes: 0 additions & 28 deletions prez/models/catprez_listings.py

This file was deleted.

43 changes: 43 additions & 0 deletions prez/models/listing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Optional, FrozenSet

from pydantic import BaseModel, root_validator
from rdflib import URIRef, Literal, XSD

from prez.cache import endpoints_graph_cache
from prez.reference_data.prez_ns import ONT


class ListingModel(BaseModel):
uri: Optional[
URIRef
] = None # this is the URI of the focus object (if listing by membership)
endpoint_uri: Optional[URIRef] = None
selected_class: Optional[FrozenSet[URIRef]] = None
profile: Optional[URIRef] = None
top_level_listing: Optional[bool] = False

def __hash__(self):
return hash(self.uri)

@root_validator
def populate(cls, values):
endpoint_uri_str = values.get("endpoint_uri")
if endpoint_uri_str:
endpoint_uri = URIRef(endpoint_uri_str)
values["classes"] = frozenset(
[
klass
for klass in endpoints_graph_cache.objects(
endpoint_uri, ONT.deliversClasses, None
)
]
)
values["base_class"] = endpoints_graph_cache.value(
endpoint_uri, ONT.baseClass
)
tll_text = endpoints_graph_cache.value(endpoint_uri, ONT.isTopLevelEndpoint)
if tll_text == Literal("true", datatype=XSD.boolean):
values["top_level_listing"] = True
else:
values["top_level_listing"] = False
return values
18 changes: 15 additions & 3 deletions prez/models/object_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@
from rdflib import URIRef, PROF

from prez.models.model_exceptions import ClassNotFoundException
from prez.reference_data.prez_ns import PREZ
from prez.services.curie_functions import get_uri_for_curie_id
from prez.services.model_methods import get_classes


class ObjectItem(BaseModel):
uri: Optional[URIRef] = None
object_curie: Optional[str] = None
classes: Optional[Set[URIRef]] = frozenset([PROF.Profile])
selected_class: Optional[URIRef] = None
profile: Optional[URIRef] = PREZ["profile/open"]
link_constructor: Optional[str] = None # TODO remove when no longer being used

def __hash__(self):
return hash(self.uri)

@root_validator
def populate(cls, values):
values["top_level_listing"] = False # this class is for objects, not listings.
uri_str = values.get("uri")
if uri_str:
values["uri"] = URIRef(uri_str)
else:
values["uri"] = get_uri_for_curie_id(values["object_curie"])
try:
values["classes"] = get_classes(values["uri"])
values["classes"] = frozenset(
tup[1] for tup in get_classes([values["uri"]])
)
except ClassNotFoundException:
# TODO return a generic DESCRIBE on the object - we can't use any of prez's profiles/endpoints to render
# information about the object, but we can provide any RDF we have for it.
pass
uri_str = values["uri"]
values["uri"] = URIRef(uri_str)

return values
4 changes: 4 additions & 0 deletions prez/models/search_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from pydantic import BaseModel
from rdflib import URIRef, Namespace, Literal

from pydantic import BaseConfig

BaseConfig.arbitrary_types_allowed = True

PREZ = Namespace("https://prez.dev/")


Expand Down
59 changes: 0 additions & 59 deletions prez/models/spaceprez_item.py

This file was deleted.

52 changes: 0 additions & 52 deletions prez/models/spaceprez_listings.py

This file was deleted.

64 changes: 0 additions & 64 deletions prez/models/vocprez_item.py

This file was deleted.

3 changes: 3 additions & 0 deletions prez/reference_data/endpoints/catprez_endpoints.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ PREFIX ont: <https://prez.dev/ont/>
PREFIX prez: <https://prez.dev/>
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 ;
ont:deliversClasses prez:CatalogList ;
ont:isTopLevelEndpoint "true"^^xsd:boolean ;
ont:baseClass dcat:Catalog ;
ont:endpointTemplate "/c/catalogs" ;
.

Expand Down
Loading

0 comments on commit 934b174

Please sign in to comment.