gpt4 book ai didi

python - 从文本语料库中提取日期和与日期相关的事件

转载 作者:太空狗 更新时间:2023-10-30 00:49:47 28 4
gpt4 key购买 nike

我目前正在运行一个 python 代码,该代码遍历文本文件的每一行并解析该行的日期。如果它确实在该行中找到了日期,则将该行复制到一个新的输出文件中。我在 100 个文档上重复这个过程,最后,我得到一个输出文件,其中包含日期为“2013 年、2014 年 8 月、01-11-1987 等等”的行。

问题在于,它没有提供与某些日期相关的事件的准确信息。

有没有更优雅的方法来解决这个问题?下面是我试图提取 2010 年 12 月日期的事件的文件

Taipei is the most competitive place among all major cities andcounties, according to a study published by a local magazineyesterday. Taipei came in first in each of the categories - economy,employment, education, environmental protection, public safety,medical care and local finances - evaluated in the study by GlobalView Magazine. In terms of overall competitiveness, Taipei istherefore number one, followed by Hsinchu City, Chiayi City and NewTaipei. Taipei, with more than six decades of privileged developmentheavily funded by the central government, will remain unchallenged inthe foreseeable future, Global View commented. Taipei and New Taipeiare two of the country's five Cabinet-level special municipalities,but the other three - Taichung, Tainan and Kaohsiung - failed toreceive good ratings in the study though they have more resources thanmost other local governments. Taichung ranks seventh, Tainan 12th andKaohsiung 15th of all 19 local governments graded in the study. Thethree special municipalities grew to the present size by mergingneighboring counties in December 2010. But Global View said themergers crippled their competitiveness. But all five specialmunicipalities are in the top-10 in terms of economic competitiveness.At the bottom is the agricultural Pingtung County. But anotheragricultural county, Taitung, made it to the top-10, occupying theeighth place mainly because of its low crime rate, the magazine said.

如您所见,当我解析包含 2010 年 12 月的行时,我并没有真正获得任何有意义的信息但实际上,有一件大事就是邻县合并。这没有被捕获。因此,我需要知道是否有任何算法/库可以帮助我捕获在特定日期发生的事件。

最佳答案

我建议您试用 Python 的 NLTK 库。你可以在这里得到它,这里还有一些基本手册: http://www.nltk.org/book/ch07.html

它有大量用于从文本中提取含义的算法。它还具有一些模块,允许您:

1) 提取实体2)提取日期3) 建立抽取实体与日期的关系。

建议关注NLTK库中的timex.py模块: https://github.com/nltk/nltk_contrib/blob/master/nltk_contrib/timex.py

它主要用于标记文本中的日期和时间。

这是提取实体关系的指南: http://www.nltk.org/howto/relextract.html

所以我相信您可以从您的文本中提取有趣的实体(比如您提到的事件),您可以提取日期作为另一组实体,并且使用 NLTK 可以在这些提取的实体之间建立关系。因此,您应该得到所需的东西 - 什么时候发生的事情。

关于python - 从文本语料库中提取日期和与日期相关的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28437945/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com