win_cDemo.cpp
资源名称:sample.zip [点击查看]
上传用户:dfahe421ef
上传日期:2021-11-07
资源大小:12279k
文件大小:3k
源码类别:
词法分析
开发平台:
Visual C++
- // win_cDemo.cpp : 定义控制台应用程序的入口点。
- //
- #include "ICTCLAS30.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #pragma comment(lib, "ICTCLAS30.lib");
- void Split(const char *sInput);
- void KeyExtract(const char *sInput);
- void FingerPrint(const char *sInput);
- void Split(const char *sInput)
- {
- //初始化分词组件
- if(!ICTCLAS_Init())
- {
- printf("ICTCLAS INIT FAILED!n");
- return ;
- }
- else
- printf("ICTCLAS INIT SUCCEED!n");
- ICTCLAS_SetPOSmap(ICT_POS_MAP_SECOND);
- //导入用户词典前
- printf("未导入用户词典:n");
- const char *sResult = ICTCLAS_ParagraphProcess(sInput, 1);
- printf("%sn", sResult);
- //导入用户词典后
- printf("n导入用户词典后:n");
- int nCount = ICTCLAS_ImportUserDict("userdic.txt");//覆盖以前的用户词典
- //保存用户词典
- ICTCLAS_SaveTheUsrDic();
- printf("导入%d个用户词。n", nCount);
- sResult = ICTCLAS_ParagraphProcess(sInput, 1);
- printf("%sn", sResult);
- //动态添加用户词
- printf("n动态添加用户词后:n");
- ICTCLAS_AddUserWord("973专家组组织的评测 ict");
- ICTCLAS_SaveTheUsrDic();
- sResult = ICTCLAS_ParagraphProcess(sInput, 1);
- printf("%sn", sResult);
- //文件分词
- printf("文件分词");
- ICTCLAS_FileProcess("test.txt","test_result.txt",1);
- //
- //释放分词组件资源
- ICTCLAS_Exit();
- }
- void KeyExtract(const char *sInput)
- {
- //初始化分词组件
- if(!ICTCLAS_Init())
- {
- printf("ICTCLAS INIT FAILED!n");
- return ;
- }
- printf("n关键词提取:n");
- int nCount = ICTCLAS_GetParagraphProcessAWordCount(sInput);
- //分词。提取关键词
- result_t *result =(result_t*)malloc(sizeof(result_t)*nCount);
- ICTCLAS_ParagraphProcessAW(nCount,result);//获取结果存到客户的内存中
- //关键词提取,须在ICTCLAS_ParagraphProcessAW函数执行完后执行
- result_t *resultKey = (result_t*)malloc(sizeof(result_t)*nCount);
- int nCountKey;
- ICTCLAS_KeyWord(resultKey, nCountKey);
- for (int i=0; i<nCountKey; i++)
- {
- char buf[100];
- memset(buf, 0, 100);
- int index = resultKey[i].start;
- memcpy(buf,(void *)(sInput+index), resultKey[i].length);
- printf("%st%dn", buf, resultKey[i].weight);
- }
- free(resultKey);
- free(result);
- //释放分词组件资源
- ICTCLAS_Exit();
- }
- void FingerPrint(const char *sInput)
- {
- //初始化分词组件
- if(!ICTCLAS_Init())
- {
- printf("ICTCLAS INIT FAILED!n");
- return ;
- }
- int nCount = ICTCLAS_GetParagraphProcessAWordCount(sInput);
- //分词。提取关键词
- result_t *result =(result_t*)malloc(sizeof(result_t)*nCount);
- ICTCLAS_ParagraphProcessAW(nCount,result);//获取结果存到客户的内存中
- //指纹提取,须在ICTCLAS_ParagraphProcessAW函数执行完后执行
- unsigned long lFinger = ICTCLAS_FingerPrint();
- char buf[100];
- memset(buf, 0, 100);
- sprintf(buf, "%x", lFinger);
- printf("指纹:%sn", buf);
- //释放分词组件资源
- ICTCLAS_Exit();
- }
- int main()
- {
- const char *sInput = "ICTCLAS在国内973专家组组织的评测中活动获得了第一名,在第一届国际中文处理研究机构SigHan组织的评测中都获得了多项第一名。";
- //分词
- Split(sInput);
- //关键词提取
- KeyExtract(sInput);
- //指纹提取
- FingerPrint(sInput);
- // char bufTmp[100];
- // scanf("%s", bufTmp);
- return 1;
- }