分词系统工程报告
课程:自然语言理解
姓名:王佳淼
学号:2011914
班级:信息安全11-1
日期:2013-11-2
实验一宋词字统计
本实验所涉及的研究背景是利用计算机来“鉴赏”宋词。主要针对宋词这种特殊的汉语诗歌体裁,开展了有关自动生成算法及其实现方法的探索性研究。通过对大量语料的学习,来自动生成宋词。由于宋词自身的特性,能够在经过大量预料学习后,利用在宋词当中出现频率较高的词语或者单字排列组合来生成宋词。
实验在WIN7的环境下利用VC++编程。
算法基本思想
从文本中字符,判断是否为中文字符(全角字符),若为全角字符则根据需要继续读取,即读取两个或三个字。利用map容器来存储统计结果。
流程图
代码
①字统计
#include <map>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
//宋词的统计
void display_map(map<string, int> &wmap);
ofstream ofs("c:\\");
int main()
{
cout<<"开始:"<<endl;
const char *szInputFileName="c:\\";
ifstream ifs(szInputFileName);
string szTemp;
string str1,str2,str3,str;
char a[10];//
map<string, int> wmap;
//统计双字的
while (ifs)
{
while(()=='\n') ();
while(()==' ') ();
while(!()&0x80) ();
(a,3,' ');
if(a[0]&0x80)
{
str1=a;
while(()=='\n') continue;
while(()==' ') continue;
while(!()&0x80) ();
(a,3,' ');
if(a[0]&0x80) str2=a;
if(str1!=","&&str1!="。"&&str1!="?"&&str1!="!"&&str1!=""&&str2!=","&&str2!="。"&&str2!="?"&&str2!="!"&&str2!="")
{
szTemp=str1+str2;
wmap[szTemp]++;
}
if(()!='\n'&&()!=' ') (-2,ios::cur);
}
}
();
//三字
ifstream ifs1(szInputFileName);
while (ifs1)
{
while(()=='\n') ();
while(()==' ') ();
while(!()&0x80) ();
(a,3,' ');
if(a[0]&0x80)
{
str1=a;
while(()=='\n') continue;
while(()==' ') continue;
while(!()&0x80) ();
(a,3,' ');
if(a[0]&0x80) str2=a;
else continue;
while(()=='\n') continue;
while(()==' ') continue;
while(!()&0x80) ();
(a,3,' ');
if(a[0]&0x80) str3=a;
else continue;
if(str1!=","&&str1!="。"&&str1!="?"&&str1!="!"&&st
自然语言理解实验报告 来自淘豆网m.daumloan.com转载请标明出处.