Skip to content
Snippets Groups Projects
Commit 5b9466bc authored by esikkala's avatar esikkala
Browse files

Use sparql object mapper with facet queries, show source in hierarchical facet

parent fb9c8247
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ function getSorting(order, orderBy) {
const rows = [
{ id: 'title', numeric: false, disablePadding: true, label: 'Name' },
{ id: 'count', numeric: true, disablePadding: false, label: 'Count' },
{ id: 'count', numeric: true, disablePadding: false, label: 'Manuscript count' },
];
class EnhancedTableHead extends React.Component {
......@@ -171,10 +171,10 @@ EnhancedTableToolbar.propTypes = {
EnhancedTableToolbar = withStyles(toolbarStyles)(EnhancedTableToolbar);
const styles = theme => ({
const styles = () => ({
root: {
width: '100%',
marginTop: theme.spacing.unit * 3,
//marginTop: theme.spacing.unit * 3,
},
table: {
minWidth: 1020,
......@@ -248,7 +248,7 @@ class EnhancedTable extends React.Component {
const { classes } = this.props;
const { data, order, orderBy, selected, rowsPerPage, page } = this.state;
const emptyRows = rowsPerPage - Math.min(rowsPerPage, data.length - page * rowsPerPage);
console.log(data)
// console.log(data)
return (
<Paper className={classes.root}>
......@@ -282,9 +282,9 @@ class EnhancedTable extends React.Component {
<Checkbox checked={isSelected} />
</TableCell>
<TableCell component="th" scope="row" padding="none">
{n.title}
{n.prefLabel}
</TableCell>
<TableCell numeric>{n.cnt}</TableCell>
<TableCell numeric>{n.instanceCount}</TableCell>
</TableRow>
);
})}
......
......@@ -82,7 +82,7 @@ class ResultTable extends React.Component {
});
}
if (prevProps.facetFilters != this.props.facetFilters) {
// console.log('filters updated')
console.log('filters updated')
this.props.updatePage(0);
this.props.fetchManuscripts();
}
......
......@@ -32,7 +32,7 @@ const columns = [
label: 'Author',
property: 'author',
desc: 'Author description',
filter: true
//filter: true
},
{
label: 'Production place',
......
......@@ -168,7 +168,7 @@ class Tree extends Component {
color="primary"
/>
}
label={`${n.node.title} (${n.node.totalCnt == 0 ? n.node.cnt : n.node.totalCnt})`}
label={`${n.node.prefLabel} (source: ${n.node.source.substring(n.node.source.lastIndexOf('/') + 1)}, ms count: ${n.node.totalInstanceCount == 0 ? n.node.instanceCount : n.node.totalInstanceCount})`}
classes={{
root: classes.formControlRoot
}}
......
......@@ -14,8 +14,8 @@ module.exports = {
'title': 'MMM',
'shortTitle': 'MMM',
//'timePeriod': '',
'endpoint': 'http://ldf.fi/mmm-cidoc/sparql',
//'endpoint': 'http://localhost:3050/ds/sparql',
//'endpoint': 'http://ldf.fi/mmm-cidoc/sparql',
'endpoint': 'http://localhost:3050/ds/sparql',
'countQuery': `
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
......@@ -57,9 +57,10 @@ module.exports = {
?id a frbroo:F4_Manifestation_Singleton .
# ?id dct:source mmm-schema:Bodley .
# ?id dct:source mmm-schema:SDBM .
?id (^frbroo:R18_created|^crm:P108_has_produced)/crm:P7_took_place_at/skos:prefLabel ?orderBy .
# ?id (^frbroo:R18_created|^crm:P108_has_produced)/crm:P7_took_place_at/skos:prefLabel ?orderBy .
}
ORDER BY (!BOUND(?orderBy)) ?orderBy
#ORDER BY (!BOUND(?orderBy)) ?orderBy
ORDER BY ?id
<PAGE>
}
FILTER(BOUND(?id))
......@@ -239,24 +240,25 @@ module.exports = {
PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
PREFIX frbroo: <http://erlangen-crm.org/efrbroo/>
PREFIX mmm-schema: <http://ldf.fi/mmm/schema/>
SELECT DISTINCT ?cnt ?facet_text ?value ?parent
WHERE {
SELECT DISTINCT ?cnt ?value ?facet_text ?parent {
{ SELECT DISTINCT (count(DISTINCT ?id) as ?cnt) ?value ?parent
{
?id a frbroo:F4_Manifestation_Singleton .
<FILTER>
?id <PREDICATE> ?value .
OPTIONAL { ?value crm:P89_falls_within ?parent }
#?value dct:source mmm-schema:Bodley .
}
GROUP BY ?value ?parent
ORDER BY DESC(?cnt)
SELECT DISTINCT ?id ?prefLabel ?source ?parent ?instanceCount {
{ SELECT DISTINCT (count(DISTINCT ?instance) as ?instanceCount) ?id ?parent ?source
{
?instance a frbroo:F4_Manifestation_Singleton .
<FILTER>
#?value dct:source mmm-schema:Bodley .
?instance <PREDICATE> ?id .
?id dct:source ?source .
OPTIONAL { ?id crm:P89_falls_within ?parent_ }
BIND(COALESCE(?parent_, '0') as ?parent)
}
FILTER(BOUND(?value))
?value skos:prefLabel ?facet_text_
BIND(STR(?facet_text_) AS ?facet_text)
GROUP BY ?id ?source ?parent
ORDER BY DESC(?instanceCount)
}
FILTER(BOUND(?id))
#<SELECTED_VALUES>
#VALUES ?selectedValues { <http://ldf.fi/mmm/place/926> }
?id skos:prefLabel ?prefLabel_
BIND(STR(?prefLabel_) AS ?prefLabel)
}
`,
'tgn': {
......
import SparqlSearchEngine from './SparqlSearchEngine';
import datasetConfig from './Datasets';
import {
mapFacet,
mapHierarchicalFacet,
mapCount,
} from './Mappers';
......@@ -13,7 +12,8 @@ const facetConfigs = {
productionPlace: {
id: 'productionPlace',
label: 'Production place',
predicate: '(^frbroo:R18_created|^crm:P108_has_produced)/crm:P7_took_place_at',
predicate: '^frbroo:R18_created/crm:P7_took_place_at',
//predicate: '(^frbroo:R18_created|^crm:P108_has_produced)/crm:P7_took_place_at',
hierarchical: true,
},
author: {
......@@ -87,14 +87,15 @@ export const getFacets = filters => {
const getFacet = (facetConfig, filters) => {
let { endpoint, facetQuery } = datasetConfig['mmm'];
//console.log(filters)
if (filters == null) {
facetQuery = facetQuery.replace('<FILTER>', '');
} else {
facetQuery = facetQuery.replace('<FILTER>', generateFacetFilter(facetConfig, filters));
}
facetQuery = facetQuery.replace('<PREDICATE>', facetConfig.predicate);
// console.log(facetQuery)
let mapper = facetConfig.hierarchical ? mapHierarchicalFacet : mapFacet;
//console.log(facetQuery)
let mapper = facetConfig.hierarchical ? mapHierarchicalFacet : makeObjectList;
return sparqlSearchEngine.doSearch(facetQuery, endpoint, mapper);
};
......@@ -103,10 +104,11 @@ const generateFacetFilter = (facetConfig, filters) => {
let filterStr = '';
for (let property in filters) {
filterStr += `
?id ${facetConfigs[property].predicate} ?${property}Filter
VALUES ?${property}Filter { <${filters[property].join('> <')}> }
`;
?id ${facetConfigs[property].predicate} ?${property}Filter .
`;
}
// console.log(filterStr)
return filterStr;
};
......@@ -115,9 +117,9 @@ const generateResultFilter = filters => {
let filterStr = '';
for (let property in filters) {
filterStr += `
?id ${facetConfigs[property].predicate} ?${property}Filter
VALUES ?${property}Filter { <${filters[property].join('> <')}> }
`;
?id ${facetConfigs[property].predicate} ?${property}Filter .
`;
}
//console.log(filterStr)
return filterStr;
......
import _ from 'lodash';
import { getTreeFromFlatData } from 'react-sortable-tree';
import { makeObjectList } from './SparqlObjectMapper';
export const mapPlaces = (sparqlBindings) => {
//console.log(sparqlBindings);
......@@ -23,28 +24,8 @@ export const mapCount = (sparqlBindings) => {
};
};
export const mapFacet = sparqlBindings => {
const results = sparqlBindings.map(b => {
return {
title: b.facet_text.value,
id: _.has(b, 'value',) ? b.value.value : 'no_selection',
cnt: b.cnt.value,
selected: false
};
});
return results;
};
export const mapHierarchicalFacet = sparqlBindings => {
const results = sparqlBindings.map(b => {
return {
title: b.facet_text.value,
id: _.has(b, 'value',) ? b.value.value : 'no_selection',
cnt: b.cnt.value,
parent: _.has(b, 'parent',) ? b.parent.value : '0',
selected: false
};
});
const results = makeObjectList(sparqlBindings);
let treeData = getTreeFromFlatData({
flatData: results,
getKey: node => node.id, // resolve a node's key
......@@ -56,16 +37,16 @@ export const mapHierarchicalFacet = sparqlBindings => {
return treeData;
};
const comparator = (a, b) => a.title.localeCompare(b.title);
const comparator = (a, b) => a.prefLabel.localeCompare(b.prefLabel);
const sumUp = node => {
node.totalCnt = parseInt(node.cnt);
node.totalInstanceCount = parseInt(node.instanceCount);
if (_.has(node, 'children')) {
for (let child of node.children) {
node.totalCnt += sumUp(child);
node.totalInstanceCount += sumUp(child);
}
}
return node.totalCnt;
return node.totalInstanceCount;
};
const recursiveSort = nodes => {
......
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