//1.创建语句
NSString * question = @"What is the weather in San Francisco?";
//2.创建筛选条件
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerJoinNames |NSLinguisticTaggerOmitPunctuation;
//3.创建自然语言标签
NSLinguisticTagger * tagger = [[NSLinguisticTagger alloc]initWithTagSchemes:[NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];
//4.给标签附字符串
tagger.string = question;
//5.执行筛选
[tagger enumerateTagsInRange:NSMakeRange(0, question.length) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSString * _Nonnull tag, NSRange tokenRange, NSRange sentenceRange, BOOL * _Nonnull stop) {
//6.获取结果
NSString *token = [question substringWithRange:tokenRange];
//7.打印结果
DLog(@"token---%@:tag---%@",token, tag);
}];
网友评论