scrapinghub / scrapinghub/dateparser

Parse whole words only

Open
#856 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

search_dates Type: Enhancement
Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

Question/Bug

When using search_dates, it picks partial letters from neighboring words as well thus forming an invalid token and wrong datetime objects. For eg:

sample_string = 'Bubble -58.5 06 Mar 2009 in need of -43.4 30 Oct 1974 also contributed for -17.7 26 Dec 2018 '
en_dates = search_dates(sample_string, languages=['en'],settings={'STRICT_PARSING': True})
Output
[('5 06 Mar 2009 in', datetime.datetime(2009, 3, 5, 0, 0)),
 ('4 30 Oct 1974', datetime.datetime(1974, 10, 4, 0, 0)),
 ('7 26 Dec 2018', datetime.datetime(2018, 12, 7, 0, 0))]

It also picked

  1. letter 5 from -58.5 to 06 Mar 2009 forming '5 06 Mar 2009 in'
  2. letter 4 from -43.4 to 30 Oct 1974 forming '4 30 Oct 1974'
  3. letter 7 from -17.7 to 26 Dec 2018 forming '7 26 Dec 2018'

Either include the whole word or exclude it. Just including partial numbers/letters from previous words makes it an invalid token and wrong DateTime objects.

Expected Output
[('06 Mar 2009 in', datetime.datetime(2009, 3, 5, 0, 0)),
 ('30 Oct 1974', datetime.datetime(1974, 10, 4, 0, 0)),
 ('26 Dec 2018', datetime.datetime(2018, 12, 7, 0, 0))]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported example through the search_dates entry point and inspect how neighboring numeric characters are incorporated into candidate date tokens. Done means partial characters from adjacent words are excluded while the three expected date matches and datetime values are preserved; add a regression test for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.