作为Foundation下面具备强大功能的自然语言处理的框架,能够对自然语言的字符串进行解析 找到一句话的语言结构 例如
// ViewController.m
// NSLinguisticTagger
//
// Created by MR-BusWang on 16/11/29.
// Copyright © 2016年 乾坤翰林. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)setup{
NSString *question = @"what is the weather in china";
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace|NSLinguisticTaggerJoinNames|NSLinguisticTaggerOmitPunctuation;
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:[NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];
tagger.string = question;
[tagger enumerateTagsInRange:NSMakeRange(0, question.length) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSString * _Nonnull tag, NSRange tokenRange, NSRange sentenceRange, BOOL * _Nonnull stop) {
NSString *token= [question substringWithRange:tokenRange];
NSLog(@"%@,%@",token,tag);
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setup];
@end