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

时间:2013-09-02 12:29:17

标签: 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 程序中运行此代码段,我正确地获得以下输出(&#34;礼物&#34; 被正确识别为动词):< / p>

[                    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 程序中的相同确切代码块会产生以下输出(&#34;礼物&#34; 被错误地识别为名词):

[                      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程序识别礼物作为动词?

1 个答案:

答案 0 :(得分:2)

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