本文介绍了NSLinguisticTagger enumerateTagsInRange不适用于具有NSLinguisticTagSchemeNameTypeOrLexicalClass的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我正在使用的代码,无论我在设备上使用什么句子,它都不会打印任何内容。在模拟器上它工作正常!
Here's the code I'm using, it prints nothing no matter what sentence I use on the device. On simulator it works fine!
- (NSMutableArray *)getTagEntries:(NSString *)sentence {
NSArray<NSLinguisticTagScheme> *tagSchemes = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"];
NSLinguisticTaggerOptions options = NSLinguisticTaggerJoinNames | NSLinguisticTaggerOmitWhitespace;
NSLinguisticTagger *linguisticTagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagSchemes options:options];
linguisticTagger.string = sentence;
__block NSMutableArray *tagEntries = [@[] mutableCopy];
[linguisticTagger enumerateTagsInRange:NSMakeRange(0, sentence.length) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSLinguisticTag tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
NSString *token = [sentence substringWithRange:tokenRange];
NSLog(@"%@ -> %@", token, tag);
[tagEntries addObject:@{@"token":token, @"tag":tag}];
}];
return tagEntries;
}
当我尝试在iPhone上打印出可用的方案时,Lexical不是一个选项。怎么来的??
When I try to print out the available schemes on my iPhone, Lexical is not an option. How come!?
NSArray<NSLinguisticTagScheme> *availSchemes = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"];
for (NSLinguisticTagScheme scheme in availSchemes) {
NSLog(@"Tag scheme %@", scheme);
}
// output:
// Tag scheme Language
// Tag scheme Script
// Tag scheme TokenType
在iOS 11上使用iPhone 6+。
Using iPhone 6+ with iOS 11.
推荐答案
Unfortunately, the answer was changing devices. My iPhone X does not have this issue. It may be due to having a dedicated ML chip that the 6s and newer phones have.
这篇关于NSLinguisticTagger enumerateTagsInRange不适用于具有NSLinguisticTagSchemeNameTypeOrLexicalClass的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!