NSLinguisticTagger enumerateTagsInRange 在带有 NSLinguisticTagSchemeNameTypeOrLexicalClass 的设备上不起作用 [英] NSLinguisticTagger enumerateTagsInRange doesn't work on device with NSLinguisticTagSchemeNameTypeOrLexicalClass

查看:19
本文介绍了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

使用 iPhone 6+ 和 iOS 11.

Using iPhone 6+ with iOS 11.

推荐答案

不幸的是,答案是改变设备.我的 iPhone X 没有这个问题.可能是因为 6s 和更新的手机有一个专用的 ML 芯片.

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 的设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆