From 5373cdcf98f6c5f836b81776d0e9eed246e72fe9 Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Tue, 20 Feb 2024 16:41:22 +0100 Subject: [PATCH 1/2] Constrain trend subquery to match, fix #288 --- CHANGELOG.md | 6 +++++- app/scripts/components/trend_diagram.js | 3 +-- app/scripts/trend_diagram/trend_util.js | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7909030..3ef224938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ - The "in order" option is inverted, so it is now "in free order" and unchecked by default (but still `in_order` in the URL query param and in the API) - The checkbox of said option no longer gets disabled in Extended mode -- Fixed parallel sentence alignment [#323](https://github.com/spraakbanken/korp-frontend/issues/323) + +### Fixed + +- Parallel sentence alignment [#323](https://github.com/spraakbanken/korp-frontend/issues/323) +- Trend diagram subquery with repetition [#288](https://github.com/spraakbanken/korp-frontend/issues/288) ### Removed diff --git a/app/scripts/components/trend_diagram.js b/app/scripts/components/trend_diagram.js index 9988beafd..e9ce6c235 100644 --- a/app/scripts/components/trend_diagram.js +++ b/app/scripts/components/trend_diagram.js @@ -109,8 +109,7 @@ export const trendDiagramComponent = { return } - const nTokens = $ctrl.data.cqp.split("]").length - 2 - const timecqp = trendUtil.getTimeCQP(time, zoom, nTokens, validZoomLevels.indexOf(zoom) < 3) + const timecqp = trendUtil.getTimeCQP(time, zoom, validZoomLevels.indexOf(zoom) < 3) const decodedCQP = decodeURIComponent(cqp) const opts = { ajaxParams: { diff --git a/app/scripts/trend_diagram/trend_util.js b/app/scripts/trend_diagram/trend_util.js index 540ad7ff0..2598c0cb4 100644 --- a/app/scripts/trend_diagram/trend_util.js +++ b/app/scripts/trend_diagram/trend_util.js @@ -1,5 +1,5 @@ /** @format */ -export function getTimeCQP(time, zoom, n_tokens, coarseGranularity) { +export function getTimeCQP(time, zoom, coarseGranularity) { let timecqp const m = moment(time * 1000) @@ -32,7 +32,7 @@ export function getTimeCQP(time, zoom, n_tokens, coarseGranularity) { ))]` } - timecqp = [timecqp].concat(_.map(_.range(0, n_tokens), () => "[]")).join(" ") + timecqp = ` ${timecqp} []* ` return timecqp } From e4650e28fbd68c97224e6398b7a2c5e527a674ff Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Tue, 20 Feb 2024 17:10:09 +0100 Subject: [PATCH 2/2] Drop whitespace in time cqp --- app/scripts/trend_diagram/trend_util.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/scripts/trend_diagram/trend_util.js b/app/scripts/trend_diagram/trend_util.js index 2598c0cb4..b2b8bffd7 100644 --- a/app/scripts/trend_diagram/trend_util.js +++ b/app/scripts/trend_diagram/trend_util.js @@ -13,23 +13,18 @@ export function getTimeCQP(time, zoom, coarseGranularity) { if (coarseGranularity) { // year, month, day - timecqp = `[(int(_.text_datefrom) >= ${datefrom} & int(_.text_dateto) <= ${dateto}) | - (int(_.text_datefrom) <= ${datefrom} & int(_.text_dateto) >= ${dateto}) - ]` + const dateInside = `(int(_.text_datefrom) >= ${datefrom} & int(_.text_dateto) <= ${dateto})` + const dateOutside = `(int(_.text_datefrom) <= ${datefrom} & int(_.text_dateto) >= ${dateto})` + timecqp = `[${dateInside} | ${dateOutside}]` } else { // hour, minute, second const timefrom = moment(m).startOf(zoom).format("HHmmss") const timeto = moment(m).endOf(zoom).format("HHmmss") - timecqp = `[(int(_.text_datefrom) = ${datefrom} & - int(_.text_timefrom) >= ${timefrom} & - int(_.text_dateto) <= ${dateto} & - int(_.text_timeto) <= ${timeto}) | - ((int(_.text_datefrom) < ${datefrom} | - (int(_.text_datefrom) = ${datefrom} & int(_.text_timefrom) <= ${timefrom}) - ) & - (int(_.text_dateto) > ${dateto} | - (int(_.text_dateto) = ${dateto} & int(_.text_timeto) >= ${timeto}) - ))]` + const startsSameDate = `(int(_.text_datefrom) = ${datefrom} & int(_.text_dateto) <= ${dateto})` + const timeInside = `(int(_.text_timefrom) >= ${timefrom} & int(_.text_timeto) <= ${timeto})` + const startsBefore = `(int(_.text_datefrom) < ${datefrom} | (int(_.text_datefrom) = ${datefrom} & int(_.text_timefrom) <= ${timefrom}))` + const endsAfter = `(int(_.text_dateto) > ${dateto} | (int(_.text_dateto) = ${dateto} & int(_.text_timeto) >= ${timeto}))` + timecqp = `[(${startsSameDate} & ${timeInside}) | (${startsBefore} & ${endsAfter})]` } timecqp = ` ${timecqp} []* `