我刚刚开始NSLinguisticTagger
在这个博客上使用我的代码:NSLinguisticTagger @ NSHipster.com
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames;
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes: [NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];
tagger.string = question;
[tagger enumerateTagsInRange:NSMakeRange(0, [question length]) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
NSString *token = [question substringWithRange:tokenRange];
NSLog(@"%@: %@", token, tag); }];
当我用 运行它时question = @"Weekend in New York"
,"New York"
会被标记为PlaceName
哪个很棒。但是当我用 运行它时question = @"Weekend in new york"
,"new"
被标记为"Adjective"
并被"york"
标记为PlaceName
。有没有办法解决这个问题,"New York"
并且"new york"
两者都被标记为PlaceName
?
我对这个语言学的东西完全陌生。