Utility.cpp
资源名称:基本词典程序.rar [点击查看]
上传用户:jxhy0791
上传日期:2007-05-24
资源大小:6173k
文件大小:17k
源码类别:
多国语言处理
开发平台:
Visual C++
- /****************************************************************************
- *
- * Copyright (c) 2000, 2001
- * Machine Group
- * Software Research Lab.
- * Institute of Computing Tech.
- * Chinese Academy of Sciences
- * All rights reserved.
- *
- * This file is the confidential and proprietary property of
- * Institute of Computing Tech. and the posession or use of this file requires
- * a written license from the author.
- * Filename: Utility.c
- * Abstract:
- * Utility functions for Chinese Language Processing
- * Author: Kevin Zhang
- * (zhanghp@software.ict.ac.cn)
- * Date: 2002-1-8
- *
- * Notes:
- *
- ****************************************************************************/
- #include "stdafx.h"
- #include "Utility.h"
- #include <stdio.h>
- #include <string.h>
- /*********************************************************************
- *
- * Func Name : GB2312_Generate
- *
- * Description: Generate the GB2312 List file
- *
- *
- * Parameters : sFilename: the file name for the output GB2312 List
- *
- * Returns : bool
- * Author : Kevin Zhang
- * History :
- * 1.create 2002-1-8
- *********************************************************************/
- bool GB2312_Generate(char *sFileName)
- {
- FILE *fp;
- unsigned int i,j;
- if((fp=fopen(sFileName,"wt"))==NULL)
- return false;//fail while opening the file
- for(i=161;i<255;i++)
- for(j=161;j<255;j++)
- fprintf(fp,"%c%c,%d,%dn",i,j,i,j);
- fclose(fp);
- return true;
- }
- /*********************************************************************
- *
- * Func Name : CC_Generate
- *
- * Description: Generate the Chinese Char List file
- *
- *
- * Parameters : sFilename: the file name for the output CC List
- *
- * Returns : bool
- * Author : Kevin Zhang
- * History :
- * 1.create 2002-1-8
- *********************************************************************/
- bool CC_Generate(char *sFileName)
- {
- FILE *fp;
- unsigned int i,j;
- if((fp=fopen(sFileName,"wt"))==NULL)
- return false;//fail while opening the file
- for(i=176;i<255;i++)
- for(j=161;j<255;j++)
- fprintf(fp,"%c%c,%d,%dn",i,j,i,j);
- fclose(fp);
- return true;
- }
- /*********************************************************************
- *
- * Func Name : CC_Find
- *
- * Description: Find a Chinese sub-string in the Chinese String
- *
- *
- * Parameters : string:Null-terminated string to search
- *
- * strCharSet:Null-terminated string to search for
- *
- * Returns : char *
- * Author : Kevin Zhang
- * History :
- * 1.create 2002-1-8
- *********************************************************************/
- char *CC_Find(const char *string, const char *strCharSet)
- {
- char *cp=strstr(string,strCharSet);
- if(cp!=NULL&&(cp-string)%2==1)
- {
- return NULL;
- }
- return cp;
- }
- /*********************************************************************
- *
- * Func Name : charType
- *
- * Description: Judge the type of sChar or (sChar,sChar+1)
- *
- *
- * Parameters : sFilename: the file name for the output CC List
- *
- * Returns : int : the type of char
- * Author : Kevin Zhang
- * History :
- * 1.create 2002-1-8
- *********************************************************************/
- int charType(unsigned char *sChar)
- {
- if(*sChar<128)
- {
- if(strchr("