Skip to content
Snippets Groups Projects
Commit 1f2545fb authored by Esko Ikkala's avatar Esko Ikkala
Browse files

Test manuscript query with group concat

parent 09f438c5
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,7 @@ class ResultTable extends React.Component {
idRenderer = (row) => {
let sdbmLink = '';
let id = row.id.replace('http://ldf.fi/mmm/manifestation_singleton/', '');
if (has(row, 'manuscriptRecord')) {
if (has(row, 'manuscriptRecord') && row.manuscriptRecord !== '-') {
sdbmLink = row.manuscriptRecord;
} else {
sdbmLink = row.entry;
......@@ -242,7 +242,7 @@ class ResultTable extends React.Component {
{this.objectListRenderer(row.creationPlace, true)}
</TableCell>
<TableCell>
{this.objectListRenderer(row.timespan, false)}
{this.stringListRenderer(row.timespan)}
</TableCell>
<TableCell>
{this.stringListRenderer(row.language)}
......
......@@ -95,7 +95,7 @@ module.exports = {
}
}
`,
'allQuery': `
'manuscriptQuery2': `
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
......@@ -109,15 +109,27 @@ module.exports = {
PREFIX sdbm: <https://sdbm.library.upenn.edu/>
SELECT
?id ?manuscriptRecord
#(GROUP_CONCAT(DISTINCT ?entry_; SEPARATOR=" | ") AS ?entry)
(GROUP_CONCAT(DISTINCT ?prefLabel_; SEPARATOR=" | ") AS ?prefLabel)
(GROUP_CONCAT(DISTINCT ?author_; SEPARATOR="|") AS ?author)
#(GROUP_CONCAT(DISTINCT ?owner_; SEPARATOR="|") AS ?owner)
(GROUP_CONCAT(DISTINCT ?timespan_; SEPARATOR="|") AS ?timespan)
(GROUP_CONCAT(DISTINCT ?creationPlace_; SEPARATOR="|") AS ?creationPlace)
(GROUP_CONCAT(DISTINCT ?material_; SEPARATOR="|") AS ?material)
(GROUP_CONCAT(DISTINCT ?language_; SEPARATOR="|") AS ?language)
WHERE {
?id a frbroo:F4_Manifestation_Singleton .
{
SELECT DISTINCT ?id {
<FILTER>
?id a frbroo:F4_Manifestation_Singleton .
}
<ORDER_BY>
<PAGE>
}
FILTER(BOUND(?id))
#?id mmm-schema:entry ?entry_ .
?id skos:prefLabel ?prefLabel_ .
OPTIONAL { ?id mmm-schema:manuscript_record ?manuscriptRecord . }
OPTIONAL { ?id crm:P45_consists_of ?material_ . }
?expression_creation frbroo:R18_created ?id .
OPTIONAL {
......@@ -125,6 +137,17 @@ module.exports = {
?authorId skos:prefLabel ?authorLabel
BIND(CONCAT(STR(?authorLabel), ";", STR(?authorId)) AS ?author_)
}
#OPTIONAL {
# ?id crm:P51_has_former_or_current_owner ?ownerId .
# ?ownerId skos:prefLabel ?ownerLabel .
#?rei a rdf:Statement ;
# rdf:subject ?id ;
# rdf:predicate crm:P51_has_former_or_current_owner ;
# rdf:object ?ownerId ;
# mmm-schema:entry ?owner__entry ;
# mmm-schema:order ?owner__order .
# BIND(CONCAT(STR(?ownerLabel), ";", STR(?ownerId)) AS ?owner_)
#}
OPTIONAL {
?expression_creation crm:P4_has_time_span ?timespanId .
?timespanId rdfs:label ?timespan_.
......@@ -138,11 +161,9 @@ module.exports = {
?id crm:P128_carries ?expression .
?expression crm:P72_has_language ?language_ .
}
OPTIONAL { ?id mmm-schema:manuscript_record ?manuscriptRecord . }
}
GROUP BY ?id ?manuscriptRecord
ORDER BY (!BOUND(?creationPlace)) ?creationPlace
<PAGE>
`,
'placesQuery': `
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
......
......@@ -2,7 +2,8 @@ import SparqlSearchEngine from './SparqlSearchEngine';
import datasetConfig from './Datasets';
import {
mapFacet,
mapCount
mapCount,
mapManuscripts
} from './Mappers';
import { makeObjectList } from './SparqlObjectMapper';
......@@ -10,14 +11,14 @@ const sparqlSearchEngine = new SparqlSearchEngine();
export const getManuscripts = (page, filterObj) => {
let { endpoint, manuscriptQuery } = datasetConfig['mmm'];
const pageSize = 3;
const pageSize = 5;
manuscriptQuery = datasetConfig['mmm'].manuscriptQuery2;
manuscriptQuery = manuscriptQuery.replace('<FILTER>', generateFilter(filterObj));
manuscriptQuery = manuscriptQuery.replace('<PAGE>', `LIMIT ${pageSize} OFFSET ${page * pageSize}`);
//manuscriptQuery = manuscriptQuery.replace('<ORDER_BY>', `ORDER BY (!BOUND(?orderBy)) ?orderBy`);
manuscriptQuery = manuscriptQuery.replace('<ORDER_BY>', `ORDER BY ?id`);
console.log(manuscriptQuery)
return sparqlSearchEngine.doSearch(manuscriptQuery, endpoint, makeObjectList);
//return sparqlSearchEngine.doSearch(manuscriptQuery, endpoint, makeObjectList);
return sparqlSearchEngine.doSearch(manuscriptQuery, endpoint, mapManuscripts);
};
export const getManuscriptCount = (filterObj) => {
......
......@@ -46,33 +46,47 @@ export const groupBy = (sparqlBindings, group) => Object.values(_.reduce(sparqlB
// };
export const mapManuscripts = (sparqlBindings) => {
//console.log(sparqlBindings);
console.log(sparqlBindings);
const results = sparqlBindings.map(b => {
return {
id: b.id.value,
manuscriptRecord: _.has(b, 'manuscriptRecord') ? b.manuscriptRecord.value : '-',
prefLabel: b.prefLabel.value.split('|'),
prefLabel: createStringList(b.prefLabel.value),
//entry: createStringList(b.entry.value),
manuscriptRecord: _.has(b, 'manuscriptRecord') ? createStringList(b.manuscriptRecord.value) : '-',
author: _.has(b, 'author',) ? createObjectList(b.author.value, 'names') : '-',
timespan: _.has(b, 'timespan',) ? b.timespan.value.split('|') : '-',
// owner: _.has(b, 'owner',) ? createObjectList(b.owner.value, 'names') : '-',
timespan: _.has(b, 'timespan',) ? createStringList(b.timespan.value) : '-',
creationPlace: _.has(b, 'creationPlace',) ? createObjectList(b.creationPlace.value, 'places') : '-',
material: _.has(b, 'material',) ? b.material.value.split('|') : '-',
language: _.has(b, 'language',) ? b.language.value.split('|') : '-',
material: _.has(b, 'material',) ? createStringList(b.material.value) : '-',
language: _.has(b, 'language',) ? createStringList(b.language.value) : '-',
};
});
return results;
};
const createStringList = (str) => {
const list = str.split('|');
return list.length < 2 ? list[0] : list;
};
const createObjectList = (str, sdbmType) => {
const strings = str.split('|');
return strings.map(s => {
const values = s.split(';');
return {
id: values[1].substring(values[1].lastIndexOf('/') + 1),
//id: values[0],
prefLabel: values[0],
sdbmType: sdbmType
};
});
const list = str.split('|');
if (list.length < 2) {
return createObject(list[0], sdbmType);
} else {
return list.map(item => {
return createObject(item, sdbmType);
});
}
};
const createObject = (str, sdbmType) => {
const values = str.split(';');
return {
id: values[1],
prefLabel: values[0],
sdbmLink: `https://sdbm.library.upenn.edu/${sdbmType}/${values[1].substring(values[1].lastIndexOf('/') + 1)}`
};
};
export const mapPlaces = (sparqlBindings) => {
......
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