Skip to content

Commit

Permalink
update sparql queries & extract graphdb url
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijeinath committed Jan 26, 2024
1 parent 4de0bef commit 9a1cb16
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/app/dsp-ui-lib/core/app-init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -58,6 +59,7 @@ export class AppInitService {
this.config['apiPath'] = apiPath;
this.config['jsonWebToken'] = jsonWebToken;
this.config['logErrors'] = logErrors;
this.config['graphDBURL'] = graphDBURL;

resolve();
}
Expand Down
143 changes: 85 additions & 58 deletions src/app/services/beol.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,28 +709,37 @@ export class BeolService {
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ofn:<http://www.ontotext.com/sparql/functions/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?From ?FromIri ?To ?ToIri ?Departure ?Arrival ?EndDate ?DurationOfStayInDays
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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 <http://localhost:3030/knora-test/query> {
?FromIri rdfs:label ?From .
?ToIri rdfs:label ?To .
}
}
`;

Expand All @@ -742,7 +751,9 @@ export class BeolService {
PREFIX trip-onto: <http://journeyStar.dhlab.ch/ontology/trip-onto#>
PREFIX schema: <https://schema.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?From ?FromIri ?To ?ToIri ?startDate ?endDate ?Transportation ?Accomodation
PREFIX trip: <http://ontology.eil.utoronto.ca/icity/Trip/Trip>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?From ?FromIri ?To ?ToIri ?Start ?End ?Transportation ?Accomodation
WHERE {
?journey a trip-onto:Journey .
BIND(<${entryIri}> AS ?entryIRI)
Expand All @@ -751,21 +762,26 @@ export class BeolService {
?journeyTriple trip-onto:hasStage ?stage .
BIND(<<?journeyTriple trip-onto:hasStage ?stage>> 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 .
}
}
`;

Expand All @@ -775,52 +791,63 @@ export class BeolService {
make_coordinates_query(entryIri: string): Observable<DataGraphDB> {
const stageCoordinatesTemplate = `
PREFIX trip-onto: <http://journeyStar.dhlab.ch/ontology/trip-onto#>
PREFIX schema: <https://schema.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdp: <http://www.wikidata.org/prop/>
PREFIX wdps: <http://www.wikidata.org/prop/statement/value/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
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(<<?journeyTriple trip-onto:hasStage ?stage>> 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 <https://query.wikidata.org/sparql> {
?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: <https://schema.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdp: <http://www.wikidata.org/prop/>
PREFIX wdps: <http://www.wikidata.org/prop/statement/value/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX beol: <http://www.knora.org/ontology/0801/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(<<?journeyTriple trip-onto:hasStage ?stage>> 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 <http://admin:test@localhost:3030/knora-test/query> {
?FromIri beol:hasWikiLink ?startWikiValue .
?startWikiValue <http://www.knora.org/ontology/knora-base#valueHasUri> ?startWikiIri_xsd .
?ToIri beol:hasWikiLink ?endWikiValue .
?endWikiValue <http://www.knora.org/ontology/knora-base#valueHasUri> ?endWikiIri_xsd .
}
BIND(URI(?startWikiIri_xsd) AS ?startWikiIri)
BIND(URI(?endWikiIri_xsd) AS ?endWikiIri)
OPTIONAL{
SERVICE <https://query.wikidata.org/sparql> {
?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<DataGraphDB> {
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",
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/config/config.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 9a1cb16

Please sign in to comment.