ios - NSLinguisticTagger 在 Mac 和 iOS 上提供不同的输出

标签 ios macos cocoa-touch cocoa nlp

我尝试使用 NSLinguisticTagger 来隔离句子中的动词,但遇到了一个问题,即输出会有所不同,具体取决于代码是在 iOS 程序中运行还是在 MacOS 程序中运行。

我的代码如下:

NSString* text = @"The person is a 50 year old gentleman with a book who presents us with a conundrum.";
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames;
NSLinguisticTagger* tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:@[NSLinguisticTagSchemeNameTypeOrLexicalClass]
                                                                    options:options];
tagger.string = text;
[tagger enumerateTagsInRange:NSMakeRange(0, [tagger.string length])
                      scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass
                     options:options
                  usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
                      NSString *token = [text substringWithRange:tokenRange];
                      NSLog(@"%@: %@", token, tag);
                  }];

OSX 程序中运行此代码片段,我正确地得到以下输出(“presents” 被正确识别为动词):

[                    AppDelegate (0x101b0bcb0)]: The: Determiner
[                    AppDelegate (0x101b0bcb0)]: person: Noun
[                    AppDelegate (0x101b0bcb0)]: is: Verb
[                    AppDelegate (0x101b0bcb0)]: a: Determiner
[                    AppDelegate (0x101b0bcb0)]: 50: Number
[                    AppDelegate (0x101b0bcb0)]: year: Noun
[                    AppDelegate (0x101b0bcb0)]: old: Adjective
[                    AppDelegate (0x101b0bcb0)]: gentleman: Noun
[                    AppDelegate (0x101b0bcb0)]: with: Preposition
[                    AppDelegate (0x101b0bcb0)]: a: Determiner
[                    AppDelegate (0x101b0bcb0)]: book: Noun
[                    AppDelegate (0x101b0bcb0)]: who: Pronoun
[                    AppDelegate (0x101b0bcb0)]: presents: Verb
[                    AppDelegate (0x101b0bcb0)]: us: Pronoun
[                    AppDelegate (0x101b0bcb0)]: with: Preposition
[                    AppDelegate (0x101b0bcb0)]: a: Determiner
[                    AppDelegate (0x101b0bcb0)]: conundrum: Noun

但是,iOS 程序中的相同代码块会产生以下输出(“presents” 被错误地识别为名词):

[                      AppDelegate (0x8d2f000)]: The: Determiner
[                      AppDelegate (0x8d2f000)]: person: Noun
[                      AppDelegate (0x8d2f000)]: is: Verb
[                      AppDelegate (0x8d2f000)]: a: Determiner
[                      AppDelegate (0x8d2f000)]: 50: Number
[                      AppDelegate (0x8d2f000)]: year: Noun
[                      AppDelegate (0x8d2f000)]: old: Adjective
[                      AppDelegate (0x8d2f000)]: gentleman: Noun
[                      AppDelegate (0x8d2f000)]: with: Preposition
[                      AppDelegate (0x8d2f000)]: a: Determiner
[                      AppDelegate (0x8d2f000)]: book: Noun
[                      AppDelegate (0x8d2f000)]: who: Pronoun
[                      AppDelegate (0x8d2f000)]: presents: Noun
[                      AppDelegate (0x8d2f000)]: us: Pronoun
[                      AppDelegate (0x8d2f000)]: with: Preposition
[                      AppDelegate (0x8d2f000)]: a: Determiner
[                      AppDelegate (0x8d2f000)]: conundrum: Noun

有谁知道为什么我会得到不同的输出,以及如何正确地让 iOS 程序将 presents 识别为动词?

最佳答案

标记器是随机的,即它总是会出错。由于iOS设备资源有限,底层语言模型不如OS X版本精确。如果您想要更高的准确性,请使用基于规则的解析器。不过,您必须处理歧义问题。

关于ios - NSLinguisticTagger 在 Mac 和 iOS 上提供不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18573325/

相关文章:

ios - 如何摆脱 Xcode 中的 "Unknown type name ' __declspec'"错误

android - Mac 上的 Android 模拟器收到错误的纬度/经度

macos - 在 OSX 上安装 Ansible

iphone - 网页调用方法

iPhone 按钮图像

ios - UIWebView 以更有效的方式减少加载时间

ios - NSURL 扩展采用 StringLiteralConvertible

objective-c - coredata View Controller 上的错误

ios - 在 UIStoryboard 中使用 NIB

macos - 'atal : Reference has invalid format: 'refs/Icon