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

[feat] merge relative date refiner #430

Merged
merged 3 commits into from
Feb 13, 2022

Conversation

liamcain
Copy link
Contributor

@liamcain liamcain commented Feb 4, 2022

Summary

Adds support for more complex composite dates.

  • 2 weeks before 2020-02-13
  • 2 days after next Friday

Verified

This commit was signed with the committer’s verified signature.
bdraco J. Nick Koston
@wanasit
Copy link
Owner

wanasit commented Feb 6, 2022

Hey @liamcain. Thank you for your work!
Could you please check my comment and tweak your change a bit?

@liamcain
Copy link
Contributor Author

liamcain commented Feb 8, 2022

Hi @wanasit, is there a review you forgot to submit? I don't see the comment you're referring to. Also just noticed that I had prettier changes unstaged, so I just pushed a fix for that.


shouldMergeResults(textBetween: string, currentResult: ParsingResult, nextResult: ParsingResult): boolean {
return (
textBetween.match(this.patternBetween()) != null &&
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is difficult to understand. Could we break this into multiple if-return-false? e.g.

if (<not match>) {
  return false;
}

if (<not time ago>) {
  return false;
}


...
return true;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, this was confusing for me to read just a few days after having written it. Improved the code style here and added some more context to make it easier follow.

* - 2 weeks before 2020-02-13
* - 2 days after next Friday
*/
export default class ENMergeDateRelativeRefiner extends MergingRefiner {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think ENMergeRelativeDateRefiner is more accurate and consistent with the other merge refiners

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to your suggest. I was also thinking ENMergeImpliedReferenceDateRefiner might be more accurate, lmk what you think.

const PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i");
const STRICT_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i");
export const PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i");
export const STRICT_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export both strict and normal? could you export only the one we need?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted. I mostly did this out of laziness, but I agree that having more precise pattern matching here is better.

@wanasit
Copy link
Owner

wanasit commented Feb 9, 2022

I don't see the comment you're referring to. Also just noticed that I had prettier changes unstaged, so I just pushed a fix for that.

Ops. Sorry, I'm actually not very used to CR through Github ^^;

@liamcain
Copy link
Contributor Author

@wanasit Thanks for the review! I addressed all your comments

@wanasit wanasit merged commit f79afcf into wanasit:master Feb 13, 2022
@liamcain liamcain deleted the feat/merge-relative-refiner branch December 1, 2023 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants