Skip to content

Commit

Permalink
Merge pull request #342 from spraakbanken/trend-kwic-288
Browse files Browse the repository at this point in the history
Fix trend diagram subquery with repetition
  • Loading branch information
arildm authored Feb 20, 2024
2 parents cc88ef2 + e4650e2 commit 800fbba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions app/scripts/components/trend_diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
25 changes: 10 additions & 15 deletions app/scripts/trend_diagram/trend_util.js
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -13,26 +13,21 @@ export function getTimeCQP(time, zoom, n_tokens, 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].concat(_.map(_.range(0, n_tokens), () => "[]")).join(" ")
timecqp = `<match> ${timecqp} []* </match>`
return timecqp
}

Expand Down

0 comments on commit 800fbba

Please sign in to comment.