Skip to main content

ChineseDateTimeNLP

PyPI Python Version

License Code style: black Imports: isort

Downloads Downloads

简介

这是 Time-NLP 的 Python3 版本。
fork 自 Kelab/ChineseTimeNLP

相关链接:

配置

可以传入自定义的 pattern,默认 pattern 也可以通过 from ChineseDateTimeNLP import pattern 导入。

TimeNormalizer(isPreferFuture=True, pattern=None):

对于下午两点、晚上十点这样的词汇,在不特别指明的情况下,默认返回明天的时间点。

安装使用

安装:

pip install ChineseDateTimeNLP

使用:

from ChineseDateTimeNLP        import TimeNormalizer
tn = TimeNormalizer()
res = tn.parse(target=u"三天后")  # target 为待分析语句,baseTime 为基准时间默认是当前时间
print(res)

功能说明

用于句子中时间词的抽取和转换
详情请见 Test.py

tn = TimeNormalizer(isPreferFuture=False)

res = tn.parse(target=u'星期天晚上')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(target=u'晚上8点到上午10点之间')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(
    target=u'2013年二月二十八日下午四点三十分二十九秒',
    baseTime='2013-02-28 16:30:29')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(
    target=u'我需要大概33天2分钟四秒',
    baseTime='2013-02-28 16:30:29')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(target=u'今年儿童节晚上九点一刻')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(target=u'三日')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(target=u'7点4')  # target为待分析语句,baseTime为基准时间默认是当前时间
print(res)
print('====')

res = tn.parse(target=u'今年春分')
print(res)
print('====')

res = tn.parse(target=u'7000万')
print(res)
print('====')

res = tn.parse(target=u'7百')
print(res)
print('====')

res = tn.parse(target=u'7千')
print(res)
print('====')

结果:

目标字符串:  星期天晚上
基础时间 2019-7-28-15-47-27
temp ['星期7晚上']
{"type": "timestamp", "timestamp": "2019-07-28 20:00:00"}
====
目标字符串:  晚上8点到上午10点之间
基础时间 2019-7-28-15-47-27
temp ['晚上8点', '上午10点']
{"type": "timespan", "timespan": ["2019-07-28 20:00:00", "2019-07-28 10:00:00"]}
====
目标字符串:  2013年二月二十八日下午四点三十分二十九秒
基础时间 2013-2-28-16-30-29
temp ['2013年2月28日下午4点30分29秒']
{"type": "timestamp", "timestamp": "2013-02-28 16:30:29"}
====
目标字符串:  我需要大概33天2分钟四秒
基础时间 2013-2-28-16-30-29
temp ['33天2分钟4秒']
timedelta:  33 days, 0:02:04
{"type": "timedelta", "timedelta": {"year": 0, "month": 1, "day": 3, "hour": 0, "minute": 2, "second": 4}}
====
目标字符串:  今年儿童节晚上九点一刻
基础时间 2019-7-28-15-47-27
temp ['今年儿童节晚上9点1刻']
{"type": "timestamp", "timestamp": "2019-06-01 21:15:00"}
====
目标字符串:  三日
基础时间 2019-7-28-15-47-27
temp ['3日']
{"type": "timestamp", "timestamp": "2019-07-03 00:00:00"}
====
目标字符串:  7点4
基础时间 2019-7-28-15-47-27
temp ['7点4']
{"type": "timestamp", "timestamp": "2019-07-28 07:04:00"}
====
目标字符串:  今年春分
基础时间 2019-7-28-15-47-27
temp ['今年春分']
{"type": "timestamp", "timestamp": "2019-03-21 00:00:00"}
====
目标字符串:  7000万
基础时间 2019-7-28-15-47-27
temp ['70000000']
{"type": "error", "error": "no time pattern could be extracted."}
====
目标字符串:  7百
基础时间 2019-7-28-15-47-27
temp []
{"type": "error", "error": "no time pattern could be extracted."}
====
目标字符串:  7千
基础时间 2019-7-28-15-47-27
temp []
{"type": "error", "error": "no time pattern could be extracted."}
====

使用方式

见 Test.py

TODO

问题 现在版本 正确
晚上8点到上午10点之间 ["2018-03-16 20:00:00", "2018-03-16 22:00:00"] ["2018-03-16 20:00:00", "2018-03-17 10:00:00"]"

声明

  1. 增加了"礼拜xx"的识别
  2. 修复了"2023/10/09"识别错误的问题
  3. 修复了"2023-10-09"被识别为时间区间的问题
  4. 增加了"10/09"的识别
  5. 修复了"10-09"在系统时间是"2023-10-09"的时候,被推测为未来日期"2024-10-09"的问题
  6. 增加了"1009"的识别
  7. 优化对"下个月明天"这类相对日期的识别

Metadata

Release files for ChineseDateTimeNLP 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ChineseDateTimeNLP 1.0.5
File Size Uploaded
ChineseDateTimeNLP-1.0.5.tar.gz 23.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ChineseDateTimeNLP 1.0.5
File Interpreter ABI Platform
ChineseDateTimeNLP-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 50.9 kB

Release files / ChineseDateTimeNLP-1.0.5.tar.gz

Download URL ChineseDateTimeNLP-1.0.5.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
10e359aa168e69a805f99a0446746487ed6e8417b79f10cdf7f7e80fb1e461c0
BLAKE2b-256 checksum
How to use checksums
5c17145054aa35939f7b4aa65910f11330cf5903763f50531d1181ae76613c64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / ChineseDateTimeNLP-1.0.5-py3-none-any.whl

Download URL ChineseDateTimeNLP-1.0.5-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
155a113edf1ebf7a410ca8144008b955ca1aef834db8482caf5d7e5729f11cbd
BLAKE2b-256 checksum
How to use checksums
a88218953cafbf06dc9be6ee6eade821ba86c7de953087ece17a4c3ca6c46565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page