- (NSArray *)mecabResultWithString:(NSString *)input
{
NSMutableArray *ret= [NSMutableArray array];
if (input==nil || [input length]==0)
return ret;
const char *buf= [input cStringUsingEncoding:NSUTF8StringEncoding];
NSUInteger l= [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
const mecab_node_t *node = mecab_sparse_tonode2(mecab, buf, l);
if (node == NULL) {
return ret;
}
node = node->next;
for (; node->next != NULL; node = node->next) {
NSString *f = [NSString stringWithCString:node->feature encoding:NSUTF8StringEncoding];
NSString *yomi= [[f componentsSeparatedByString:@","] objectAtIndex:7];
[ret addObject:yomi];
}
return ret;
}
int i, ic= [mecabResult count];
NSMutableString *str= [NSMutableString string];
for(i= 0;i<ic;i++) {
[str appendFormat:@"%@ ", [mecabResult objectAtIndex:i]];
}
CFStringTransform(str, NULL, kCFStringTransformHiraganaKatakana, YES); //カタカナ→ひらがな
CFStringTransform(str, NULL, kCFStringTransformLatinHiragana, YES); //ひらがな→ローマ字(?)
NSLog(@"%@", str);
0 件のコメント:
コメントを投稿