简体   繁体   English

NSLinguisticTagger enumerateTagsInRange在具有NSLinguisticTagSchemeNameTypeOrLexicalClass的设备上不起作用

[英]NSLinguisticTagger enumerateTagsInRange doesn't work on device with 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;
}

When I try to print out the available schemes on my iPhone, Lexical is not an option. 当我尝试在iPhone上打印可用的方案时,无法选择Lexical。 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

Using iPhone 6+ with iOS 11. 在iOS 11上使用iPhone 6+。

Unfortunately, the answer was changing devices. 不幸的是,答案是更换设备。 My iPhone X does not have this issue. 我的iPhone X没有这个问题。 It may be due to having a dedicated ML chip that the 6s and newer phones have. 这可能是由于6s和更新手机具有专用的ML芯片所致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM