Repository navigation
Add "ngram" search strategy to search_dates - #1351
Merged
Merged
Conversation
The new strategy tokenizes the text on characters that never occur inside a date expression and tries to parse token n-grams, longest first, so that the most complete date is found. Compared to the default translation-based "split" strategy it produces more predictable results on noisy real-world text. The strategy is exposed through the new "strategy" parameter of search_dates and defaults to the existing behavior.
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1351 +/- ##
==========================================
- Coverage 97.12% 97.07% -0.06%
==========================================
Files 235 236 +1
Lines 2924 2972 +48
==========================================
+ Hits 2840 2885 +45
- Misses 84 87 +3 β View full report in Codecov by Harness. π New features to boost your workflow:
|
Collaborator
Author
Implementation summaryThis PR adds an opt-in How the ngram strategy worksFor example, in
Changes
Verification
Usagefrom dateparser.search import search_dates
search_dates("Posted on 4 October 1957 by admin", strategy="ngram")
# [('4 October 1957', datetime.datetime(1957, 10, 4, 0, 0))] |
AdrianAtZyte
approved these changes
Jul 21, 2026
Merged
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The new strategy tokenizes the text on characters that never occur inside a date expression and tries to parse token n-grams, longest first, so that the most complete date is found. Compared to the default translation-based "split" strategy it produces more predictable results on noisy real-world text.
The strategy is exposed through the new "strategy" parameter of search_dates and defaults to the existing behavior.