diff --git a/src/client/components/EnhancedTable.js b/src/client/components/EnhancedTable.js index b758e4b9acb90c2fe1cf0fa397d4c9de4e3c8320..91dc19472390c4139b3188832999284bcd743d31 100644 --- a/src/client/components/EnhancedTable.js +++ b/src/client/components/EnhancedTable.js @@ -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> ); })} diff --git a/src/client/components/ResultTable.js b/src/client/components/ResultTable.js index f5ca7fc65259d5b60bdd2454e112ce9aea012849..c21b47910481100ba7692cbbe5359650063065d1 100644 --- a/src/client/components/ResultTable.js +++ b/src/client/components/ResultTable.js @@ -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(); } diff --git a/src/client/components/Tree.js b/src/client/components/Tree.js index 6a38b2f655f72f7cdcc4ea8cb97bfedcc3d09816..6b72fa45e6eb0735dabe9286f3e44f0dd0fa7651 100644 --- a/src/client/components/Tree.js +++ b/src/client/components/Tree.js @@ -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 }} diff --git a/src/server/sparql/Datasets.js b/src/server/sparql/Datasets.js index 3adfda33e13a5cfc4b426e205aba70f5e36e8aa7..62aa7ec0a577152b2d6c209a901ca1d59a0939b3 100644 --- a/src/server/sparql/Datasets.js +++ b/src/server/sparql/Datasets.js @@ -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': { diff --git a/src/server/sparql/Manuscripts.js b/src/server/sparql/Manuscripts.js index d5f78b5e3a00939d5b3ed9edffbb106a10854326..e8cbcb540254ed26fe88f694feb5f0ab85ff81f8 100644 --- a/src/server/sparql/Manuscripts.js +++ b/src/server/sparql/Manuscripts.js @@ -1,7 +1,6 @@ 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; diff --git a/src/server/sparql/Mappers.js b/src/server/sparql/Mappers.js index 526416c4180233189d2860b2232e0b21cc576659..413af776f2af024773053ea65f45f6bd38127c5e 100644 --- a/src/server/sparql/Mappers.js +++ b/src/server/sparql/Mappers.js @@ -1,5 +1,6 @@ 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 => {