NSLinguisticTagger语言是“und”

时间:2014-01-28 16:44:03

标签: 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 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”,为什么它不能正确识别语言?

2 个答案:

答案 0 :(得分:3)

来自the docs的NSOrthography:

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

答案 1 :(得分:0)

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

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:@" "];

它看起来像这样,NSLinguisticTagger会正确识别语言。

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?