python中的syntime实现。
pysyntime的Python项目详细描述
pysyntime
pysyntime
是一个python库,它使用语法标记类型和一般的启发式规则实现了SynTime
算法。
功能
pysyntime
支持从原始文本中提取timex
(时间表达式)。例如,给定以下文本:
The last 6 months surviving member of the team which first conquered Everest in 6 a.m. 17 Jan 1953 has died in a Derbyshire nursing home.
pysyntime
将从文本中提取timex
,并以TimeML
格式生成以下带注释的文本:
<TIMEX3 tid="t1" type="DATE" value="2016-10-10">The last 6 months</TIMEX3> surviving member of the team which first conquered Everest in <TIMEX3 tid="t2" type="DATE" value="2016-10-10">6 a.m. 17 Jan 1953</TIMEX3> has died in a Derbyshire nursing home.
安装
您可以通过轻松运行pip
命令来安装软件包:
pip install pysyntime
由于pysyntime
依赖于作为nlp库的spaCy,因此需要下载所需的模型:
python -m spacy download en_core_web_sm
注意:上面的命令将下载spacy模型并创建符号链接,确保您具有根权限。 如果您使用的是python virtualenv,则不需要根权限。有关详细信息,请参见spaCy documentation。
用法
frompysyntimeimportSynTime# Instanciate SynTimesynTime=SynTime()# Your raw texttext='The last 6 months surviving member of the team which first conquered Everest in 6 a.m. 17 Jan 1953 has died in a Derbyshire nursing home.'date='2016-10-10'# Extract timex from raw texttimeMLText=synTime.extractTimexFromText(text,date)print(timeMLText)
参考文献
〔1〕萧世中、艾欣隼和Erik Cambria。基于句法标记类型和一般启发式规则的时间表达式分析与识别。《计算语言学协会第55届年会论文集》,420-4292017页。[pdf[slides]
[2]Syntime
在java中的实现。[github]