我正在寻找一种从用户输入中提取日期的解决方案。它应该支持:
- 英语以外的其他语言
- 应该用 C/ObjC/C++/Python/Perl/Ruby 编写
- 目标平台是 Mac OS X 10.6+
- 它不需要互联网连接
欢迎付费解决方案以及开源(非 GPL)。
最佳答案
苹果包括NSDataDetector在10.7中。
除了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);
}
关于macos - Mac OS X 中用于自然文本处理的框架、库或工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8769949/