📄 1 标题提取(包含正文).cpp
字号:
//功能:提取 语料库的标题
//输入:199801.txt语料库
//输出dic_try1.txt 标题集
//思路:
//根据篇章信息(19980104-04-001-001)确定当前读入行是否是标题(-001是标题)
// 如果是标题,显示(修改显示标志位 print=1)
// 不是(print=0)
#include <stdio.h>
void main()
{
FILE *fp;FILE *fpw;
fp=fopen("199801.txt","r");//读入文件
fpw=fopen("dic_try1.txt","w");//写入文件
if (fp==NULL)
{ printf("cannot open thi file\n");}
if (fpw==NULL)
{ printf("cannot open thi file\n");}
int status=0;//0 处理排版信息 1 处理词
int pb_p=0;
int print=0;
int i=1;
unsigned int temp[20];//篇章信息 19位
while(!feof(fp))
{
unsigned int c1 =fgetc(fp);//printf("%x\n",c1);
if(c1==-1){continue;}//处理文件结尾符作为字符显示的问题
//处理回车,同时说明了 篇章信息和文章内容的结束
if(c1==10){
if(print==1)
{fputc(c1,fpw);print=0;}
pb_p=0;
continue;
}
//处理空格
if(c1==32){
if(print==1)fputc(c1,fpw);
continue;
}
//ascii码(1 篇章信息 2 标注信息)
if(c1<161){
//修改 打印标题 标志位
if (c1>=48 && c1<=57 || c1==45) //是篇章信息
{
pb_p=(pb_p++)%19;
if(c1!=temp[15] && pb_p==15 ){print=1;}
temp[pb_p]=c1;
if(pb_p==19 && print==1)
{ fputc(10,fpw);
for( i=1;i<20;i++)
fputc(temp[i],fpw);
}
}
else{//标注信息
}
}
//是一个GBK (文章内容)
else{
//if(print==1)
fputc(c1,fpw);
unsigned int c2 =fgetc(fp);
// if(print==1)
fputc(c2,fpw);
}
}
fclose(fpw);
fclose(fp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -