I used the NSLinguisticTagger with sentences and ran into a strange problem with sentences like "I'm hungry" or "I'm drunk." Although one would expect the “I” to be marked as a pronoun, the “I” as a verb and the “hungry” as an adjective, this is not so. Most likely they are all marked as OtherWord .
Is there something I'm doing wrong?
NSString *input = @"I am hungry"; NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace; NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:[NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options]; tagger.string = input; [tagger enumerateTagsInRange:NSMakeRange(0, input.length) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { NSString *token = [input substringWithRange:tokenRange]; NSString *lemma = [tagger tagAtIndex:tokenRange.location scheme:NSLinguisticTagSchemeLemma tokenRange: NULL sentenceRange:NULL]; NSLog(@"%@ (%@) : %@\n", token, lemma, tag); }];
And the result:
I ((null)) : OtherWord am ((null)) : OtherWord hungry ((null)) : OtherWord
ios objective-c cocoa nlp linguistics
Joshua
source share