1
我需要一个关键字(这是它的词汇形式)与文本匹配,返回是否关键字匹配(就像一个搜索引擎)获得时的iOS NSLinguisticTagger总是返回null引理干
例如
text: I want some apples
keyword: apple
result: matched
keyword: banana
result: not matched
这是我的方法,我总是空的标签
- (BOOL)matchKeywordWithText:(NSString *)text keyword:(NSString *)keyword {
__block NSMutableArray *words = [NSMutableArray array];
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames;
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes: [NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];
tagger.string = text;
[tagger enumerateTagsInRange:NSMakeRange(0, [text length]) scheme:NSLinguisticTagSchemeLemma options:options usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
NSString *token = [text substringWithRange:tokenRange];
//TODO: TAG IS ALWAYS NULL HERE
NSLog(@"words are %@: %@", token, tag);
if (tag.length > 0) {
[words addObject:tag];
}
}];
for (NSString *word in words) {
if ([word isEqualToString:keyword]) {
return YES;
}
}
return NO;
}
你能看看我的问题吗?非常沮丧.. https://stackoverflow.com/questions/48768919/device-vs-simulator-linguistic-schemes –