macos - Mac OS X 中用于自然文本处理的框架、库或工具

标签 macos cocoa text-processing text-parsing

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

  • 英语以外的其他语言
  • 应该用 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/

相关文章:

objective-c - 根据 AppleScript,Cocoa 应用程序不包含菜单栏

macos - 如何使用 XCTest 对基于文档的应用程序进行 UI 测试?

python - 在 python/bash 中打印带有条件的特定范围的行

python - 我的歌词机器人不向服务器发送字符串

linux - 在 Linux 中将相关数据行分组到单个列中

java - 使用Intellij时在macOS基座上隐藏Gradle守护程序的Java图标?

macos - Applescript:执行上下文菜单操作

objective-c - Xcode Interface Builder 设置按钮的突出显示图像

c++ - sqlite c++ 体系结构 x86_64 的 undefined symbol

cocoa - 使用 @avg 集合运算符格式化 NSPredicate 的字符串