diff --git a/src/app/services/resources.service.ts b/src/app/services/resources.service.ts index e8a54f3..a31b609 100644 --- a/src/app/services/resources.service.ts +++ b/src/app/services/resources.service.ts @@ -1,37 +1,49 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import namespaces from '../../assets/namespaces.json'; @Injectable() export class DataService { constructor(private http: HttpClient) { } readonly httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/sparql-query', 'Accept': 'application/sparql-results+json; charset=UTF-8' }) }; baseUrl = 'http://localhost:3030/nietzsche/query'; prefix = 'http://www.nie.org/ontology/nietzsche#' prefix2 = 'http://rdfh.ch/projects/0068#' fallBackQuery = 'prefix tln: <' + this.prefix + '> prefix data: <' + this.prefix2 + '> ' + ' SELECT ?s ?p ?o WHERE' + ' { ?s a tln:Word . ?s tln:hasText ?o ' + ' OPTIONAL { ?s ?p ?o } ' + ' } LIMIT 50'; public getData(query: string) { if (this.baseUrl && query && this.httpOptions.headers) { return this.http.post(this.baseUrl, query, this.httpOptions); } if (this.baseUrl && this.httpOptions.headers && (query === undefined || query === null || query === '') ) { console.log('fallback to static query as there is no query passed: ' + this.fallBackQuery); const fuu = this.http.post(this.baseUrl, this.fallBackQuery, this.httpOptions); // console.log(fuu) return fuu; } } + + public shrink_iri(iri) { + let shrunkIri: string; + Object.keys(namespaces).forEach((ns, index) => { + // console.log(this.namespaces[ns] + ' key ' + ns ) + if (iri.includes(namespaces[ns])) { + shrunkIri = iri.replace(namespaces[ns], ns ); + } + }); + if (shrunkIri) { return shrunkIri; } + } }