求用C/C++写的抽词干(stem)函数

来源:百度知道 编辑:UC知道 时间:2024/06/18 18:25:36
比如说写个程序,要搜索某个单词在多篇文档中出现的位置,如果需要进行stem(抽词干)的处理:比如查read. 可以那些reading 的单词也返回。
这个stem函数怎么写?有没有一个写好的函数程序?
如果希望函数的参数是一个字符串string a,返回一个字符串string b,b是a的母串。比如我传入一个reading,可以返回read。
我只要做到给一个词典,返回关于这个词典经过取词干后的词典就可以(具体就是传入一个词,给出这个词的词干),不用管什么文档,也就是说我的词典txt文件只有一堆单词,用空格或者回车来区分。

C 程序
给定目标 字符str_stem
打开文件 a.txt
查到有str_stem 子串的 的字符串则 打印出来

#include"stdio.h"
FILE *fin;

void main()
{
char namein[80]="a.txt";
char str_stem[]="read";
char str[32];
int i,j,N,L;

N = strlen(str_stem);

if ( (fin = fopen(namein,"r") ) == NULL ) {
printf("open %s error\n",namein);
exit(0);
};

while (fscanf(fin,"%s",&str[0]) == 1){
L = strlen(str);
if (L >= N) {
for (i=0;i<=L-N;i++)
if (strncmp(&str[i],str_stem,N) == 0){ printf("found: %s\n",str); };
} // if
}; // while
fclose(fin);
getch();
}

----------
type a.txt
Let us read some thing
reading book forread
.... 1234 read1 3read--

我实现了一个从键盘输入的,效果如下 ,至于文件的,改一下应该不难,应该会用到串流类。
hello
for
read
reading
forread
输入要查找的单词: