Visual C++6.0是微软公司推出的开发Win32应用程序(Windows 95/98/2000/XP/NT)的、面向对象的可视化集成工具[8]。它的最大优点就是提供了功能强大的MFC类库,MFC是一个很大的C++类层次结构,其中封装了大量的类及其函数,很多Windows程序所共有的标准内容可以由MFC的类来提供,MFC类为这些内容提供了用户接口的标准实现方法,程序员所要做的就是通过预定义的接口把具体应用程序特有的东西填入这个轮廓,这将简化编程工作,大大的减少程序员编写的代码数量,使编程工作变得更加轻松容易。
3.3实现技术
3.3.1 数据存储
单词按照词性存储在不同的无限大的数组中,只需要在所有单词末尾加“0”就可以使数组无限的添加单词,删除和添加都很简便。举例只列出代词的存储如下:
char pron1[][20]={"i","I","0"}; //代词1本文来自辣'文.论^文·网原文请找腾讯3249^114
char pron2[][20]={"we","you","they","We","You","They","0"}; //代词2
char pron3[][20]=
论文网http://www.751com.cn/ {"he","she","it","He","She","It","0"}; //代词3
char pron4[][20]={"us","themselves", "myself","ourselves","me",
"them","itself","himself","him","her","0"}; //代词4
char pron5[][20]={"my","your","his","her","its","our","their","My",
"Your","His","Its","Our","They","0"}; //代词5
char pron6[][20]={"this","This","that","That","0"}; //代词6
char pron7[][20]={"these","those","These","Those","0"}; //代词7
3.3.2 主要算法实现
1、将用户输入的字符串去除空格,找出每个单词后将它存入string[]的数组中,并且输出单词的个数。代码如下:
void analyse()
{
char string[80];
char result[100] = "\0";
int pre_state = 0; //前一状态
int cur_state = 0;//当前状态
int next_state = 0;//后一状态
int i=0,j=0,k=0,t=0;
printf("\n\nPlease enter a sentence:\n");
gets(string);
if (string[strlen(string)-1] == '.')//判断句点.
{
string[strlen(string)-1] = '\0';
}
while(string[k]!='\0')
{
while(string[k]!=32 && string[k]!='\0')
//如果输入不是空格则放到依次存入数组中
{
s[i][j]=string[k];
j++;
k++;
}
s[i][j]='\0';
i++;
j=0;
//遇到空格,则在后面加入结束符号标记,将数组移动到第二列首地址
if(string[k] == 32) k++;
}
s[i][j]='\0';
t=i;
printf("\n单词数为:count=%d \n",t); //输出单词个数
}
2、建立一个words.c的文件,文件里的一个里面存储了许多数组,这些数组里面存放着不同词性及词义的单词;文件里还有判断单词词性的函数PartOfSpeech()函数,判断词性后的返回值(return的值)可以知道单词的词性(1表示代词 2 表示动词 3 表示介词 4 表示冠词 5 表示形容词 6 表示名词)。主要代码如下:
judge()函数:本文来自辣'文.论^文·网原文请找腾讯3249.114
int judge(char *word)
{
int i=0;
char pron1[][20]={"i","I","0"}; //代词1
char pron2[][20]={"we","you","they","We","You","They","0"}; //代词2
char pron3[][20]={"he","she","it","He","She","It","0"}; //代词3
……
查找用户输入的单词是否存在,直到最后都没有找到则退出。
//代词~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while(1)
{
if(strcmp(pron1[i],"0") == 0) break;
if(strcmp(word,pron1[i]) == 0) return 1; i++;
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
用状态机解决句子语义分析 第7页下载如图片无法显示或论文不完整,请联系qq752018766