仅从英语句子中提取日期部分 [英] Extract date part only from a english sentence

查看:84
本文介绍了仅从英语句子中提取日期部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅从英语句子中提取日期部分。

某些情况



19-02-是否有任何假期2012

是否有任何假期于19/02/2012

19.02.2012是否有任何假期

有没有假期于2012/02/19

是否有任何假期在02-19-2012

2017年2月19日是否有任何假期

2017年2月19日是否有任何假期

2017年2月19日是否有任何假期

是否有任何假期于19 / feb / 2017

2月19日是否有任何假期

2月19日是否有任何假期



对于这些预期的所有句子输出应为日期格式

日 - 19

月 - 02

年-2017




我尝试过:



我们使用 [ ^ ]



但不能涵盖所有情况。

解决方案

可能是有任何工具,但如果你想手动完成,你应该使用一些小步骤。



1.找到句子中的日期。

2.使句子的子串仅具有日期部分。

3.因为日期格式不同,您应该为不同的日期格式更改不同的查找条件。您可以按年份或月份名称查找,或者如果可能,只使用相同的日期格式。



字符串s1 =2012年2月19日是否有任何假期; 
int i = s1.IndexOf(Feb)
String date = s1.Substring(i-3,11);


我有一个类似的问题,并最终提出了一个正确的技巧。请参阅我的质量保证此处 [ ^ ](解决方案4做的伎俩) )

How to extract date part only from a English sentence.
Some scenario

Is there is any holiday on 19-02-2012
Is there is any holiday on 19/02/2012
Is there is any holiday on 19.02.2012
Is there is any holiday on 2012/02/19
Is there is any holiday on 02-19-2012
Is there is any holiday on 19th feb 2017
Is There is any holiday on 19th-feb-2017
Is There is any holiday on Feb 19 2017
Is There is any holiday on 19th/feb/2017
Is There is any holiday on 19 Feb
Is There is any holiday on Feb 19

For these all sentences expected output should be in Date format
Day - 19
Month - 02
Year -2017


What I have tried:

We used regular expressions of [^]

but not able to cover all cases.

解决方案

May be there any tool, but if you want to do it manually you should use some small steps.

1. find the date in sentence.
2. make substring of the sentence as having only date part.
3. because date are in different formats, you should change different find criteria for different date format. You can find by year or by month name or simply use the same date format if possible.

String s1 = "Is there is any holiday on 19-Feb-2012";
int i = s1.IndexOf("Feb")
String date = s1.Substring(i-3, 11);


I had a similar issue, and eventually came up with a Regex that did the trick. See my QA here[^] (Solution 4 does the trick)


这篇关于仅从英语句子中提取日期部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆