From 326714a9675fa0d2c5d87674c70badce6786a328 Mon Sep 17 00:00:00 2001 From: esikkala <esko.ikkala@aalto.fi> Date: Thu, 9 Dec 2021 16:41:06 +0200 Subject: [PATCH] Clean up --- .../search_perspectives/perspective3.json | 1 + src/server/sparql/FacetValues.js | 77 ------------------ src/server/sparql/Utils.js | 78 +++++++++++++++++++ .../perspective_configs/Perspective3Config.js | 4 - .../sampo/perspective_configs/WarsaConfig.js | 9 --- 5 files changed, 79 insertions(+), 90 deletions(-) delete mode 100644 src/server/sparql/sampo/perspective_configs/WarsaConfig.js diff --git a/src/client/configs/sampo/perspective_configs/search_perspectives/perspective3.json b/src/client/configs/sampo/perspective_configs/search_perspectives/perspective3.json index 85336725..534ebfe7 100644 --- a/src/client/configs/sampo/perspective_configs/search_perspectives/perspective3.json +++ b/src/client/configs/sampo/perspective_configs/search_perspectives/perspective3.json @@ -170,6 +170,7 @@ "facets": { "type": { "containerClass": "three", + "facetLabelPredicate": "skos:prefLabel|rdfs:label", "facetType": "list", "facetValueFilter": "FILTER(?id NOT IN ( <http://ldf.fi/mmm/schema/PlaceNationality> ))", "filterType": "uriFilter", diff --git a/src/server/sparql/FacetValues.js b/src/server/sparql/FacetValues.js index 52b086b9..9d17d660 100644 --- a/src/server/sparql/FacetValues.js +++ b/src/server/sparql/FacetValues.js @@ -1,4 +1,3 @@ -import { perspective3Config } from './sampo/perspective_configs/Perspective3Config' import { runSelectQuery } from './SparqlApi' import { has } from 'lodash' import { @@ -27,82 +26,6 @@ export const getFacet = async ({ constrainSelf }) => { const facetConfig = backendSearchConfig[facetClass].facets[facetID] - - const oldFacets = perspective3Config.facets - const mergedFacets = backendSearchConfig[facetClass].facets - - for (const facetID in oldFacets) { - const oldFacet = oldFacets[facetID] - // strip new lines - if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { - oldFacet.facetValueFilter = oldFacet.facetValueFilter.replace(/\s+/g, ' ').trim() - } - if (oldFacet.predicate && oldFacet.predicate !== '') { - oldFacet.predicate = oldFacet.predicate.replace(/\s+/g, ' ').trim() - } - if (oldFacet.labelPath && oldFacet.labelPath !== '') { - oldFacet.labelPath = oldFacet.labelPath.replace(/\s+/g, ' ').trim() - } - if (oldFacet.textQueryPredicate && oldFacet.textQueryPredicate !== '') { - oldFacet.textQueryPredicate = oldFacet.textQueryPredicate.replace(/\s+/g, ' ').trim() - } - - if (oldFacet.type === 'text') { - mergedFacets[facetID].facetType = 'text' - mergedFacets[facetID].textQueryProperty = oldFacet.textQueryProperty - if (oldFacet.textQueryPredicate && oldFacet.textQueryPredicate !== '') { - mergedFacets[facetID].textQueryPredicate = oldFacet.textQueryPredicate - } else { - delete mergedFacets[facetID].textQueryPredicate - } - mergedFacets[facetID].sortByPredicate = oldFacet.labelPath - } - if (oldFacet.type === 'list') { - if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { - mergedFacets[facetID].facetValueFilter = oldFacet.facetValueFilter - } - if (has(oldFacet, 'literal')) { - mergedFacets[facetID].literal = oldFacet.literal - } - mergedFacets[facetID].facetType = 'list' - mergedFacets[facetID].predicate = oldFacet.predicate - mergedFacets[facetID].sortByPredicate = oldFacet.labelPath - } - - if (oldFacet.type === 'hierarchical') { - if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { - mergedFacets[facetID].facetValueFilter = oldFacet.facetValueFilter - } - mergedFacets[facetID].facetType = 'hierarchical' - mergedFacets[facetID].predicate = oldFacet.predicate - mergedFacets[facetID].sortByPredicate = oldFacet.labelPath - mergedFacets[facetID].parentProperty = oldFacet.parentProperty - } - - if (oldFacet.type === 'timespan') { - mergedFacets[facetID].facetType = 'timespan' - mergedFacets[facetID].sortByAscPredicate = oldFacet.sortByAscPredicate - mergedFacets[facetID].sortByDescPredicate = oldFacet.sortByDescPredicate - mergedFacets[facetID].predicate = oldFacet.predicate - mergedFacets[facetID].startProperty = oldFacet.startProperty - mergedFacets[facetID].endProperty = oldFacet.endProperty - } - } - - for (const facetID in mergedFacets) { - const unorderedFacet = mergedFacets[facetID] - const orderedFacet = Object.keys(unorderedFacet).sort().reduce( - (obj, key) => { - obj[key] = unorderedFacet[key] - return obj - }, - {} - ) - mergedFacets[facetID] = orderedFacet - } - - // console.log(JSON.stringify(mergedFacets)) - const { endpoint, defaultConstraint = null, langTag = null } = backendSearchConfig[facetClass] // choose query template and result mapper: let q = '' diff --git a/src/server/sparql/Utils.js b/src/server/sparql/Utils.js index fdbab9a3..080afc28 100644 --- a/src/server/sparql/Utils.js +++ b/src/server/sparql/Utils.js @@ -1,4 +1,5 @@ import { readFile } from 'fs/promises' +import { has } from 'lodash' export const createBackendSearchConfig = async () => { const portalConfigJSON = await readFile('src/client/configs/portalConfig.json') @@ -38,3 +39,80 @@ export const createBackendSearchConfig = async () => { } return backendSearchConfig } + +export const mergeFacetConfigs = (oldFacets, mergedFacets) => { + for (const facetID in oldFacets) { + if (!has(mergedFacets, facetID)) { + console.log(facetID + ' missing from new facets') + continue + } + const oldFacet = oldFacets[facetID] + // strip new lines + if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { + oldFacet.facetValueFilter = oldFacet.facetValueFilter.replace(/\s+/g, ' ').trim() + } + if (oldFacet.predicate && oldFacet.predicate !== '') { + oldFacet.predicate = oldFacet.predicate.replace(/\s+/g, ' ').trim() + } + if (oldFacet.labelPath && oldFacet.labelPath !== '') { + oldFacet.labelPath = oldFacet.labelPath.replace(/\s+/g, ' ').trim() + } + if (oldFacet.textQueryPredicate && oldFacet.textQueryPredicate !== '') { + oldFacet.textQueryPredicate = oldFacet.textQueryPredicate.replace(/\s+/g, ' ').trim() + } + + if (oldFacet.type === 'text') { + mergedFacets[facetID].facetType = 'text' + mergedFacets[facetID].textQueryProperty = oldFacet.textQueryProperty + if (oldFacet.textQueryPredicate && oldFacet.textQueryPredicate !== '') { + mergedFacets[facetID].textQueryPredicate = oldFacet.textQueryPredicate + } else { + delete mergedFacets[facetID].textQueryPredicate + } + mergedFacets[facetID].sortByPredicate = oldFacet.labelPath + } + if (oldFacet.type === 'list') { + if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { + mergedFacets[facetID].facetValueFilter = oldFacet.facetValueFilter + } + if (has(oldFacet, 'literal')) { + mergedFacets[facetID].literal = oldFacet.literal + } + mergedFacets[facetID].facetType = 'list' + mergedFacets[facetID].predicate = oldFacet.predicate + mergedFacets[facetID].sortByPredicate = oldFacet.labelPath + } + + if (oldFacet.type === 'hierarchical') { + if (oldFacet.facetValueFilter && oldFacet.facetValueFilter !== '') { + mergedFacets[facetID].facetValueFilter = oldFacet.facetValueFilter + } + mergedFacets[facetID].facetType = 'hierarchical' + mergedFacets[facetID].predicate = oldFacet.predicate + mergedFacets[facetID].sortByPredicate = oldFacet.labelPath + mergedFacets[facetID].parentProperty = oldFacet.parentProperty + } + + if (oldFacet.type === 'timespan') { + mergedFacets[facetID].facetType = 'timespan' + mergedFacets[facetID].sortByAscPredicate = oldFacet.sortByAscPredicate + mergedFacets[facetID].sortByDescPredicate = oldFacet.sortByDescPredicate + mergedFacets[facetID].predicate = oldFacet.predicate + mergedFacets[facetID].startProperty = oldFacet.startProperty + mergedFacets[facetID].endProperty = oldFacet.endProperty + } + } + + for (const facetID in mergedFacets) { + const unorderedFacet = mergedFacets[facetID] + const orderedFacet = Object.keys(unorderedFacet).sort().reduce( + (obj, key) => { + obj[key] = unorderedFacet[key] + return obj + }, + {} + ) + mergedFacets[facetID] = orderedFacet + } + console.log(JSON.stringify(mergedFacets)) +} diff --git a/src/server/sparql/sampo/perspective_configs/Perspective3Config.js b/src/server/sparql/sampo/perspective_configs/Perspective3Config.js index 20f5ed5a..b907cb4b 100644 --- a/src/server/sparql/sampo/perspective_configs/Perspective3Config.js +++ b/src/server/sparql/sampo/perspective_configs/Perspective3Config.js @@ -18,10 +18,6 @@ export const perspective3Config = { relatedInstances: '' }, facets: { - prefLabel: { - id: 'prefLabel', - labelPath: 'skos:prefLabel' - }, type: { predicate: 'a', facetValueFilter: ` diff --git a/src/server/sparql/sampo/perspective_configs/WarsaConfig.js b/src/server/sparql/sampo/perspective_configs/WarsaConfig.js deleted file mode 100644 index 18de616e..00000000 --- a/src/server/sparql/sampo/perspective_configs/WarsaConfig.js +++ /dev/null @@ -1,9 +0,0 @@ -import { prefixes } from '../sparql_queries/SparqlQueriesPrefixes' - -export const warsaConfig = { - endpoint: { - url: 'http://ldf.fi/warsa/sparql', - prefixes, - useAuth: false - } -} -- GitLab