u钙网免费制作文字头像-u钙网免费制作

u钙网免费制作文字头像-u钙网免费制作
浏览 (392)
  • 类型:
  • 更新:2024-07-17
  • 大小:282M
  • 所需权限:查看
  • 隐私政策:查看
", nil]; //对标题序列构建词典 //创建字典 WORD_ID = [NSMutableDictionary dictionary]; //[WORD_ID setObject:<#(id)#> forKey:<#(id)#>;] for (NSInteger i = 0; i < [TITLE_CONTENT count]; i++) { NSString *string = TITLE_CONTENT[i]; NSArray *sentence = [string componentsSeparatedByString:@" "]; for (NSString *word in sentence) { if (![WORD_ID valueForKey:word] ) { if ([word isEqualToString:@""]) { continue; } WORD_ID[word] = @(WORD_ID.count); } } } //A - B NSMutableDictionary *dict_A = [NSMutableDictionary dictionary];//存储各个标题对应的词频向量 NSMutableDictionary *vector_A = [NSMutableDictionary dictionary];//存储各个标题的向量表示 for (NSInteger i = 0; i < [TITLE_CONTENT count]; i++) { //获取当前标题 NSString *string = TITLE_CONTENT[i]; NSArray *sentence = [string componentsSeparatedByString:@" "]; //获取当前标题对应的向量 for (NSString *word in sentence) { if (![WORD_ID valueForKey:word]) continue; //如果字典中已经存储了该单词对应的词频,则将该词频加一 NSInteger index = [WORD_ID valueForKey:word]; NSString *word_key = [NSString stringWithFormat:@"%ld",index]; if ([dict_A valueForKey:word_key]) { NSInteger freq = [[dict_A valueForKey:word_key] integerValue]; dict_A[word_key] = [NSString stringWithFormat:@"%ld",freq+1]; }else{//如果没出现过 //将词频设置为1 dict_A[word_key] = @"1"; } } //生产向量 NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init]; formatter.numberStyle = kCFNumberFormatterNoStyle; for (NSString *key in [dict_A allKeys]) { NSNumber *num = [NSNumber numberWithFloat:[[dict_A valueForKey:key] floatValue]]; ((NSMutableDictionary *)vector_A[string])[key] = num; } } //插入之后,打印出 // for (NSInteger i = 0; i < [TITLE_CONTENT count]; i++) { // // NSString *string = TITLE_CONTENT[i]; // NSArray *sentence = [string componentsSeparatedByString:@" "]; // // for (NSString *word in sentence) { // if (![WORD_ID objectForKey:word]) continue; // // NSInteger index = [WORD_ID objectForKey:word]; // NSNumber *freq = vector_A[sentence][word]; // // NSLog(@"%@",[WORD_ID valueForKey:word]); // NSLog(@"%@---%@",word,freq); // } // // NSLog(@"%@",vector_A[string]); // } //A - B NSMutableDictionary *dict_B = [NSMutableDictionary dictionary];//存储各个标题对应的词频向量 NSMutableDictionary *vector_B = [NSMutableDictionary dictionary];//存储各个标题的向量表示 for (NSInteger i = 0; i < [ABSTRACT_CONTENT count]; i++) { //获取当前标题 NSString *string = ABSTRACT_CONTENT[i]; NSArray *sentence = [string componentsSeparatedByString:@" "]; //获取当前标题对应的向量 for (NSString *word in sentence) { if (![WORD_ID valueForKey:word]) continue; //如果字典中已经存储了该单词对应的词频,则将该词频加一 NSInteger index = [WORD_ID valueForKey:word]; NSString *word_key = [NSString stringWithFormat:@"%ld",index]; if ([dict_B valueForKey:word_key]) { NSInteger freq = [[dict_B valueForKey:word_key] integerValue]; dict_B[word_key] = [NSString stringWithFormat:@"%ld",freq+1]; }else{//如果没出现过 //将词频设置为1 dict_B[word_key] = @"1"; } } //生产向量 NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init]; formatter.numberStyle = kCFNumberFormatterNoStyle; for (NSString *key in [dict_B allKeys]) { NSNumber *num = [NSNumber numberWithFloat:[[dict_B valueForKey:key] floatValue]]; ((NSMutableDictionary *)vector_B[string])[key] = num; } } //构建相似度矩阵 NSInteger row = [ABSTRACT_CONTENT count]; NSInteger col = [TITLE_CONTENT count]; A_B_matrix = (float **)malloc(sizeof(float *) * row); for (NSInteger i = 0; i < row; i++) { A_B_matrix[i] = (float *)malloc(sizeof(float) * col); NSMutableDictionary *dict_B = vector_A[ABSTRACT_CONTENT[i]]; for (NSInteger j = 0; j < col; j++) { A_B_matrix[i][j] = 0.0; NSMutableDictionary *dict_A = vector_B[TITLE_CONTENT[j]]; //遍历词典 for (NSString *key in [dict_B allKeys]) { if ([dict_A valueForKey:key] && [dict_B valueForKey:key]) { //计算余弦相似度 //公式为:∑(Ai * Bi)/ √∑(Ai²) * √∑(Bi²) float Ai = [[dict_A valueForKey:key] floatValue]; float Bi = [[dict_B valueForKey:key] floatValue]; //计算平方 Ai *= Ai; Bi *= Bi; A_B_matrix[i][j] += Ai * Bi; } } } } //找出所有情况下每个J以及对应的I值 // 这里可以将打分值存储起来,找出最高的I值,找出最低的J值 //找出所有矩阵中的最大J值 float max = 0.0; NSInteger rowI = 0,columnJ = 0; float current = 0.0; for (NSInteger i = 0; i < row; i++) { for (NSInteger j = 0; j < col; j++) { current = A_B_matrix[i][j]; if (max < current) { max = current; //将当前值存入 rowI = i; columnJ = j; } } } //将存入的用户选择的摘要及标题取出 NSString *TITLE_STR = TITLE_CONTENT[columnJ]; NSString *ABSTRACT_STR = ABSTRACT_CONTENT[rowI]; NSLog(@"\n"); NSLog(@"输入的标题:%@",TITLE_STR); NSLog(@"输入的摘要:%@",ABSTRACT_STR); _titleString = TITLE_STR; _abstraingString = ABSTRACT_STR; } - (void)viewDidLoad { [super viewDidLoad]; //创建ReusableView UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 20.0f, self.view.bounds.size.width, self.view.bounds.size.height - 20.0f)]; view.backgroundColor = [UIColor grayColor]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(toIncorrectViewCon)]; [self.view addSubview:view]; // Do any additional setup after loading the view from its nib. } /* * 跳转到错误词处理界面 */ - (void)toIncorrectViewCon { DealWordsViewController *incorrectListView = [[DealWordsViewController alloc]init]; incorrectListView.incorrectWords = incorrectWords; [self.navigationController pushViewController:incorrectListView animated:YES]; NSLog(@"来到后台界面"); //推出ErrorListViewCon // ErrorListViewCon *errorListViewCon = [[ErrorListViewCon alloc]init]; // errorListViewCon.incorrectArray = incorrectArray; // [self.navigationController pushViewController:errorListViewCon animated:YES]; // // [self.view addSubview:_titleTxt]; // [self.view addSubview:_descTxt]; //添加正确标题及摘要 // self.titleTxt.text = _titleString; // self.descTxt.text = _abstraingString; // // [self.navigationItem.rightBarButtonItem setEnabled:NO]; // // NSMutableDictionary *titleAttri = [NSMutableDictionary dictionaryWithCapacity:3]; // // UIFont *titleFont = [UIFont fontWithName:@"Helvetica-Bold" size:16]; // // [titleAttri setObject:titleFont forKey:NSFontAttributeName]; // // // // //标题文字段落样式 // NSMutableParagraphStyle *titlePghStyle = [[NSMutableParagraphStyle alloc] init]; // //标题字体字符串属性 // NSString *titleStr = @"正确标题:"; // //标题字符串大小属性 // CGSize
安卓版下载

同类推荐更多

专题合集更多>>

小小法师无敌版无限钻石-小小法师无敌版 轩辕剑苍之涛手机版下载 MT管理器官方正版苹果-MT管理器官方正版 新超越极限魔道版-新超越极限修改版