数据结构课程设计求教!

雪域迷影 2010-07-06 02:06:24
以下是本人的课程设计作业:
微型搜索引擎 ★★★★★
Google、Baidu、Bing、Yahoo这些都是你能在网上找得到的搜索引擎,搜索引擎的主要功能就是根据用户给出的关键词在文档集合当中找到满足条件的文档。请根据你学到的数据结构知识完成以下任务。
你的任务:
(1)设计和实现一种算法:能够在一组文档集合中找到包含搜索关键词的文档。首先、应该处理文档集合,把文档中的单词提取出来,存储到适当的数据结构中;这个过程称为建立索引过程,此过程选用的数据结构非常关键,直接影响到搜索速度。然后、在搜索的时候根据关键词在之前建立的数据结构中查找满足条件的文档。搜索的结果按照相关度排序。相关度可以用简单的单词出现频率来衡量(实际搜索引擎不会这么简单)。

(2)实现条件查询(AND和OR):比如说在查询过程中如果两个Keyword之间用AND相连,Keyword1 AND Keyword2,那么你找到的文档中必须同时包含这两个关键词。假如用OR相连,Keyword1 OR Keyword2 那么找到的文档中要么包含Keyword1要么包含Keyword2.

输入:50篇文档(在Project8中的documents文件夹)和样例搜索(Project8文件夹下的sample_query.txt可用于测试你的程序)。
输出:对于每一个搜索条件输出满足条件的文档文件名。

举例
假如有以下几个文件,文件内容如下:
Doc1: I like the class on data structures and algorithms.
Doc2: I hate the class on data structures and algorithms.
Doc3: Interesting statistical data may result from this survey.
再看以下几种查询
查询输入:data
输出:Doc1, Doc2, Doc3

查询输入:data AND structures
输出:Doc1, Doc2

查询输入:like OR survey
输入:Doc1, Doc3

感觉这个挺有挑战性的,对于C语言和数据结构文件这一块本人不是很熟,
希望大家给予帮助!
...全文
205 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dickwuhui 2011-01-05
  • 打赏
  • 举报
回复
用哈希字典序貌似可以实现
罗纳尔迪尼奥 2010-07-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 budtang 的回复:]

我看这还挺好实现的, 首先就扫描文件,提取关键词,然后存在数据库中。 当查询时通过关键词检索数据库,查出文件, 最后输出即可
[/Quote]

厉害···
wing_0706 2010-07-25
  • 打赏
  • 举报
回复

//-------------------hash.h-----------
#ifndef __HASH__H
#define __HASH__H


typedef int Status;
#define SUCCESS 1
#define UNSUCCESS 0
//#define DUPLICATE -1

#define INVALID -1 //无数据情况
#define VALID 1 //有数据情况
//#define hashSize 1847
#define hashSize 601



typedef struct node
{
char word[20];
long frequency; //次数
int flag;
struct node* next;
}hashNode;

typedef struct
{
node* pElem;
int count;
int size;
}hashTable;

void CharChange(char *pChar);//character 大写换小写
Status InitHash(hashTable* pHashTable);
Status CreatHash(hashTable* pHashTable, char word[]);
int Coding(char word[]);

#endif
//***************************************************************
//hash.cpp
#include "hash.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>


void CharChange(char *pChar)
{
char *p;
p = pChar;
while(*p)
{
if (*p>='A' && *p<='Z')
{
*p= (char)(*p + 32);
}
p++;
}
}




Status InitHash(hashTable* pHashTable)
{
int i = 0;
pHashTable->count = 0;//当前元素个数
pHashTable->size = hashSize;//容量
pHashTable->pElem = ( node* )calloc(pHashTable->size, sizeof(node));
if (pHashTable->pElem)
{
for (i=0; i<pHashTable->size; i++)
{
pHashTable->pElem[i].flag = INVALID;
pHashTable->pElem[i].frequency = 0;
pHashTable->pElem[i].next = NULL;
strcpy(pHashTable->pElem[i].word,"");
}
return SUCCESS;
}
else
{
return UNSUCCESS;
}

}

int Coding(char* word)
{
CharChange(word);
char *p;
int num = 0;
int size = hashSize;
p = word;
while ('\0' != *p)
{
num += (int)*p++;
}
return num % size;
}

Status CreatHash(hashTable* pHashTable, char word[])
{
int position = Coding(word);
node *p;
node *pNode;
p = &(pHashTable->pElem[position]);//当前结点地址

if (INVALID == pHashTable->pElem[position].flag)
{
strcpy(pHashTable->pElem[position].word, word);
pHashTable->pElem[position].flag = VALID;
pHashTable->pElem[position].frequency++;
pHashTable->count++;
}
else
{
if(strcmp(pHashTable->pElem[position].word,word) == 0)
{
pHashTable->pElem[position].frequency++;
}
else
{
while (p->next != NULL)
{
p = p->next;
if (strcmp(word,p->word) == 0)
{
p->frequency++;
return SUCCESS;
}
}
if (p->next == NULL)
{
pNode = (node *)malloc(sizeof(node));
if (pNode)
{
strcpy(pNode->word, word);
pNode->next = NULL;
p->next = pNode;
pNode->flag = VALID;
pNode->frequency = 1;
}
else
{
return UNSUCCESS;
}
}
}
}
return SUCCESS;
}

wing_0706 2010-07-25
  • 打赏
  • 举报
回复
哈希表。。
ljia0 2010-07-22
  • 打赏
  • 举报
回复
能够在一组文档集合中找到包含搜索关键词的文档
对这些文档的单词按照出现的频率进行排序,每个单词设置一个标志位说明它是哪个文档的同。然后就输放关键字进行查找。在查找过程中再对那些单词进行排序,查找频率高的排前面。
Six_dimensional 2010-07-22
  • 打赏
  • 举报
回复
mark一下,晚上过来弄
qq120848369 2010-07-20
  • 打赏
  • 举报
回复
可以哈希里边套哈希.
pzlfly 2010-07-20
  • 打赏
  • 举报
回复
用hash表或者树都可以,建立索引,然后根据索引快速查找。
采用表的话,索引可以选取每个单词中字母的个数,然后建立索引,碰撞解决可以采用链表法。单词and的查找,可以建立有重复单词的hash表。
雪域迷影 2010-07-07
  • 打赏
  • 举报
回复
那这个数据库该用什么数据结构呢?
是该用表还是树呢?
budweiser 2010-07-06
  • 打赏
  • 举报
回复
我看这还挺好实现的, 首先就扫描文件,提取关键词,然后存在数据库中。 当查询时通过关键词检索数据库,查出文件, 最后输出即可

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧