diff --git a/package.json b/package.json index 4cdaf304c390ce71847cafe05e279b2c4047c845..00f9712a273d030fdaf868bcb2e9c3391c191a6f 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "client": "cross-env BABEL_ENV=browser webpack serve --config webpack.client.dev.js", "dev": "concurrently --prefix none --kill-others \"npm run server\" \"npm run client\"", "server": "cross-env BABEL_ENV=node NODE_ENV=development nodemon -r dotenv/config src/server/index.js --exec babel-node", + "utils": "cross-env BABEL_ENV=node NODE_ENV=development nodemon -r dotenv/config src/server/sparql/Utils.js --exec babel-node", "sitemap": "cross-env BABEL_ENV=node babel-node src/server/sitemap_generator/SitemapGenerator.js", "translate": "cross-env BABEL_ENV=node babel-node src/server/translations_generator/index.js" }, diff --git a/src/client/configs/sampo/perspective_configs/search_perspectives/perspective1.json b/src/client/configs/sampo/perspective_configs/search_perspectives/perspective1.json index f7d0adea6b6ca65d963e7e5c275005414ce8dda6..c14880b58cd7aa2ba92a1d3882caeffa4b73821e 100644 --- a/src/client/configs/sampo/perspective_configs/search_perspectives/perspective1.json +++ b/src/client/configs/sampo/perspective_configs/search_perspectives/perspective1.json @@ -28,15 +28,6 @@ "instancePageConfig": { "propertiesQueryBlock": "manuscriptPropertiesInstancePage" } - }, - "placesMsProduced": { - "query": "productionPlacesQuery", - "filterTarget": "manuscripts", - "resultMapper": "mapPlaces", - "instance": { - "properties": "placePropertiesInfoWindow", - "relatedInstances": "manuscriptsProducedAt" - } } }, "maps": { diff --git a/src/server/sparql/Utils.js b/src/server/sparql/Utils.js index 080afc2859d4d74ac258efc92ff6a51ec8e4e56f..d7042e959985a5f0b5e987cf51a135750328fd76 100644 --- a/src/server/sparql/Utils.js +++ b/src/server/sparql/Utils.js @@ -1,5 +1,6 @@ import { readFile } from 'fs/promises' import { has } from 'lodash' +import { backendSearchConfig } from '../sparql/sampo/BackendSearchConfig' export const createBackendSearchConfig = async () => { const portalConfigJSON = await readFile('src/client/configs/portalConfig.json') @@ -116,3 +117,41 @@ export const mergeFacetConfigs = (oldFacets, mergedFacets) => { } console.log(JSON.stringify(mergedFacets)) } + +const mergeResultClasses = async () => { + const portalConfigJSON = await readFile('src/client/configs/portalConfig.json') + const portalConfig = JSON.parse(portalConfigJSON) + const { portalID } = portalConfig + const newPerspectiveConfigs = {} + for (const newResultClass in backendSearchConfig) { + const resultClassConfig = backendSearchConfig[newResultClass] + if (has(resultClassConfig, 'perspectiveID')) { + const { perspectiveID } = resultClassConfig + const perspectiveConfigJSON = await readFile(`src/client/configs/${portalID}/perspective_configs/search_perspectives/${perspectiveID}.json`) + if (!has(newPerspectiveConfigs, perspectiveID)) { + newPerspectiveConfigs[perspectiveID] = JSON.parse(perspectiveConfigJSON) + } + } + } + for (const newResultClass in backendSearchConfig) { + const resultClassConfig = backendSearchConfig[newResultClass] + if (has(resultClassConfig, 'perspectiveID')) { + const { perspectiveID } = resultClassConfig + const { filterTarget, resultMapper, resultMapperConfig } = resultClassConfig + let resultMapperName = null + if (resultMapper) { + resultMapperName = resultMapper.name + } + newPerspectiveConfigs[perspectiveID].resultClasses[newResultClass] = { + ...(filterTarget && { filterTarget }), + ...(resultMapperName && { resultMapper: resultMapperName }), + ...(resultMapperConfig && { resultMapperConfig }) + } + } + } + // const { q } = backendSearchConfig.eventLineChart + // console.log(newPerspectiveConfigs.perspective1.resultClasses) +} +// const varToString = varObj => Object.keys(varObj)[0] + +mergeResultClasses() diff --git a/src/server/sparql/sampo/BackendSearchConfig.js b/src/server/sparql/sampo/BackendSearchConfig.js index fa8facc77f48314be099882708ac71c1461a038c..886867bf104621b92abb0b886dcaee45335ea7df 100644 --- a/src/server/sparql/sampo/BackendSearchConfig.js +++ b/src/server/sparql/sampo/BackendSearchConfig.js @@ -1,135 +1,44 @@ import { perspective1Config } from './perspective_configs/Perspective1Config' import { perspective2Config } from './perspective_configs/Perspective2Config' import { perspective3Config } from './perspective_configs/Perspective3Config' -import { findsConfig } from './perspective_configs/FindsConfig' -import { actorsConfig } from './perspective_configs/EmloActorsConfig' -import { hellerauConfig } from './perspective_configs/HellerauConfig' -import { speechesConfig } from './perspective_configs/SemparlSpeechesConfig' -import { warsaConfig } from './perspective_configs/WarsaConfig' import { productionPlacesQuery, lastKnownLocationsQuery, migrationsQuery, migrationsDialogQuery, - manuscriptPropertiesInstancePage, - expressionProperties, - collectionProperties, productionsByDecadeQuery, productionsByDecadeAndCountryQuery, eventsByDecadeQuery, manuscriptInstancePageNetworkLinksQuery, manuscriptFacetResultsNetworkLinksQuery, manuscriptNetworkNodesQuery, - knowledgeGraphMetadataQuery, - choroplethQuery + knowledgeGraphMetadataQuery } from './sparql_queries/SparqlQueriesPerspective1' +// import { +// eventPlacesQuery +// } from './sparql_queries/SparqlQueriesPerspective3' import { - workProperties -} from './sparql_queries/SparqlQueriesPerspective2' -import { - eventProperties, - eventPlacesQuery -} from './sparql_queries/SparqlQueriesPerspective3' -import { - actorProperties -} from './sparql_queries/SparqlQueriesActors' -import { - placePropertiesInstancePage, placePropertiesInfoWindow, manuscriptsProducedAt, lastKnownLocationsAt } from './sparql_queries/SparqlQueriesPlaces' -import { - findPropertiesInstancePage, - findsPlacesQuery, - findsTimelineQuery, - nearbyFindsQuery -} from './sparql_queries/SparqlQueriesFinds' -import { - emloLetterLinksQuery, - emloNetworkNodesQuery, - emloPeopleEventPlacesQuery, - emloSentReceivedQuery -} from './sparql_queries/SparqlQueriesEmloActors' -import { - emloPlacePropertiesInfoWindow, - emloPeopleRelatedTo -} from './sparql_queries/SparqlQueriesEmloPlaces' -import { hellerauMigrationsQuery } from './sparql_queries/SparqlQueriesHellerau' -import { speechesByYearAndPartyQuery } from './sparql_queries/SparqlQueriesSpeeches' -import { federatedSearchDatasets } from './sparql_queries/SparqlQueriesFederatedSearch' -import { fullTextSearchProperties } from './sparql_queries/SparqlQueriesFullText' -import { sitemapInstancePageQuery } from '../SparqlQueriesGeneral' +// import { federatedSearchDatasets } from './sparql_queries/SparqlQueriesFederatedSearch' +// import { fullTextSearchProperties } from './sparql_queries/SparqlQueriesFullText' +// import { sitemapInstancePageQuery } from '../SparqlQueriesGeneral' import { makeObjectList } from '../SparqlObjectMapper' import { mapPlaces, mapLineChart, mapMultipleLineChart, linearScale, - toBarChartRaceFormat, - toPolygonLayerFormat + toBarChartRaceFormat + // toPolygonLayerFormat } from '../Mappers' export const backendSearchConfig = { perspective1: perspective1Config, perspective2: perspective2Config, perspective3: perspective3Config, - finds: findsConfig, - emloActors: actorsConfig, - hellerau: hellerauConfig, - semparlSpeeches: speechesConfig, - warsa: warsaConfig, - manuscripts: { - perspectiveID: 'perspective1', // get rest of the config from 'perspective1' - instance: { - properties: manuscriptPropertiesInstancePage, - relatedInstances: '' - } - }, - works: { - perspectiveID: 'perspective1', - rdfType: 'frbroo:F1_Work', - includeInSitemap: true, - instance: { - properties: workProperties, - relatedInstances: '' - } - }, - events: { - perspectiveID: 'perspective1', - instance: { - properties: eventProperties, - relatedInstances: '' - } - }, - actors: { - perspectiveID: 'perspective1', - instance: { - properties: actorProperties, - relatedInstances: '' - } - }, - places: { - perspectiveID: 'perspective1', - instance: { - properties: placePropertiesInstancePage, - relatedInstances: '' - } - }, - expressions: { - perspectiveID: 'perspective1', - instance: { - properties: expressionProperties, - relatedInstances: '' - } - }, - collections: { - perspectiveID: 'perspective1', - instance: { - properties: collectionProperties, - relatedInstances: '' - } - }, placesMsProduced: { perspectiveID: 'perspective1', q: productionPlacesQuery, @@ -170,33 +79,22 @@ export const backendSearchConfig = { } } }, - casualtiesByMunicipality: { - perspectiveID: 'warsa', - q: choroplethQuery, - resultMapper: makeObjectList, - postprocess: { - func: toPolygonLayerFormat, - config: { - variable: 'death' - } - } - }, placesMsMigrationsDialog: { perspectiveID: 'perspective1', q: migrationsDialogQuery, filterTarget: 'id', resultMapper: makeObjectList }, - placesEvents: { - perspectiveID: 'perspective3', - q: eventPlacesQuery, - filterTarget: 'event', - resultMapper: mapPlaces, - instance: { - properties: placePropertiesInfoWindow, - relatedInstances: '' - } - }, + // placesEvents: { + // perspectiveID: 'perspective3', + // q: eventPlacesQuery, + // filterTarget: 'event', + // resultMapper: mapPlaces, + // instance: { + // properties: placePropertiesInfoWindow, + // relatedInstances: '' + // } + // }, productionTimespanLineChart: { perspectiveID: 'perspective1', q: productionsByDecadeQuery, @@ -218,18 +116,6 @@ export const backendSearchConfig = { } } }, - speechesByYearAndParty: { - perspectiveID: 'semparlSpeeches', - q: speechesByYearAndPartyQuery, - filterTarget: 'speech', - resultMapper: makeObjectList, - postprocess: { - func: toBarChartRaceFormat, - config: { - step: 1 - } - } - }, eventLineChart: { perspectiveID: 'perspective1', q: eventsByDecadeQuery, @@ -252,80 +138,24 @@ export const backendSearchConfig = { filterTarget: 'manuscript', useNetworkAPI: true }, - findsPlaces: { - perspectiveID: 'finds', // use endpoint config from finds - q: findsPlacesQuery, - filterTarget: 'id', - resultMapper: mapPlaces, - instance: { - properties: findPropertiesInstancePage, - relatedInstances: '' - } - }, - findsTimeline: { - perspectiveID: 'finds', // use endpoint config from finds - q: findsTimelineQuery, - filterTarget: 'find', - resultMapper: makeObjectList - }, - nearbyFinds: { - perspectiveID: 'finds', // use endpoint config from finds - q: nearbyFindsQuery, - resultMapper: makeObjectList, - instance: { - properties: findPropertiesInstancePage, - relatedInstances: '' - } - }, - emloPlacesActors: { - perspectiveID: 'emloActors', - q: emloPeopleEventPlacesQuery, - filterTarget: 'person', - resultMapper: mapPlaces, - instance: { - properties: emloPlacePropertiesInfoWindow, - relatedInstances: emloPeopleRelatedTo - } - }, - emloLetterNetwork: { - perspectiveID: 'emloActors', - q: emloLetterLinksQuery, - nodes: emloNetworkNodesQuery, - useNetworkAPI: true - }, - emloSentReceived: { - perspectiveID: 'emloActors', - q: emloSentReceivedQuery, - // filterTarget: 'id', - resultMapper: mapMultipleLineChart, - resultMapperConfig: { - fillEmptyValues: false - } - }, - hellerauMigrations: { - perspectiveID: 'hellerau', - q: hellerauMigrationsQuery, - filterTarget: 'person__id', - resultMapper: makeObjectList - }, perspective1KnowledgeGraphMetadata: { perspectiveID: 'perspective1', q: knowledgeGraphMetadataQuery, resultMapper: makeObjectList - }, - jenaText: { - perspectiveID: 'perspective1', - properties: fullTextSearchProperties - }, - federatedSearch: { - datasets: federatedSearchDatasets - }, - sitemapConfig: { - baseUrl: 'https://sampo-ui.demo.seco.cs.aalto.fi', - langPrimary: 'en', - langSecondary: 'fi', - outputDir: './src/server/sitemap_generator', - sitemapUrl: 'https://sampo-ui.demo.seco.cs.aalto.fi/sitemap', - sitemapInstancePageQuery } + // jenaText: { + // perspectiveID: 'perspective1', + // properties: fullTextSearchProperties + // }, + // federatedSearch: { + // datasets: federatedSearchDatasets + // }, + // sitemapConfig: { + // baseUrl: 'https://sampo-ui.demo.seco.cs.aalto.fi', + // langPrimary: 'en', + // langSecondary: 'fi', + // outputDir: './src/server/sitemap_generator', + // sitemapUrl: 'https://sampo-ui.demo.seco.cs.aalto.fi/sitemap', + // sitemapInstancePageQuery + // } }