美文网首页
自然语言NSLinguisticTagger

自然语言NSLinguisticTagger

作者: muyang_js的简书 | 来源:发表于2016-11-01 01:01 被阅读75次

    //1.创建语句

    NSString * question = @"What is the weather in San Francisco?";

    //2.创建筛选条件

    NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerJoinNames |NSLinguisticTaggerOmitPunctuation;

    //3.创建自然语言标签

    NSLinguisticTagger * tagger = [[NSLinguisticTagger alloc]initWithTagSchemes:[NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];

    //4.给标签附字符串

    tagger.string = question;

    //5.执行筛选

    [tagger enumerateTagsInRange:NSMakeRange(0, question.length) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass  options:options usingBlock:^(NSString * _Nonnull tag, NSRange tokenRange, NSRange sentenceRange, BOOL * _Nonnull stop) {

    //6.获取结果

    NSString *token = [question substringWithRange:tokenRange];

    //7.打印结果

    DLog(@"token---%@:tag---%@",token, tag);

    }];

    打印结果

    相关文章

      网友评论

          本文标题:自然语言NSLinguisticTagger

          本文链接:https://www.haomeiwen.com/subject/tgtmuttx.html