【问题标题】:Named Entity recognition relative date命名实体识别相对日期
【发布时间】:2020-01-29 17:52:57
【问题描述】:

我使用 spaCy 作为 NLP 库来检测命名实体。我想自动从文本中提取日期和时间参考。例如,捕获这句话中的日期:I will go to the show on 1/1/2020 并检测到 1/1/2020 是一个 DATE 命名实体。

但我也想了解相对时间短语,例如I will go to the show tomorrowtomorrow 被检测为 DATE 命名实体,但我不知道它指的是哪个时间 - 如果今天是 1/1/2020,那么明天是 1/2/2020。我想直接从命名实体中获取1/2/2020,即使它是相对的。

我尝试通过创建字典手动执行此操作,但命名实体的日期非常宽,我用静态字典错过了它们。

有没有办法从相对日期命名实体接收实际时间?

【问题讨论】:

标签: nlp spacy


【解决方案1】:

您可以尝试dateparser 库。 Link to Docs

pip install dateparser

例子:

from dateparser import parse
from dateparser.search import search_dates

print(parse('Tomorrow'))
print(parse('01/01/20'))
print(search_dates("I will go to the show tomorrow"))
print(search_dates("The client arrived to the office for the first time in March 3rd, 2004 and got serviced, after a couple of months, on May 6th 2004, the customer returned indicating a defect on the part"))

输出

2020-01-30 21:03:17.551187
2020-01-01 00:00:00
[('tomorrow', datetime.datetime(2020, 1, 30, 21, 6, 19, 545368))]
[('in March 3rd, 2004 and', datetime.datetime(2004, 3, 3, 0, 0)), 
 ('on May 6th 2004', datetime.datetime(2004, 5, 6, 0, 0))]

【讨论】:

  • 它工作得很好,但它错过了一些“持续时间”行“一天”-“我可以在一天内完成”
猜你喜欢
  • 2014-03-17
  • 2011-07-31
  • 2018-03-08
  • 2020-07-02
  • 2010-11-04
  • 2021-05-06
  • 2012-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多