diff --git a/src/server/Datasets.js b/src/server/Datasets.js index 7e7b905cb6e791778d76387f32bee190a20ea881..ce69f80925b8bfe5905c99a81f5318111b57b0e3 100644 --- a/src/server/Datasets.js +++ b/src/server/Datasets.js @@ -186,23 +186,24 @@ module.exports = { 'shortTitle': 'TGN', 'timePeriod': 'contemporary', 'endpoint': 'http://vocab.getty.edu/sparql.json', - 'simpleSuggestionQuery': ` - PREFIX gvp: <http://vocab.getty.edu/ontology#> - PREFIX luc: <http://www.ontotext.com/owlim/lucene#> - PREFIX foaf: <http://xmlns.com/foaf/0.1/> - PREFIX skos: <http://www.w3.org/2004/02/skos/core#> - PREFIX xl: <http://www.w3.org/2008/05/skos-xl#> - PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> - PREFIX wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#> - SELECT DISTINCT ?label - WHERE { - ?s skos:inScheme <http://vocab.getty.edu/tgn/> . - ?s luc:term '<QUERYTERM>*' . - ?s gvp:prefLabelGVP [xl:literalForm ?lbl] - BIND(STR(?lbl) AS ?label) - } - LIMIT 20 - `, + // 'simpleSuggestionQuery': ` + // PREFIX gvp: <http://vocab.getty.edu/ontology#> + // PREFIX luc: <http://www.ontotext.com/owlim/lucene#> + // PREFIX foaf: <http://xmlns.com/foaf/0.1/> + // PREFIX skos: <http://www.w3.org/2004/02/skos/core#> + // PREFIX xl: <http://www.w3.org/2008/05/skos-xl#> + // PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> + // PREFIX wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#> + // SELECT DISTINCT ?label + // WHERE { + // ?s skos:inScheme <http://vocab.getty.edu/tgn/> . + // ?s luc:term "<QUERYTERM>*" . + // ?s gvp:prefLabelGVP [xl:literalForm ?lbl] + // BIND(STR(?lbl) AS ?label) + // } + // LIMIT 20 + // `, + 'simpleSuggestionQuery': 'SELECT+DISTINCT+?label{?s+skos:inScheme+tgn:;luc:term+"<QUERYTERM>*";gvp:prefLabelGVP/xl:literalForm?lbl+BIND(STR(?lbl)+AS+?label)}LIMIT+20', 'resultQuery': ` PREFIX text: <http://jena.apache.org/text#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> diff --git a/src/server/SparqlApi.js b/src/server/SparqlApi.js index ea0bf8efbe75c4eef8bb809e974a5b4a5a3fc4c7..310a280a9f7c5606745a7416c87e5e0a7615f19b 100644 --- a/src/server/SparqlApi.js +++ b/src/server/SparqlApi.js @@ -20,50 +20,36 @@ class SparqlApi { return new Promise((resolve, reject) => { if (this.endpoint === 'http://vocab.getty.edu/sparql.json') { - fetch('http://vocab.getty.edu/sparql.json?query=select*{?s+a+gvp:Facet;skos:inScheme+aat:;gvp:prefLabelGVP/xl:literalForm?label}') - .then(response => { return response.text();}) + //const q = 'select*{?s+a+gvp:Facet;skos:inScheme+aat:;gvp:prefLabelGVP/xl:literalForm?label}'; + const url = this.endpoint + '?query=' + query; + fetch(url) + .then(response => { + return response.json(); + }) .then(responseData => { - console.log(responseData); return resolve(responseData); }) .catch(error => console.log('error is', error)); + } else { + request.post(this.endpoint) + .send({ query }) + .set(headers) + .end((err, res) => { + if (err || !res.ok) return reject(err); + return resolve(res.text); + }); } - // - // fetch('http://vocab.getty.edu/sparql.json', - // { method: 'POST', - // body: 'query=' + query, - // }) - // .then(res => { - // return res.json() - // //res.text(); - // }) - // .then(data => console.log('data is', data)) - // .catch(error => console.log('error is', error)); - - // The res.text property contains the unparsed response body string. This - // property is always present for the client API, and only when the mime type - // matches "text/", "/json", or "x-www-form-urlencoded" by default for node. - // The reasoning is to conserve memory, as buffering text of - // large bodies such as multipart files or images is extremely inefficient. - // To force buffering see the "Buffering responses" section - - request.post(this.endpoint) - .send({ query }) - .set(headers) - .end((err, res) => { - //console.log(res.headers); - //console.log(res.body); - //console.log(res.text); - //console.log(res.req.rawHeaders) - if (err || !res.ok) return reject(err); - //return(resolve(JSON.stringify(test))); - return resolve(res.text); - }); }); } selectQuery(query, params = { headers: defaultSelectHeaders }) { - return this.query(query, params).then((data) => JSON.parse(data)); + return this.query(query, params).then((data) => { + if (this.endpoint === 'http://vocab.getty.edu/sparql.json') { + return(data); + } else { + return JSON.parse(data); + } + }); } constructQuery(query, params = { headers: defaultConstructHeaders }) { diff --git a/src/server/SparqlSearchEngine.js b/src/server/SparqlSearchEngine.js index a61275018069c8a1adf34bc7076b7b05e86a22c4..b0e9c5efd7dc4079594a5b9dd7d6e301490dedff 100644 --- a/src/server/SparqlSearchEngine.js +++ b/src/server/SparqlSearchEngine.js @@ -22,7 +22,6 @@ class SparqlSearchEngine { const { endpoint, simpleSuggestionQuery } = datasetConfig[datasetId]; const query = simpleSuggestionQuery.replace(/<QUERYTERM>/g, queryTerm); const sparqlApi = new SparqlApi({ endpoint }); - //console.log(query) return this.doSearch(query, sparqlApi, null) .then((results) => results.map(res => (res.label.value)));