
有什么我做错了吗?
Nsstring *input = @"I am hungry";NSlinguisticTaggerOptions options = NSlinguisticTaggerOmitWhitespace;NSlinguisticTagger *tagger = [[NSlinguisticTagger alloc] initWithTagschemes:[NSlinguisticTagger availableTagschemesForLanguage:@"en"] options:options];tagger.string = input;[tagger enumerateTagsInRange:NSMakeRange(0,input.length) scheme:NSlinguisticTagschemenameTypeOrLexicalClass options:options usingBlock:^(Nsstring *tag,NSRange tokenRange,NSRange sentenceRange,BOol *stop) { Nsstring *token = [input substringWithRange:tokenRange]; Nsstring *lemma = [tagger tagAtIndex:tokenRange.location scheme:NSlinguisticTagschemeLemma tokenRange: NulL sentenceRange:NulL]; NSLog(@"%@ (%@) : %@\n",token,lemma,tag);}]; 输出是:
I ((null)) : OtherWordam ((null)) : OtherWordhungry ((null)) : OtherWord@R_502_6120@ quite some time in chat之后我们发现了这个问题:
The sentence does not contain enough information to determine its language.
要解决此问题,您可以:
在你的实际句子之后用你选择的语言添加一个演示句.这应该保证您的首选语言被检测到.
要么
告诉标记器使用哪种语言:添加行
[tagger setorthography:[NSOrthography orthographyWithDominantScript:@"Latn" languageMap:@{@"Latn" : @[@"en"]}] range:NSMakeRange(0,input.length)]; 在枚举调用之前.通过这种方式,您可以明确告诉标记器您希望文本使用哪种语言,在本例中,englisch(en)是拉丁语主导语言(Latn)的一部分.
如果您不确定该语言,那么如果将单词标记为OtherWord意味着无法检测到该语言,那么将这些方法中的任何一种仅用作后备可能是有用的.
总结以上是内存溢出为你收集整理的ios – 语言标记器错误地标记为“OtherWord”全部内容,希望文章能够帮你解决ios – 语言标记器错误地标记为“OtherWord”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)