A tool for extracting datetime intervals from Hungarian sentences and turning datetime objects into Hungarian text.
Project description
Hungarian Date Parser
A tool for extracting datetime intervals from Hungarian sentences and turning datetime objects into Hungarian text.
Install and try the package with pip install hun-date-parser
Usage
If not specified otherwise, relative dates (eg.: tomorrow, next week, etc.) are calculated relative to the current datetime, at the time when the function is called. The now
parameter can be used for parsing relative datetimes relative to any timestamp other than the current time.
from hun_date_parser import text2datetime
from datetime import datetime
text2datetime('találkozzunk jövő kedd délután!', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2020, 12, 29, 17, 59, 59)}]
text2datetime('találkozzunk jövő héten szombaton háromnegyed nyolc előtt két perccel', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 2, 7, 43, 59)}]
text2datetime('találkozzunk jövő héten szombaton este háromnegyed nyolc előtt két perccel', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 2, 19, 43, 59)}]
The date parser is also capable of parsing explicit intervals from the text even when only one side of the interval is specified.
from hun_date_parser import text2datetime
from datetime import datetime
text2datetime('2020 decemberétől 2021 januárig', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 31, 23, 59, 59)}]
text2datetime('2021 januárig', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 31, 23, 59, 59)}]
The library is also capable of turning datetime objects into their Hungarian text representation.
from hun_date_parser import datetime2text
from datetime import datetime
datetime2text(datetime(2020, 12, 20, 18, 34), now=datetime(2020, 12, 27), time_precision=2)
# {'dates': ['múlt héten vasárnap', '2020 december 20'],
# 'times'34', 'este hat óra harmincnégy perc', 'este fél 7 után 4 perccel']}
License
This project is licensed under MIT license. Feel free to use it in your own projects.
Contribute
Any help or feedback in further developing the library is welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hun_date_parser-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3543194a1c540d1fa74a7d0d30bc366c79bd2fca9a3b553dbb2816d6acf08fc |
|
MD5 | c8883d5701083d8e982b2a7b8fd0530e |
|
BLAKE2b-256 | 37537c7daa085aa39c502a5edfc8b043f3080956733968210ba93a3dd0e35664 |