Skip to content

Commit

Permalink
further ingetration
Browse files Browse the repository at this point in the history
  • Loading branch information
recalcitrantsupplant committed Dec 11, 2023
1 parent 21bde00 commit 380320d
Show file tree
Hide file tree
Showing 39 changed files with 1,375 additions and 634 deletions.
54 changes: 54 additions & 0 deletions demo/prez-v4-backend/config.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

PREFIX : <#>
PREFIX fuseki: <http://jena.apache.org/fuseki#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX geosparql: <http://jena.apache.org/geosparql#>

[] rdf:type fuseki:Server ;
fuseki:services (
:service
) .

:service rdf:type fuseki:Service ;
fuseki:name "dataset" ;

fuseki:endpoint [ fuseki:operation fuseki:query ; ] ;
fuseki:endpoint [
fuseki:operation fuseki:query ;
fuseki:name "sparql"
];
fuseki:endpoint [
fuseki:operation fuseki:query ;
fuseki:name "query"
] ;
fuseki:endpoint [
fuseki:operation fuseki:gsp-r ;
fuseki:name "get"
] ;
fuseki:dataset <#geo_ds> ;
.

<#geo_ds> rdf:type geosparql:GeosparqlDataset ;
geosparql:dataset :dataset ;
geosparql:inference true ;
geosparql:queryRewrite true ;
geosparql:indexEnabled true ;
geosparql:applyDefaultGeometry true ;
.

# Transactional in-memory dataset.
:dataset rdf:type ja:MemoryDataset ;
## Optional load with data on start-up
ja:data "/rdf/catprez.ttl";
ja:data "/rdf/vocprez.ttl";
ja:data "/rdf/catprez.ttl";
ja:data "/rdf/sandgate.ttl";
ja:data "/rdf/object_catalog_bblocks_catalog.ttl";
ja:data "/rdf/object_vocab_api_bblocks.ttl";
ja:data "/rdf/object_vocab_datatype_bblocks.ttl";
ja:data "/rdf/object_vocab_parameter_bblocks.ttl";
ja:data "/rdf/object_vocab_schema_bblocks.ttl";
.
33 changes: 33 additions & 0 deletions demo/prez-v4-backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3"
services:

fuseki:
image: "ghcr.io/zazuko/fuseki-geosparql:v3.2.0"
ports:
- "3030:3030"
volumes:
- type: bind
source: config.ttl
target: /fuseki/config.ttl
- type: bind
source: ../../test_data
target: /rdf
environment:
ADMIN_PASSWORD: pw
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:3030 || exit 1"]
interval: 5s
timeout: 10s
retries: 3

prez:
build:
context: ../../
dockerfile: ./Dockerfile
ports:
- "8000:8000"
environment:
SPARQL_ENDPOINT: 'http://fuseki:3030/dataset'
depends_on:
fuseki:
condition: service_healthy
3 changes: 3 additions & 0 deletions demo/prez-v4-backend/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains a docker compose file which will run the Prez backend and Fuseki GeoSPARQL together with some sample data.

NB any data added to the test_data folder must also be specified in the fuseki config.ttl file.
54 changes: 39 additions & 15 deletions poetry.lock

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

33 changes: 18 additions & 15 deletions prez/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from prez.config import settings
from prez.sparql.methods import PyoxigraphRepo, RemoteSparqlRepo, OxrdflibRepo
from temp.cql2sparql import CQLParser
from rdframe import CQLParser


async def get_async_http_client():
Expand Down Expand Up @@ -105,17 +105,20 @@ async def cql_post_parser_dependency(request: Request):


async def cql_get_parser_dependency(request: Request):
try:
query = json.loads(request.query_params["q"])
context = json.load(
(Path(__file__).parent.parent / "temp" / "default_cql_context.json").open()
)
cql_parser = CQLParser(cql=query, context=context)
cql_parser.generate_jsonld()
return cql_parser
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format.")
except Exception as e: # Replace with your specific parsing exception
raise HTTPException(
status_code=400, detail="Invalid CQL format: Parsing failed."
)
if request.query_params.get("filter"):
try:
query = json.loads(request.query_params["filter"])
context = json.load(
(
Path(__file__).parent.parent / "temp" / "default_cql_context.json"
).open()
)
cql_parser = CQLParser(cql=query, context=context)
cql_parser.generate_jsonld()
return cql_parser
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format.")
except Exception as e: # Replace with your specific parsing exception
raise HTTPException(
status_code=400, detail="Invalid CQL format: Parsing failed."
)
21 changes: 21 additions & 0 deletions prez/reference_data/context_ontologies/prez-ontology.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<https://prez.dev/link> <http://www.w3.org/2000/01/rdf-schema#label> "link" <https://prez.dev/ontology> .
<https://prez.dev/count> <http://www.w3.org/2000/01/rdf-schema#label> "count" <https://prez.dev/ontology> .
<https://prez.dev/members> <http://www.w3.org/2000/01/rdf-schema#label> "members" <https://prez.dev/ontology> .
<https://prez.dev/searchResultMatch> <http://www.w3.org/2000/01/rdf-schema#label> "Matched Term" <https://prez.dev/ontology> .
<https://prez.dev/searchResultPredicate> <http://www.w3.org/2000/01/rdf-schema#label> "Matched Predicate" <https://prez.dev/ontology> .
<https://prez.dev/searchResultWeight> <http://www.w3.org/2000/01/rdf-schema#label> "Search Result Weight" <https://prez.dev/ontology> .
<http://www.w3.org/ns/dx/conneg/altr-ext#hasDefaultResourceFormat> <http://www.w3.org/2000/01/rdf-schema#label> "Default Resource Format" <https://prez.dev/ontology> .
<http://www.w3.org/ns/dx/conneg/altr-ext#hasResourceFormat> <http://www.w3.org/2000/01/rdf-schema#label> "Has Resource Format" <https://prez.dev/ontology> .
<http://www.w3.org/ns/dx/conneg/altr-ext#constrainsClass> <http://www.w3.org/2000/01/rdf-schema#label> "Constrains Class" <https://prez.dev/ontology> .
<http://www.w3.org/ns/dx/conneg/altr-ext#hasNodeShape> <http://www.w3.org/2000/01/rdf-schema#label> "Has Node Shape" <https://prez.dev/ontology> .
<http://www.w3.org/ns/dx/conneg/altr-ext#hasDefaultProfile> <http://www.w3.org/2000/01/rdf-schema#label> "Has Default Profile" <https://prez.dev/ontology> .
<http://example.com/shacl-extension#allPredicateValues> <http://www.w3.org/2000/01/rdf-schema#label> "All Predicate Values" <https://prez.dev/ontology> .
<http://example.com/shacl-extension#limit> <http://www.w3.org/2000/01/rdf-schema#comment> "limit" <https://prez.dev/ontology> .
<http://example.com/shacl-extension#offset> <http://www.w3.org/2000/01/rdf-schema#comment> "offset" <https://prez.dev/ontology> .
<http://example.com/shacl-extension#orderBy> <http://www.w3.org/2000/01/rdf-schema#comment> "order by" <https://prez.dev/ontology> .
<http://example.com/shacl-extension#bnode-depth> <http://www.w3.org/2000/01/rdf-schema#comment> "blank node depth" <https://prez.dev/ontology> .
<https://prez.dev/ont/endpointTemplate> <http://www.w3.org/2000/01/rdf-schema#label> "endpoint template" <https://prez.dev/ontology> .
<https://prez.dev/ont/deliversClasses> <http://www.w3.org/2000/01/rdf-schema#label> "delivers classes" <https://prez.dev/ontology> .
<https://prez.dev/ont/parentEndpoint> <http://www.w3.org/2000/01/rdf-schema#label> "parent endpoint" <https://prez.dev/ontology> .
<https://prez.dev/ont/parentToFocusRelation> <http://www.w3.org/2000/01/rdf-schema#label> "parent to focus relation" <https://prez.dev/ontology> .
<https://prez.dev/ont/focusToParentRelation> <http://www.w3.org/2000/01/rdf-schema#label> "focus to parent relation" <https://prez.dev/ontology> .
27 changes: 25 additions & 2 deletions prez/reference_data/endpoints/cql_endpoints.ttl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX endpoint: <https://prez.dev/endpoint/>
PREFIX endpoint: <https://prez.dev/endpoint/cql/>
PREFIX prez: <https://prez.dev/>
PREFIX ont: <https://prez.dev/ont/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Expand All @@ -10,8 +10,31 @@ PREFIX shext: <http://example.com/shacl-extension#>


endpoint:cql a ont:ListingEndpoint ;
ont:endpointTemplate "/cql" ;
ont:deliversClasses prez:CQLObjectList ; # required to determine the correct profile for ConnegP
shext:limit 20 ;
shext:offset 0 ;
.

endpoint:queryables a ont:ListingEndpoint ;
sh:rule [ sh:subject "?focus_node" ;
sh:predicate <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
sh:object <https://prez.dev/Queryable> ] ;
ont:deliversClasses prez:QueryablesList ;
sh:target [ sh:select """SELECT DISTINCT ?focus_node
WHERE {
?s a ?class ;
?focus_node ?o .
VALUES ?class {
dcat:Catalog
dcat:Dataset
dcat:Resource
skos:ConceptScheme
skos:Collection
skos:Concept
geo:FeatureCollection
geo:Feature
}
}""" ] ;
shext:limit 100 ;
shext:offset 0 ;
.
Loading

0 comments on commit 380320d

Please sign in to comment.