From 84962a203e51e798bb5c6db8cc0f83e8011de232 Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Wed, 19 Jun 2019 16:50:41 +0300
Subject: [PATCH] Actors: add birth date facet

---
 src/client/reducers/actors.js             |  2 +-
 src/client/reducers/actorsFacets.js       | 22 +++++++++++++++++-
 src/server/sparql/FacetConfigs.js         | 28 +++++++++++++++++++++++
 src/server/sparql/FacetValues.js          |  4 ++--
 src/server/sparql/Filters.js              |  4 ++--
 src/server/sparql/SparqlQueriesGeneral.js |  2 ++
 6 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/src/client/reducers/actors.js b/src/client/reducers/actors.js
index a344b1d5..eada9a15 100644
--- a/src/client/reducers/actors.js
+++ b/src/client/reducers/actors.js
@@ -77,7 +77,7 @@ export const INITIAL_STATE = {
       makeLink: false,
       sortValues: true,
       numberedList: false,
-      minWidth: 200
+      minWidth: 220
     },
     {
       id: 'deathDateTimespan',
diff --git a/src/client/reducers/actorsFacets.js b/src/client/reducers/actorsFacets.js
index 608719d2..b6419470 100644
--- a/src/client/reducers/actorsFacets.js
+++ b/src/client/reducers/actorsFacets.js
@@ -51,9 +51,29 @@ export const INITIAL_STATE = {
       uriFilter: null,
       spatialFilter: null
     },
+    birthDateTimespan: {
+      id: 'birthDateTimespan',
+      label: 'Date of birth/formation',
+      //predicate: defined in backend
+      distinctValueCount: 0,
+      values: [],
+      flatValues: [],
+      sortBy: null,
+      sortDirection: null,
+      sortButton: false,
+      spatialFilterButton: false,
+      isFetching: false,
+      searchField: false,
+      containerClass: 'three',
+      filterType: 'timespanFilter',
+      min: null,
+      max: null,
+      timespanFilter: null,
+      type: 'timespan'
+    },
     birthPlace: {
       id: 'birthPlace',
-      label: 'Place of birth',
+      label: 'Place of birth/formation',
       // predicate: defined in backend
       distinctValueCount: 0,
       values: [],
diff --git a/src/server/sparql/FacetConfigs.js b/src/server/sparql/FacetConfigs.js
index 175c4341..09549c24 100644
--- a/src/server/sparql/FacetConfigs.js
+++ b/src/server/sparql/FacetConfigs.js
@@ -158,6 +158,34 @@ export const facetConfigs = {
       predicate: 'dct:source',
       type: 'list',
     },
+    birthDateTimespan: {
+      id: 'birthDateTimespan',
+      facetValueFilter: `
+       FILTER(?timespan NOT IN (
+         <http://ldf.fi/mmm/actor/sdbm_39923_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_2814_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_4391_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_45865_birth_timespan>,
+         <http://ldf.fi/mmm/time/bibale_element_876634-269>,
+         <http://ldf.fi/mmm/time/bibale_element_876940-269>,
+         <http://ldf.fi/mmm/time/bibale_element_877018-269>,
+         <http://ldf.fi/mmm/time/bibale_element_876634-269>,
+         <http://ldf.fi/mmm/time/bibale_element_877167-269>,
+         <http://ldf.fi/mmm/time/bibale_element_877167-269>,
+         <http://ldf.fi/mmm/time/bibale_element_882490-269>,
+         <http://ldf.fi/mmm/actor/sdbm_44872_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_45182_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_40695_birth_timespan>,
+         <http://ldf.fi/mmm/actor/sdbm_44762_birth_timespan>
+       ))
+      `,
+      sortByAscPredicate: 'crm:P98i_was_born/crm:P4_has_time-span/crm:P82a_begin_of_the_begin',
+      sortByDescPredicate: 'crm:P98i_was_born/crm:P4_has_time-span/crm:P82b_end_of_the_end',
+      predicate: 'crm:P98i_was_born/crm:P4_has_time-span',
+      startProperty: 'crm:P82a_begin_of_the_begin',
+      endProperty: 'crm:P82b_end_of_the_end',
+      type: 'timespan',
+    },
     birthPlace: {
       id: 'birthPlace',
       facetValueFilter: `
diff --git a/src/server/sparql/FacetValues.js b/src/server/sparql/FacetValues.js
index cea5e221..57c7235b 100644
--- a/src/server/sparql/FacetValues.js
+++ b/src/server/sparql/FacetValues.js
@@ -104,7 +104,7 @@ export const getFacet = ({
   }
   q = q.replace('<SELECTED_VALUES>', selectedBlock);
   q = q.replace('<SELECTED_VALUES_NO_HITS>', selectedNoHitsBlock);
-  q = q.replace('<FACET_VALUE_FILTER>', facetConfig.facetValueFilter);
+  q = q.replace(/<FACET_VALUE_FILTER>/g, facetConfig.facetValueFilter);
   q = q.replace('<PARENTS>', parentBlock);
   if (facetConfig.type === 'list') {
     q = q.replace('<ORDER_BY>', `ORDER BY ${sortDirection}(?${sortBy})` );
@@ -118,7 +118,7 @@ export const getFacet = ({
     q = q.replace('<START_PROPERTY>', facetConfig.startProperty);
     q = q.replace('<END_PROPERTY>', facetConfig.endProperty);
   }
-  // if (facetID == 'productionPlace') {
+  // if (facetID == 'birthDateTimespan') {
   //   console.log(prefixes + q)
   // }
   return runSelectQuery(prefixes + q, endpoint, mapper);
diff --git a/src/server/sparql/Filters.js b/src/server/sparql/Filters.js
index 0fcb2ae4..b6e2a373 100644
--- a/src/server/sparql/Filters.js
+++ b/src/server/sparql/Filters.js
@@ -56,7 +56,7 @@ export const generateFilter = ({
         //   ?${filterTarget} ${facetConfig.predicate} ?timespan .
         //   ?timespan ${facetConfig.startProperty} ?start .
         //   ?timespan ${facetConfig.endProperty} ?end .
-        //   # both start and end is included in selected range
+        //   # both start and end is in selected range
         //   FILTER(?start >= "${start}"^^xsd:date)
         //   FILTER(?end <= "${end}"^^xsd:date)
         // `;
@@ -64,7 +64,7 @@ export const generateFilter = ({
           ?${filterTarget} ${facetConfig.predicate} ?timespan .
           ?timespan ${facetConfig.startProperty} ?timespanStart .
           ?timespan ${facetConfig.endProperty} ?timespanEnd .
-          # either start or end is included in the selected range
+          # either start or end is in selected range
           FILTER(
             ?timespanStart >= "${selectionStart}"^^xsd:date && ?timespanStart <= "${selectionEnd}"^^xsd:date
             ||
diff --git a/src/server/sparql/SparqlQueriesGeneral.js b/src/server/sparql/SparqlQueriesGeneral.js
index a673dacc..6b3af93f 100644
--- a/src/server/sparql/SparqlQueriesGeneral.js
+++ b/src/server/sparql/SparqlQueriesGeneral.js
@@ -106,6 +106,7 @@ export const facetValuesQueryTimespan = `
         VALUES ?facetClass { <FACET_CLASS> }
         ?instance a ?facetClass .
         ?timespan <START_PROPERTY> ?start .
+        <FACET_VALUE_FILTER>
       }
     }
     {
@@ -114,6 +115,7 @@ export const facetValuesQueryTimespan = `
         VALUES ?facetClass { <FACET_CLASS> }
         ?instance a ?facetClass .
         ?timespan <END_PROPERTY> ?end .
+        <FACET_VALUE_FILTER>
       }
     }
   }
-- 
GitLab