gpt4 book ai didi

ios - iOS 中的词干提取 - 不适用于单个词

转载 作者:可可西里 更新时间:2023-11-01 03:08:58 25 4
gpt4 key购买 nike

我正在使用 NSLinguisticTagger 进行词干提取。我能够获得句子中单词的词干,但无法获得单个词的词干。

以下是我使用的代码,

    NSString *stmnt = @"i waited";
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames;

NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:@[NSLinguisticTagSchemeLemma] options:options];
tagger.string = stmnt;
[tagger enumerateTagsInRange:NSMakeRange(0, [stmnt length]) scheme:NSLinguisticTagSchemeLemma options:options usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
NSString *token = [stmnt substringWithRange:tokenRange];
NSLog(@"%@: %@", token, tag);
}];

为此我正确地离开了:

i: i
waited: wait

但是如果 stmnt = @"waited";

上面的代码无法识别词干

非常感谢任何帮助

最佳答案

以下代码对我有用,

NSString *stmt = @"waited";
NSRange stringRange = NSMakeRange(0, stmt.length);
NSDictionary* languageMap = @{@"Latn" : @[@"en"]};
[stmt enumerateLinguisticTagsInRange:stringRange
scheme:NSLinguisticTagSchemeLemma
options:NSLinguisticTaggerOmitWhitespace
orthography:[NSOrthography orthographyWithDominantScript:@"Latn" languageMap:languageMap]
usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
// Log info to console for debugging purposes
NSString *currentEntity = [stmt substringWithRange:tokenRange];
NSLog(@"%@ is a %@, tokenRange (%d,%d)",currentEntity,tag,tokenRange.length,tokenRange.location);
}];

关于ios - iOS 中的词干提取 - 不适用于单个词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24402415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com