Objective c NSLinguagistTagger语言是;und";

Objective c NSLinguagistTagger语言是;und";,objective-c,cocoa,Objective C,Cocoa,我想弄清楚字符串的语言。如果我从一个变量传递它,它会将语言识别为“und”,但如果我将它作为 [tagger setString:[NSString stringWithFormat:@"Example 2 Three people have attached a rope around your belly and pull it with the indicated forces. The sketch isn’t true to scale and shows the situation

我想弄清楚字符串的语言。如果我从一个变量传递它,它会将语言识别为“und”,但如果我将它作为

 [tagger setString:[NSString stringWithFormat:@"Example 2 Three people have attached a rope around your belly and pull it with the indicated forces. The sketch isn’t true to scale and shows the situation froth above. a) Detennine with a drawing, in what direction you are pulled (assuming that you don’t put up any resistance) Choose a scale of l00N 2 Ion . b) What is the influence of the lengths of the ropes?"]];
它能正确识别语言。两种情况下的文本相同

//Recognize Language for Output
{
    NSArray *tagschemes = [NSArray arrayWithObjects:NSLinguisticTagSchemeLanguage, nil];
    NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagschemes options:0];
    [tagger setString:[NSString stringWithFormat:@"%@", text]];

    NSString *language = [tagger tagAtIndex:0 scheme:NSLinguisticTagSchemeLanguage tokenRange:NULL sentenceRange:NULL];

    output = [NSString stringWithFormat:@"The language is %@\rand the following words were found:\r\r%@", language, output];

}

什么样的语言是“und”,为什么不能正确地将语言重新编码为en?

问题是文本格式不正确。“文本”字符串中的原始文本如下所示:

2014-01-28 18:13:51.412 Tesseract[35357:70b] Old text: Example 2

Three people have attached a rope around your belly

and pull it with the indicated forces. The sketch isn’t

true to scale and shows the situation from above.

a) Detennine with a drawing, in what direction you are
pulled (assuming that you don’t put up any resistance)
Choose a scale of l00N 2 tom .

b) What is the influence of the lengths of the ropes?
如果使用

text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
看起来是这样的,NSLinguagistTagger会正确识别语言

2014-01-28 18:13:51.412 Tesseract[35357:70b] Reformatted text: Example 2  Three people have attached a rope around your belly  and pull it with the indicated forces. The sketch isn’t  true to scale and shows the situation from above.  a) Detennine with a drawing, in what direction you are pulled (assuming that you don’t put up any resistance) Choose a scale of l00N 2 tom .  b) What is the influence of the lengths of the ropes? 
从以下位置开始进行图像分析:


如果无法确定特定语言,则使用标记
und

您是否100%确定[NSString stringWithFormat:@“%@”,text]正在解析为非零是的,如果它将解析为零,则输出也将为(空)。您能否显示一个完整的“非工作情况”自包含示例我已经用
[tagger setString:[NSString stringWithFormat:@“%@”,text]]
测试了您的代码,其中
text
是您的字符串,tagger正确识别了语言“en”。是的,问题是我使用的字符串的格式。我一拆下断线,效果就很好。你认为这是一个错误吗?如果是这样,我该如何告诉苹果呢?很抱歉问这个问题,但我对几乎所有与代码相关的内容都是新手。顺便说一句,您过度使用了-stringWithFormat:。上面有两个多余的使用,其中一个实际上相当危险。非常感谢。在查看文件时没有发现。