#include "search.h"
/*************************************************
Function:search_file_file_all
Description:根据输入的word搜索全部的文件,并且将结果置入result中
Input:用于存放结果的result,目标单词word,根节点集合root
Output:无
Return:无
Others:times会统计每次搜索的次数,最后统计到sum_times中
*************************************************/
search_file::search_file()
{
}
int search_file::search_all(int result[Maxnumber],const char* word,tree root[])
{
for(int i=0;i<Maxnumber;i++)
{
int times =0 ;
if(root[i].searchnode(word,times))
{
result[i]=1;
}
else
{
result[i] = 0;
}
sum_times += times;
}
}
/*************************************************
Function:split
Description:实现分割方法,根据输入的split作为分割依据,将目标语句分为两个搜索语句
Input:需要分段的目标target,分段词split,存储分段结果的word1与word2,开始位置start,默认为0
Output:无
Return:无
*************************************************/
int search_file::split(string target,string split,string &word1,string &word2,int start =0)
{
string word="";//用于中转存储word
int a = target.find(split,start);//查找分段词的位置
//根据不同的分段词进行判断
if(split == "AND"){
for(int i=0;i<a;i++) {
if (target[i] != ' ') {
word += target[i];
}
}
word1 = word;
word = "";
for(int i=a+3;i<target.length();i++) {
if (target[i] != ' ') {
word += target[i];
}
}
word2 = word;
}
if(split == "OR"){
for(int i=0;i<a;i++) {
if (target[i] != ' ') {
word += target[i];
}
}
word1 = word;
word = "";
for(int i=a+2;i<target.length();i++) {
if (target[i] != ' ') {
word += target[i];
}
}
word2 = word;
}
}
/*************************************************
Function:high_search
Description:针对两个词的搜索,分别对两个词进行全局的搜索,并且根据结果进行逻辑运算,存储到result中。
Input:存储结果的resul,两个关键词,分割词,以及根节点集合root
Output:无
Return:无
Others:
*************************************************/
int search_file::high_search(int result[Maxnumber],string word1,string word2,string split,tree root[])
{
//分别对两个关键词单独搜索与储存
int result1[Maxnumber];
int result2[Maxnumber];
search_all(result1,word1.data(), root);
search_all(result2,word2.data(), root);
//根据不用的关键词,进行逻辑判断
if(split == "AND")
{
for(int i = 0;i < Maxnumber;i++)
{
if(result1[i] == 1 && result2[i] == 1)
result[i] =1;
else
result[i] =0;
}
}
if(split == "OR")
{
for(int i = 0; i < Maxnumber; i++)
{ if(result1[i] == 1 || result2[i] == 1)
result[i] = 1;
else
result[i] = 0;
}
}
}
/*************************************************
Function:final_search
Description:整合search_file中的搜索功能,根据输入的target进行分析,采取不同的搜索策略。
具备识别是否是单一单词的搜索,是否是两个单词以及识别其逻辑词
鲁棒性增强,针对不同极端性搜索进行了识别
Input:存储结果的result,搜索目标target,根节点集合root
Output:输出总操作次数到控制台,便于后期优化算法
Return:无
Others:为了提高鲁棒性,对输入的target进行了多次判断
*************************************************/
int search_file::final_search(int result[Maxnumber],string target, tree root[]){
int location = target.find("AND");
string word1 = "";
string word2 = "";
if(location == 0 && target.length() >3)
{
location = target.find("AND", 2);
}
if(location != -1)
{
if(location == 0)
{
search_all(result,target.data(), root);
return 1;
}else{
split(target, "AND", word1, word2,3);
high_search(result,word1,word2,"AND", root);
return 1;
}
}else
{
location = target.find("OR");
if(location == -1)
{
search_all(result,target.data(), root);
cout << "总进行的操作次数为" << sum_times <<endl;
sum_times = 0;
return 1;
}
if(location == 0 && target.length() >=3)
{
location = target.find("OR", 2);
}
if(location == 0)
{
search_all(result,target.data(), root);
cout << "总进行的操作次数为" << sum_times <<endl;
sum_times = 0;
return 1;
}else{
split(target, "OR", word1, word2,2);
high_search(result,word1,word2,"OR", root);
cout << "总进行的操作次数为" << sum_times <<endl;
sum_times = 0;
return 1;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
fileSearch1_5.zip_文件搜索
共19个文件
h:6个
cpp:6个
png:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 185 浏览量
2022-09-21
21:58:59
上传
评论
收藏 75KB ZIP 举报
温馨提示
搜索两文件,看他们的相似性,曾而判断重合率。效果明显,查询快速
资源推荐
资源详情
资源评论
收起资源包目录
fileSearch1_5.zip (19个子文件)
fileSearch1_5
tree2.h 4KB
compare.cpp 3KB
fileSearch1_5.pro 1KB
search.h 719B
res.qrc 159B
compare.png 8KB
search.png 47KB
clear.png 3KB
tree.h 351B
.DS_Store 6KB
compare.h 651B
main.cpp 445B
search.cpp 5KB
file_input.cpp 2KB
mainwindow.cpp 5KB
file_input.h 521B
mainwindow.h 595B
tree.cpp 3KB
fileSearch1_5.pro.user 24KB
共 19 条
- 1
资源评论
小波思基
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功