用于在Mac OS X中进行自然文本处理的框架,库或工具

时间:2012-01-07 13:12:48

标签: macos cocoa text-processing text-parsing

我正在寻找一种从用户输入中提取日期的解决方案。它应该支持:

  • 除英语以外的其他语言
  • 它应该用C / ObjC / C ++ / Python / Perl / Ruby
  • 编写
  • 目标平台是Mac OS X 10.6 +
  • 不得要求互联网连接

欢迎付费解决方案以及开源(非GPL)。

1 个答案:

答案 0 :(得分:2)

Apple在10.7中包括NSDataDetector 除了URL,电话号码等,它还支持日期(NSTextCheckingTypeDate)检测。 (似乎Mail.app广泛使用这些探测器)

此示例检测“string”中的所有日期,并记录匹配(如果有)位置和&长度:

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);
}