2
我正在寻找解决方案来从用户输入中提取日期。它应该支持:在Mac OS X中用于自然文本处理的框架,库或工具
- 其他非英语
- 它应该用C编写/ ObjC/C++/Python的/的Perl/Ruby的
- 目标平台的Mac OS X 10.6+
- 它必须不需要互联网连接
付费解决方案也欢迎以及开源(非GPL)。
我正在寻找解决方案来从用户输入中提取日期。它应该支持:在Mac OS X中用于自然文本处理的框架,库或工具
付费解决方案也欢迎以及开源(非GPL)。
苹果在10.7中包括NSDataDetector。
除了URL,电话号码等,它还支持日期(NSTextCheckingTypeDate)检测。 (似乎Mail.app广泛使用的探测器)
这个例子检测“串”的所有日期和记录比赛(如果有的话)的位置&长度:
NSError* error = NULL;
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:&error];
NSArray* matches = [detector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult* match in matches)
{
NSRange matchRange = [match range];
NSLog(@"Match at position:%lu with length:%lu", matchRange.location, matchRange.length);
}
很好的回答(和+ 1),但是Kentzo也在寻找一个运行在10.6以下的解决方案。 – 2012-01-07 13:52:38
谢谢,错过了。但我仍然需要在10.6中提取日期,是否有更天真的解决方案(例如基于NSScanner或NSDateFormatter)? – Kentzo 2012-01-07 14:15:54