Skip to content
Snippets Groups Projects
Commit 3675d62b authored by esikkala's avatar esikkala
Browse files

Remove old perspective configs

parent 093a1df0
No related branches found
No related tags found
No related merge requests found
// import { backendSearchConfig } from './sparql/sampo/BackendSearchConfig'
import fs from 'fs'
import express from 'express'
import path from 'path'
......
import { has } from 'lodash'
import { runSelectQuery } from './SparqlApi'
import { runNetworkQuery } from './NetworkApi'
import { makeObjectList } from './SparqlObjectMapper'
import { mapCount } from './Mappers'
import { makeObjectList, mapCount } from './Mappers'
import { generateConstraintsBlock } from './Filters'
import {
countQuery,
......
import { has } from 'lodash'
import { runSelectQuery } from './SparqlApi'
import { fullTextQuery } from './SparqlQueriesGeneral'
import { makeObjectList } from './SparqlObjectMapper'
import { makeObjectList } from './Mappers'
export const queryJenaIndex = async ({
backendSearchConfig,
......
import _ from 'lodash'
// const NS_PER_SEC = 1e9
// const MS_PER_NS = 1e-6
/**
* @param {Array} objects A list of objects as SPARQL results.
* @returns {Array} The mapped object list.
* @description
* Map the SPARQL results as objects, and return a list where result rows with the same
* id are merged into one object.
*/
export const makeObjectList = (objects) => {
// const time = process.hrtime()
const objList = _.transform(objects, function (result, obj) {
if (!obj.id) {
return null
}
// let orig = obj;
obj = makeObject(obj)
// obj = reviseObject(obj, orig);
mergeValueToList(result, obj)
})
// const diff = process.hrtime(time)
// console.log(`makeObjectList took ${(diff[0] * NS_PER_SEC + diff[1]) * MS_PER_NS} milliseconds`)
return objList
// return self.postProcess(objList);
}
export const makeDict = (objects) => {
return arrayToObject(objects, 'id')
}
/**
* @param {Object} obj A single SPARQL result row object.
* @returns {Object} The mapped object.
* @description
* Flatten the result object. Discard everything except values.
* Assume that each property of the obj has a value property with
* the actual value.
*/
const makeObject = (obj) => {
const o = {}
_.forIn(obj, function (value, key) {
// If the variable name contains "__", an object
// will be created as the value
// E.g. { place__id: '1' } -> { place: { id: '1' } }
_.set(o, key.replace(/__/g, '.'), value.value)
})
return o
}
/**
* @param {Array} valueList A list to which the value should be added.
* @param {Object} value The value to add to the list.
* @returns {Array} The merged list.
* @description
* Add the given value to the given list, merging an object value to and
* object in the list if both have the same id attribute.
* A value already present in valueList is discarded.
*/
const mergeValueToList = (valueList, value) => {
let old
if (_.isObject(value) && value.id) {
// Check if this object has been constructed earlier
old = _.findLast(valueList, function (e) {
return e.id === value.id
})
if (old) {
// Merge this object to the object constructed earlier
mergeObjects(old, value)
}
} else {
// Check if this value is present in the list
old = _.findLast(valueList, function (e) {
return _.isEqual(e, value)
})
}
if (!old) {
// This is a distinct value
valueList.push(value)
}
return valueList
}
/**
* @param {Object} first An object as returned by makeObject.
* @param {Object} second The object to merge with the first.
* @returns {Object} The merged object.
* @description
* Merges two objects.
*/
const mergeObjects = (first, second) => {
// Merge two objects into one object.
return _.mergeWith(first, second, merger)
}
const merger = (a, b) => {
if (_.isEqual(a, b)) {
return a
}
if (a && !b) {
return a
}
if (b && !a) {
return b
}
if (_.isArray(a)) {
if (_.isArray(b)) {
b.forEach(function (bVal) {
return mergeValueToList(a, bVal)
})
return a
}
return mergeValueToList(a, b)
}
if (_.isArray(b)) {
return mergeValueToList(b, a)
}
if (!(_.isObject(a) && _.isObject(b) && a.id === b.id)) {
return [a, b]
}
return mergeObjects(a, b)
}
const arrayToObject = (array, keyField) =>
array.reduce((obj, item) => {
const newItem = {}
Object.entries(item).forEach(([key, value]) => {
if (key !== keyField) {
newItem[key] = value.value
}
})
obj[item[keyField].value] = newItem
return obj
}, {})
import { readFile } from 'fs/promises'
import { has } from 'lodash'
import { backendSearchConfig } from '../sparql/sampo/BackendSearchConfig'
// import { backendSearchConfig } from '../sparql/sampo/BackendSearchConfig'
export const createBackendSearchConfig = async () => {
const portalConfigJSON = await readFile('src/client/configs/portalConfig.json')
......@@ -156,14 +156,14 @@ export const mergeFacetConfigs = (oldFacets, mergedFacets) => {
console.log(JSON.stringify(mergedFacets))
}
export const mergeResultClasses = async () => {
export const mergeResultClasses = async oldBackendSearchConfig => {
const portalConfigJSON = await readFile('src/client/configs/portalConfig.json')
const portalConfig = JSON.parse(portalConfigJSON)
const { portalID } = portalConfig
const newPerspectiveConfigs = {}
// build initial config object
for (const newResultClass in backendSearchConfig) {
const resultClassConfig = backendSearchConfig[newResultClass]
for (const newResultClass in oldBackendSearchConfig) {
const resultClassConfig = oldBackendSearchConfig[newResultClass]
if (has(resultClassConfig, 'perspectiveID')) {
const { perspectiveID } = resultClassConfig
if (!has(newPerspectiveConfigs, perspectiveID)) {
......@@ -173,8 +173,8 @@ export const mergeResultClasses = async () => {
}
}
// merge result classes
for (const newResultClass in backendSearchConfig) {
const resultClassConfig = backendSearchConfig[newResultClass]
for (const newResultClass in oldBackendSearchConfig) {
const resultClassConfig = oldBackendSearchConfig[newResultClass]
if (has(resultClassConfig, 'perspectiveID')) {
const { perspectiveID } = resultClassConfig
const { q, nodes, filterTarget, resultMapper, resultMapperConfig, instance, properties, useNetworkAPI } = resultClassConfig
......
import { perspective1Config } from './perspective_configs/Perspective1Config'
import { perspective2Config } from './perspective_configs/Perspective2Config'
import { perspective3Config } from './perspective_configs/Perspective3Config'
// 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
} from '../Mappers'
export const backendSearchConfig = {
perspective1: perspective1Config,
perspective2: perspective2Config,
perspective3: perspective3Config,
placesMsProduced: {
perspectiveID: 'perspective1',
q: 'productionPlacesQuery',
filterTarget: 'manuscripts',
resultMapper: mapPlaces,
instance: {
properties: 'placePropertiesInfoWindow',
relatedInstances: 'manuscriptsProducedAt'
}
},
placesMsProducedHeatmap: {
perspectiveID: 'perspective1',
q: 'productionPlacesQuery',
filterTarget: 'manuscripts',
resultMapper: mapPlaces
},
lastKnownLocations: {
perspectiveID: 'perspective1',
q: 'lastKnownLocationsQuery',
filterTarget: 'manuscripts',
resultMapper: mapPlaces,
instance: {
properties: 'placePropertiesInfoWindow',
relatedInstances: 'lastKnownLocationsAt'
}
},
placesMsMigrations: {
perspectiveID: 'perspective1',
q: 'migrationsQuery',
filterTarget: 'manuscript',
resultMapper: makeObjectList,
postprocess: {
func: linearScale,
config: {
variable: 'instanceCount',
minAllowed: 3,
maxAllowed: 30
}
}
},
placesMsMigrationsDialog: {
perspectiveID: 'perspective1',
q: 'migrationsDialogQuery',
filterTarget: 'id',
resultMapper: makeObjectList
},
placesEvents: {
perspectiveID: 'perspective3',
q: 'eventPlacesQuery',
filterTarget: 'event',
resultMapper: mapPlaces,
instance: {
properties: 'placePropertiesInfoWindow'
}
},
productionTimespanLineChart: {
perspectiveID: 'perspective1',
q: 'productionsByDecadeQuery',
filterTarget: 'instance',
resultMapper: mapLineChart,
resultMapperConfig: {
fillEmptyValues: false
}
},
productionsByDecadeAndCountry: {
perspectiveID: 'perspective1',
q: 'productionsByDecadeAndCountryQuery',
filterTarget: 'manuscript',
resultMapper: makeObjectList,
postprocess: {
func: toBarChartRaceFormat,
config: {
step: 10
}
}
},
eventLineChart: {
perspectiveID: 'perspective1',
q: 'eventsByDecadeQuery',
filterTarget: 'manuscript',
resultMapper: mapMultipleLineChart,
resultMapperConfig: {
fillEmptyValues: false
}
},
manuscriptInstancePageNetwork: {
perspectiveID: 'perspective1',
q: 'manuscriptInstancePageNetworkLinksQuery',
nodes: 'manuscriptNetworkNodesQuery',
useNetworkAPI: true
},
manuscriptFacetResultsNetwork: {
perspectiveID: 'perspective1',
q: 'manuscriptFacetResultsNetworkLinksQuery',
nodes: 'manuscriptNetworkNodesQuery',
filterTarget: 'manuscript',
useNetworkAPI: true
},
perspective1KnowledgeGraphMetadata: {
perspectiveID: 'perspective1',
q: 'knowledgeGraphMetadataQuery',
resultMapper: makeObjectList
},
jenaText: {
perspectiveID: 'perspective1',
properties: 'fullTextSearchProperties'
}
}
import {
manuscriptPropertiesFacetResults,
manuscriptPropertiesInstancePage
} from '../sparql_queries/SparqlQueriesPerspective1'
import { prefixes } from '../sparql_queries/SparqlQueriesPrefixes'
export const perspective1Config = {
endpoint: {
url: 'http://ldf.fi/mmm/sparql',
prefixes,
useAuth: false
},
facetClass: 'frbroo:F4_Manifestation_Singleton',
includeInSitemap: true,
// defaultConstraint: `
// <SUBJECT> dct:source mmm-schema:Bibale .
// `,
paginatedResultsConfig: {
propertiesQueryBlock: manuscriptPropertiesFacetResults
// resultMapper:
// resultMapperConfig:
// postprocess:
},
instance: {
properties: manuscriptPropertiesInstancePage,
relatedInstances: '',
defaultTab: 'table'
},
facets: {
prefLabel: {
id: 'prefLabel',
labelPath: 'skos:prefLabel',
textQueryPredicate: '', // empty for querying the facetClass
textQueryProperty: 'skos:prefLabel', // limit only to prefLabels
type: 'text'
},
author: {
id: 'author',
facetValueFilter: '',
hideUnknownValue: true,
label: 'Author',
labelPath: 'mmm-schema:manuscript_author/skos:prefLabel',
predicate: 'mmm-schema:manuscript_author',
type: 'list'
},
work: {
id: 'work',
labelPath: 'mmm-schema:manuscript_work/skos:prefLabel',
textQueryPredicate: 'mmm-schema:manuscript_work', // text query for works
textQueryProperty: '', // query everything in text index
type: 'text'
},
productionPlace: {
id: 'productionPlace',
facetValueFilter: `
?id dct:source <http://vocab.getty.edu/tgn/> .
`,
label: 'Production place',
labelPath: '^crm:P108_has_produced/crm:P7_took_place_at/skos:prefLabel',
predicate: '^crm:P108_has_produced/crm:P7_took_place_at',
parentProperty: 'gvp:broaderPreferred',
type: 'hierarchical'
},
productionTimespan: {
id: 'productionTimespan',
facetValueFilter: '',
sortByAscPredicate: '^crm:P108_has_produced/crm:P4_has_time-span/crm:P82a_begin_of_the_begin',
sortByDescPredicate: '^crm:P108_has_produced/crm:P4_has_time-span/crm:P82b_end_of_the_end',
predicate: '^crm:P108_has_produced/crm:P4_has_time-span',
startProperty: 'crm:P82a_begin_of_the_begin',
endProperty: 'crm:P82b_end_of_the_end',
type: 'timespan'
},
note: {
id: 'note',
labelPath: 'crm:P3_has_note',
textQueryPredicate: '', // empty for querying the facetClass
textQueryProperty: 'crm:P3_has_note',
type: 'text'
},
transferOfCustodyPlace: {
id: 'productionPlace',
facetValueFilter: `
?id dct:source <http://vocab.getty.edu/tgn/> .
`,
label: 'Transfer of custody place',
labelPath: '^crm:P30_transferred_custody_of/crm:P7_took_place_at/skos:prefLabel',
predicate: '^crm:P30_transferred_custody_of/crm:P7_took_place_at',
parentProperty: 'gvp:broaderPreferred',
type: 'hierarchical'
},
transferOfCustodyTimespan: {
id: 'transferOfCustodyTimespan',
facetValueFilter: '',
sortByAscPredicate: '^crm:P30_transferred_custody_of/crm:P4_has_time-span/crm:P82a_begin_of_the_begin',
sortByDescPredicate: '^crm:P30_transferred_custody_of/crm:P4_has_time-span/crm:P82b_end_of_the_end',
predicate: '^crm:P30_transferred_custody_of/crm:P4_has_time-span',
startProperty: 'crm:P82a_begin_of_the_begin',
endProperty: 'crm:P82b_end_of_the_end',
type: 'timespan'
},
lastKnownLocation: {
id: 'lastKnownLocation',
facetValueFilter: `
?id dct:source <http://vocab.getty.edu/tgn/> .
`,
label: 'Production place',
labelPath: 'mmm-schema:last_known_location/skos:prefLabel',
predicate: 'mmm-schema:last_known_location',
parentProperty: 'gvp:broaderPreferred',
type: 'hierarchical'
},
language: {
id: 'language',
facetValueFilter: '',
label: 'Language',
labelPath: 'crm:P128_carries/crm:P72_has_language/skos:prefLabel',
predicate: 'crm:P128_carries/crm:P72_has_language',
type: 'list'
},
material: {
id: 'material',
facetValueFilter: '',
label: 'Language',
labelPath: 'crm:P45_consists_of/skos:prefLabel',
predicate: 'crm:P45_consists_of',
type: 'list'
},
height: {
id: 'height',
facetValueFilter: '',
labelPath: 'mmm-schema:height/crm:P90_has_value',
predicate: 'mmm-schema:height/crm:P90_has_value',
type: 'integer',
typecasting: 'BIND(xsd:integer(ROUND(?value)) as ?valueAsInteger)'
},
width: {
id: 'width',
facetValueFilter: '',
labelPath: 'mmm-schema:width/crm:P90_has_value',
predicate: 'mmm-schema:width/crm:P90_has_value',
type: 'integer'
},
folios: {
id: 'folios',
facetValueFilter: '',
labelPath: 'mmm-schema:folios/crm:P90_has_value',
predicate: 'mmm-schema:folios/crm:P90_has_value',
type: 'integer'
},
lines: {
id: 'lines',
facetValueFilter: '',
labelPath: 'mmm-schema:lines/crm:P90_has_value',
predicate: 'mmm-schema:lines/crm:P90_has_value',
type: 'integer'
},
columns: {
id: 'columns',
facetValueFilter: '',
labelPath: 'mmm-schema:columns/crm:P90_has_value',
predicate: 'mmm-schema:columns/crm:P90_has_value',
type: 'integer'
},
miniatures: {
id: 'miniatures',
facetValueFilter: '',
labelPath: 'mmm-schema:miniatures/crm:P90_has_value',
predicate: 'mmm-schema:miniatures/crm:P90_has_value',
type: 'integer'
},
decoratedInitials: {
id: 'decoratedInitials',
facetValueFilter: '',
labelPath: 'mmm-schema:decorated_initials/crm:P90_has_value',
predicate: 'mmm-schema:decorated_initials/crm:P90_has_value',
type: 'integer'
},
historiatedInitials: {
id: 'historiatedInitials',
facetValueFilter: '',
labelPath: 'mmm-schema:historiated_initials/crm:P90_has_value',
predicate: 'mmm-schema:historiated_initials/crm:P90_has_value',
type: 'integer'
},
collection: {
id: 'collection',
facetValueFilter: '',
labelPath: 'crm:P46i_forms_part_of/skos:prefLabel',
predicate: 'crm:P46i_forms_part_of',
type: 'list'
},
owner: {
id: 'owner',
facetValueFilter: '',
label: 'Owner',
labelPath: 'crm:P51_has_former_or_current_owner/skos:prefLabel',
predicate: 'crm:P51_has_former_or_current_owner',
type: 'list'
},
source: {
id: 'source',
facetValueFilter: '',
label: 'Source',
labelPath: 'dct:source/skos:prefLabel',
predicate: 'dct:source',
type: 'list'
}
}
}
import {
workProperties
} from '../sparql_queries/SparqlQueriesPerspective2'
import { prefixes } from '../sparql_queries/SparqlQueriesPrefixes'
export const perspective2Config = {
endpoint: {
url: 'http://ldf.fi/mmm/sparql',
prefixes,
useAuth: false
},
facetClass: 'frbroo:F1_Work',
includeInSitemap: false,
paginatedResults: {
properties: workProperties
},
instance: {
properties: workProperties,
relatedInstances: ''
},
facets: {
prefLabel: {
id: 'prefLabel',
labelPath: 'skos:prefLabel',
textQueryPredicate: '', // empty for querying the facetClass
textQueryProperty: 'skos:prefLabel', // limit only to prefLabels
type: 'text'
},
source: {
id: 'source',
facetValueFilter: '',
labelPath: 'dct:source/skos:prefLabel',
predicate: 'dct:source',
type: 'list'
},
author: {
id: 'author',
facetValueFilter: '',
label: 'Author',
labelPath: '^frbroo:R16_initiated/(mmm-schema:carried_out_by_as_possible_author|mmm-schema:carried_out_by_as_author)/skos:prefLabel',
predicate: '^frbroo:R16_initiated/(mmm-schema:carried_out_by_as_possible_author|mmm-schema:carried_out_by_as_author)',
type: 'list'
},
manuscript: {
labelPath: '^mmm-schema:manuscript_work/skos:prefLabel'
},
language: {
id: 'language',
facetValueFilter: '',
label: 'Language',
labelPath: '^frbroo:R19_created_a_realisation_of/frbroo:R17_created/crm:P72_has_language/skos:prefLabel',
predicate: '^frbroo:R19_created_a_realisation_of/frbroo:R17_created/crm:P72_has_language',
type: 'list'
},
collection: {
id: 'collection',
facetValueFilter: '',
labelPath: '^mmm-schema:manuscript_work/crm:P46i_forms_part_of/skos:prefLabel',
predicate: '^mmm-schema:manuscript_work/crm:P46i_forms_part_of',
type: 'list'
},
productionTimespan: {
id: 'productionTimespan',
facetValueFilter: '',
sortByAscPredicate: '^mmm-schema:manuscript_work/^crm:P108_has_produced/crm:P4_has_time-span/crm:P82a_begin_of_the_begin',
sortByDescPredicate: '^mmm-schema:manuscript_work/^crm:P108_has_produced/crm:P4_has_time-span/crm:P82b_end_of_the_end',
predicate: '^mmm-schema:manuscript_work/^crm:P108_has_produced/crm:P4_has_time-span',
startProperty: 'crm:P82a_begin_of_the_begin',
endProperty: 'crm:P82b_end_of_the_end',
type: 'timespan'
}
}
}
import {
eventProperties
} from '../sparql_queries/SparqlQueriesPerspective3'
import { prefixes } from '../sparql_queries/SparqlQueriesPrefixes'
export const perspective3Config = {
endpoint: {
url: 'http://ldf.fi/mmm/sparql',
prefixes,
useAuth: false
},
facetClass: 'crm:E10_Transfer_of_Custody crm:E12_Production mmm-schema:ManuscriptActivity',
paginatedResults: {
properties: eventProperties
},
instance: {
properties: eventProperties,
relatedInstances: ''
},
facets: {
type: {
predicate: 'a',
facetValueFilter: `
FILTER(?id NOT IN (
<http://ldf.fi/mmm/schema/PlaceNationality>
))
`,
type: 'list',
labelPath: 'a/(skos:prefLabel|rdfs:label)'
},
manuscript: {
textQueryPredicate: `
(crm:P30_transferred_custody_of
|crm:P108_has_produced
|mmm-schema:observed_manuscript)`,
textQueryProperty: 'skos:prefLabel', // limit only to prefLabels
type: 'text',
labelPath: `(crm:P30_transferred_custody_of
|crm:P108_has_produced
|mmm-schema:observed_manuscript
)/skos:prefLabel`
},
eventTimespan: {
id: 'eventTimespan',
facetValueFilter: '',
sortByAscPredicate: 'crm:P4_has_time-span/crm:P82a_begin_of_the_begin',
sortByDescPredicate: 'crm:P4_has_time-span/crm:P82b_end_of_the_end',
predicate: 'crm:P4_has_time-span',
startProperty: 'crm:P82a_begin_of_the_begin',
endProperty: 'crm:P82b_end_of_the_end',
type: 'timespan'
},
place: {
id: 'place',
facetValueFilter: `
?id dct:source <http://vocab.getty.edu/tgn/> .
`,
label: 'Place',
labelPath: 'crm:P7_took_place_at/skos:prefLabel',
predicate: 'crm:P7_took_place_at',
parentProperty: 'gvp:broaderPreferred',
type: 'hierarchical'
},
placeType: {
id: 'placeType',
facetValueFilter: '',
label: 'Place type',
labelPath: 'crm:P7_took_place_at/gvp:placeTypePreferred',
predicate: 'crm:P7_took_place_at/gvp:placeTypePreferred',
type: 'list',
literal: true
},
source: {
id: 'source',
facetValueFilter: '',
labelPath: 'dct:source/skos:prefLabel',
predicate: 'dct:source',
type: 'list'
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment