NSLinguisticTagger
은 여러 언어로 된 번호를 표시합니다.
NSArray * texts = @[@"It's 3 degrees outside", @"Ocho tacos", @"What is 3 1/2?", @"ocho"];
for (NSString * text in texts)
{
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerJoinNames;
NSArray * tagSchemes = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"];
tagSchemes = [tagSchemes arrayByAddingObjectsFromArray:[NSLinguisticTagger availableTagSchemesForLanguage:@"es"]];
NSLinguisticTagger * tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagSchemes
options:options];
[tagger setString:text];
[tagger enumerateTagsInRange:NSMakeRange(0, [text length])
scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass
options:options
usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop)
{
NSString *token = [text substringWithRange:tokenRange];
NSLog(@"%@: %@", token, tag);
}];
}
이 언제, 어떻게 분수 해상도 같은 일을 식별하는 작업과 당신을 떠나지 않습니다.
"자연 언어"와 "NSNumberFormatter"에 대한 문서 검색 –
@JoshuaNozzi 발견 한 바로는 'NSNumberFormatter'는이 작업의 반대 작업 만 수행 할 수 있습니다. – edc1591
키 "1"에 2, "2"에 2 등의 값을 갖는 NSDictionnary를 만들 수 있습니다. 하지만 각 번호를 하나씩 써야합니다. 실용적인 것은 아닙니다. – Moray