Skip to content

Commit

Permalink
Add profiles profile. (#250)
Browse files Browse the repository at this point in the history
* Add profiles profile.
Add connegp debug print output; adds tabulate development dependency.
Reduce pagination count limit to 100.

* Fix profiles so tests pass.

* fix: print -> log.debug
  • Loading branch information
recalcitrantsupplant committed Aug 15, 2024
1 parent 428ca45 commit e4af3d3
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Settings(BaseSettings):
curie_separator: str = ":"
system_uri: Optional[str] = f"{protocol}://{host}:{port}"
order_lists_by_label: bool = True
listing_count_limit: int = 1000
listing_count_limit: int = 100
label_predicates: Optional[List[URIRef]] = [
SKOS.prefLabel,
DCTERMS.title,
Expand Down
10 changes: 8 additions & 2 deletions prez/reference_data/profiles/ogc_records_profile.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ prez:OGCRecordsProfile
dcterms:title "OGC Profile" ;
altr-ext:constrainsClass prez:CatPrez ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/json" ,
"application/ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass prof:Profile , dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
sh:targetClass dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
, skos:Collection , rdf:Resource , prez:SearchResult , prez:CQLObjectList ;
altr-ext:hasDefaultProfile prez:OGCListingProfile
] , [
Expand All @@ -38,7 +44,7 @@ prez:OGCRecordsProfile
altr-ext:hasDefaultProfile prez:OGCSchemesObjectProfile
] , [
a sh:NodeShape ;
sh:targetClass prof:Profile , dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
sh:targetClass dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
, skos:Collection , rdf:Resource ;
altr-ext:hasDefaultProfile prez:OGCItemProfile
]
Expand Down
41 changes: 40 additions & 1 deletion prez/reference_data/profiles/prez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
a prof:Profile ;
dcterms:identifier "prez"^^xsd:token ;
dcterms:description "A profile for the Prez Linked Data API" ;
skos:prefLabel "Prez profile" ;
dcterms:title "Prez profile" ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/json" ,
"application/ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass prez:SPARQLQuery ;
Expand All @@ -29,6 +35,10 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
a sh:NodeShape ;
sh:targetClass prez:AltProfilesList ;
altr-ext:hasDefaultProfile <https://prez.dev/profile/open-object>
] , [
a sh:NodeShape ;
sh:targetClass prof:Profile ;
altr-ext:hasDefaultProfile <https://prez.dev/profile/profiles>
]
.

Expand Down Expand Up @@ -138,3 +148,32 @@ altr-ext:alt-profile
)
] ;
.

<https://prez.dev/profile/profiles>
a prof:Profile , prez:ObjectProfile , prez:ListingProfile ;
dcterms:description "A Profile for displaying profiles" ;
dcterms:identifier "prof"^^xsd:token ;
dcterms:title "Profiles Profile" ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/ld+json" ,
"application/anot+ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:constrainsClass
prof:Profile ;
sh:property [
sh:path (
sh:union (
rdf:type
altr-ext:hasResourceFormat
altr-ext:hasDefaultResourceFormat
dcterms:description
dcterms:title
dcterms:identifier
)
)
] ;
shext:bnode-depth 20 ;
.
25 changes: 25 additions & 0 deletions prez/services/connegp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel
from rdflib import Graph, Namespace, URIRef

from prez.config import settings
from prez.exceptions.model_exceptions import NoProfilesException
from prez.repositories.base import Repo
from prez.services.curie_functions import get_curie_id_for_uri, get_uri_for_curie_id
Expand Down Expand Up @@ -302,4 +303,28 @@ async def _do_query(self, query: str) -> tuple[Graph, list]:
response = await self.system_repo.send_queries([], [(None, query)])
if not response[1][0][1]:
raise NoProfilesException(self.classes)

if settings.log_level == "DEBUG":
from tabulate import tabulate
table_data = [
[
item['profile']['value'],
item['title']['value'],
item['class']['value'],
item['distance']['value'],
item['def_profile']['value'],
item['format']['value'],
item['req_format']['value'],
item['def_format']['value'],
]
for item in response[1][0][1]
]

# Define headers
headers = ["Profile", "Title", "Class", "Distance", "Default Profile", "Format", "Requested Format",
"Default Format"]

# Render as a table
log.debug(tabulate(table_data, headers=headers, tablefmt="grid"))

return response
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ scalene = "^1.5.18"
python-dotenv = "^1.0.0"
pyoxigraph = "^0.3.19"
coverage = "^7.3.2"
tabulate = "^0.9.0"


[build-system]
requires = ["poetry-core>=1.9.0"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endpoints_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def test_profile(client_no_override):
r = client_no_override.get("/profiles")
r = client_no_override.get("/profiles?per_page=50")
g = Graph().parse(data=r.text)
assert (URIRef("https://prez.dev/profile/prez"), RDF.type, PROF.Profile) in g

Expand Down

0 comments on commit e4af3d3

Please sign in to comment.