Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trend diagram subquery with repetition #342

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading