From 9a1cb16879bc58f419f86d8fd14ebd31faff99d7 Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Fri, 26 Jan 2024 18:02:11 +0100 Subject: [PATCH] update sparql queries & extract graphdb url --- src/app/dsp-ui-lib/core/app-init.service.ts | 2 + src/app/services/beol.service.ts | 143 ++++++++++++-------- src/config/config.dev.json | 3 +- src/config/config.prod.json | 3 +- 4 files changed, 91 insertions(+), 60 deletions(-) diff --git a/src/app/dsp-ui-lib/core/app-init.service.ts b/src/app/dsp-ui-lib/core/app-init.service.ts index 45d6f308..cf23c096 100644 --- a/src/app/dsp-ui-lib/core/app-init.service.ts +++ b/src/app/dsp-ui-lib/core/app-init.service.ts @@ -37,6 +37,7 @@ export class AppInitService { const apiPath = (typeof dspApiConfig.apiPath === 'string' ? dspApiConfig.apiPath : ''); const jsonWebToken = (typeof dspApiConfig.jsonWebToken === 'string' ? dspApiConfig.jsonWebToken : ''); const logErrors = (typeof dspApiConfig.logErrors === 'boolean' ? dspApiConfig.logErrors : false); + const graphDBURL = (typeof dspApiConfig.graphDBURL === 'string' ? dspApiConfig.graphDBURL: ''); // init dsp-api configuration this.dspApiConfig = new KnoraApiConfig( @@ -58,6 +59,7 @@ export class AppInitService { this.config['apiPath'] = apiPath; this.config['jsonWebToken'] = jsonWebToken; this.config['logErrors'] = logErrors; + this.config['graphDBURL'] = graphDBURL; resolve(); } diff --git a/src/app/services/beol.service.ts b/src/app/services/beol.service.ts index 5b9e6874..6db447d0 100644 --- a/src/app/services/beol.service.ts +++ b/src/app/services/beol.service.ts @@ -709,28 +709,37 @@ export class BeolService { PREFIX xsd: PREFIX ofn: PREFIX owl: - SELECT ?From ?FromIri ?To ?ToIri ?Departure ?Arrival ?EndDate ?DurationOfStayInDays + PREFIX rdfs: + SELECT ?From ?FromIri ?To ?ToIri ?Departure ?Arrival ?End ?Duration WHERE { BIND (<< ?person trip-onto:hasJourney ?journey>> AS ?journeyTriple) BIND(<${entryIri}> AS ?entryIRI) ?journeyTriple trip-onto:mentionedIn ?entryIRI . ?journey trip-onto:hasStartLocation ?FromLocation . ?FromLocation owl:sameAs ?FromIri . - ?FromLocation schema:name ?FromName . - BIND(STR(?FromName) AS ?From) + BIND(<< ?journey trip-onto:hasStartLocation ?FromLocation >> AS ?startStatement) ?journey trip-onto:hasDestination ?ToLocation . - ?ToLocation schema:name ?ToName . ?ToLocation owl:sameAs ?ToIri . - BIND(STR(?ToName) AS ?To) - ?startStatement trip-onto:hasStartDate ?Departure . + ?startStatement trip-onto:hasDeparture ?DepartureDate . + << ?startStatement trip-onto:hasDeparture ?DepartureDate >> trip-onto:calendar ?dep_calendar . + BIND(fn:concat(?dep_calendar, " ", STR(?DepartureDate)) AS ?Departure) + BIND(<< ?journey trip-onto:hasDestination ?ToLocation >> AS ?arrivalStatement) - ?arrivalStatement trip-onto:hasArrival ?Arrival . + ?arrivalStatement trip-onto:hasArrival ?ArrivalDate . + << ?arrivalStatement trip-onto:hasArrival ?ArrivalDate >> trip-onto:calendar ?arr_calendar . + BIND(fn:concat(?arr_calendar, " ", STR(?ArrivalDate)) AS ?Arrival) ?journeyTriple trip-onto:hasEndDate ?EndDate . - BIND(ofn:days-from-duration(?EndDate-?Arrival) AS ?duration_d) - BIND(ofn:years-from-duration(?EndDate-?Arrival) AS ?duration_y) - BIND(ofn:months-from-duration(?EndDate-?Arrival) AS ?duration_m) - BIND(?duration_y *365+ ?duration_m*12 + ?duration_d AS ?DurationOfStayInDays) + << ?journeyTriple trip-onto:hasEndDate ?EndDate >> trip-onto:calendar ?end_calendar . + BIND(fn:concat(?end_calendar, " ", STR(?EndDate)) AS ?End) + BIND(ofn:days-from-duration(?EndDate-?ArrivalDate) AS ?duration_d) + BIND(ofn:years-from-duration(?EndDate-?ArrivalDate) AS ?duration_y) + BIND(ofn:months-from-duration(?EndDate-?ArrivalDate) AS ?duration_m) + BIND(fn:concat( STR(?duration_y *365+ ?duration_m*30 + ?duration_d), " days") AS ?Duration) + SERVICE { + ?FromIri rdfs:label ?From . + ?ToIri rdfs:label ?To . + } } `; @@ -742,7 +751,9 @@ export class BeolService { PREFIX trip-onto: PREFIX schema: PREFIX owl: - SELECT ?From ?FromIri ?To ?ToIri ?startDate ?endDate ?Transportation ?Accomodation + PREFIX trip: + PREFIX rdfs: + SELECT ?From ?FromIri ?To ?ToIri ?Start ?End ?Transportation ?Accomodation WHERE { ?journey a trip-onto:Journey . BIND(<${entryIri}> AS ?entryIRI) @@ -751,21 +762,26 @@ export class BeolService { ?journeyTriple trip-onto:hasStage ?stage . BIND(<> AS ?stageTriple) ?stage trip-onto:hasStartLocation ?FromLocation . - ?FromLocation schema:name ?FromName . ?FromLocation owl:sameAs ?FromIri . - BIND(STR(?FromName) As ?From) ?stageTriple trip-onto:hasEndDate ?endDate . + << ?stageTriple trip-onto:hasEndDate ?endDate >> trip-onto:calendar ?end_calendar . + BIND(fn:concat(?end_calendar, " ", STR(?endDate)) AS ?End) ?stageTriple trip-onto:hasStartDate ?startDate . + << ?stageTriple trip-onto:hasStartDate ?startDate >> trip-onto:calendar ?start_calendar + BIND(fn:concat(?start_calendar, " ", STR(?startDate)) AS ?Start) ?stage trip-onto:hasDestination ?ToLocation . ?ToLocation owl:sameAs ?ToIri . - ?ToLocation schema:name ?ToName . - BIND(STR(?ToName) As ?To) - ?stage trip-onto:meanOfTransportation ?Transportation . + ?stage trip-onto:meanOfTransportation ?TransportationType . + ?TransportationType schema:name ?Transportation OPTIONAL { ?stage trip-onto:hasStay ?stay . ?stay trip-onto:hasAccommodation ?accomodationRes . ?accomodationRes schema:name ?Accomodation . } + SERVICE <${this._appInitService.config['graphDBURL']}> { + ?FromIri rdfs:label ?From . + ?ToIri rdfs:label ?To . + } } `; @@ -775,52 +791,63 @@ export class BeolService { make_coordinates_query(entryIri: string): Observable { const stageCoordinatesTemplate = ` PREFIX trip-onto: - PREFIX schema: - PREFIX owl: - PREFIX wd: - PREFIX wdp: - PREFIX wdps: - PREFIX rdfs: - PREFIX wikibase: - SELECT ?startWikiIri ?startLat ?startLong ?endWikiIri ?endLat ?endLong ?startDate ?endDate ?Transportation - WHERE { - ?journey a trip-onto:Journey . - BIND(<${entryIri}> AS ?entryIRI) - BIND (<< ?person trip-onto:hasJourney ?journey>> AS ?journeyTriple) - ?journeyTriple trip-onto:mentionedIn ?entryIRI . - ?journeyTriple trip-onto:hasStage ?stage . - BIND(<> AS ?stageTriple) - ?stage trip-onto:hasStartLocation ?FromLocation . - ?FromLocation trip-onto:hasWikiLink ?startWikiIri . - - ?stageTriple trip-onto:hasEndDate ?endDate . - ?stageTriple trip-onto:hasStartDate ?startDate . - ?stage trip-onto:hasDestination ?ToLocation . - ?ToLocation trip-onto:hasWikiLink ?endWikiIri . - ?stage trip-onto:meanOfTransportation ?meanOfTransportation . - ?meanOfTransportation schema:name ?Transportation . - OPTIONAL{ - SERVICE { - ?startWikiIri wdp:P625 ?coordinate_start. - - ?coordinate_start wdps:P625 ?coordinate_node_start. - ?coordinate_node_start wikibase:geoLongitude ?startLong. - ?coordinate_node_start wikibase:geoLatitude ?startLat. - - ?endWikiIri wdp:P625 ?coordinate_end . - ?coordinate_end wdps:P625 ?coordinate_node_end. - ?coordinate_node_end wikibase:geoLongitude ?endLong. - ?coordinate_node_end wikibase:geoLatitude ?endLat. - - } - } - } + PREFIX schema: + PREFIX owl: + PREFIX wd: + PREFIX wdp: + PREFIX wdps: + PREFIX rdfs: + PREFIX wikibase: + PREFIX beol: + SELECT ?startWikiIri ?startLat ?startLong ?endWikiIri ?endLat ?endLong ?startDate ?endDate ?Transportation + WHERE { + ?journey a trip-onto:Journey . + BIND(<${entryIri}> AS ?entryIRI) + BIND (<< ?person trip-onto:hasJourney ?journey>> AS ?journeyTriple) + ?journeyTriple trip-onto:mentionedIn ?entryIRI . + ?journeyTriple trip-onto:hasStage ?stage . + BIND(<> AS ?stageTriple) + ?stage trip-onto:hasStartLocation ?FromLocation . + ?FromLocation owl:sameAs ?FromIri . + ?stageTriple trip-onto:hasEndDate ?endDate . + ?stageTriple trip-onto:hasStartDate ?startDate . + ?stage trip-onto:hasDestination ?ToLocation . + ?ToLocation owl:sameAs ?ToIri . + + ?stage trip-onto:meanOfTransportation ?meanOfTransportation . + ?meanOfTransportation schema:name ?Transportation . + + SERVICE { + ?FromIri beol:hasWikiLink ?startWikiValue . + ?startWikiValue ?startWikiIri_xsd . + ?ToIri beol:hasWikiLink ?endWikiValue . + ?endWikiValue ?endWikiIri_xsd . + } + BIND(URI(?startWikiIri_xsd) AS ?startWikiIri) + BIND(URI(?endWikiIri_xsd) AS ?endWikiIri) + OPTIONAL{ + SERVICE { + ?startWikiIri wdp:P625 ?coordinate_start. + + ?coordinate_start wdps:P625 ?coordinate_node_start. + ?coordinate_node_start wikibase:geoLongitude ?startLong. + ?coordinate_node_start wikibase:geoLatitude ?startLat. + + ?endWikiIri wdp:P625 ?coordinate_end . + ?coordinate_end wdps:P625 ?coordinate_node_end. + ?coordinate_node_end wikibase:geoLongitude ?endLong. + ?coordinate_node_end wikibase:geoLatitude ?endLat. + + } + } + } + `; return this.requestGraphDB(stageCoordinatesTemplate) } requestGraphDB(query: string): Observable { - const url = "https://graphdb.organa.myds.me/repositories/journeyStar"; + const url = "http://localhost:7200/repositories/Reisbuchlein"; const httpOptions = { headers: new HttpHeaders({ "Content-Type": "application/x-www-form-urlencoded", diff --git a/src/config/config.dev.json b/src/config/config.dev.json index af88942b..a5b6717f 100644 --- a/src/config/config.dev.json +++ b/src/config/config.dev.json @@ -10,5 +10,6 @@ "logErrors": true, "ontologyIRI": "http://0.0.0.0:3333", "iiifURL": "http://0.0.0.0:1024", - "appURL": "http://0.0.0.0:4200" + "appURL": "http://0.0.0.0:4200", + "graphDBURL": "http://admin:test@localhost:3030/knora-test/query" } diff --git a/src/config/config.prod.json b/src/config/config.prod.json index c133b5da..4f06789d 100644 --- a/src/config/config.prod.json +++ b/src/config/config.prod.json @@ -10,5 +10,6 @@ "logErrors": true, "ontologyIRI": "http://0.0.0.0:3333", "iiifURL": "http://0.0.0.0:1024", - "appURL": "http://0.0.0.0:4200" + "appURL": "http://0.0.0.0:4200", + "graphDBURL": "http://admin:test@localhost:3030/knora-test/query" }