⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sntncelex.cpp

📁 中科院开源的ictprop源码,使用方法: 1、修改源码中的InputComboBox.cpp文件 InvokeAction里面的txt文件路径换成你的本地路径; 2、入口在帮助里面
💻 CPP
字号:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sntncelex.h"
#include "grmrgrph.h"

#define MAXTOKENSIZE 100
//#define MAXLINESIZE 5000

char token[MAXTOKENSIZE];
char sentbuf[MAXSENTLEN];
int symbmode;
int endofsntnce;
int endposofsntnce;
unsigned int nextcate, currcate;
unsigned int curchartnode, prechartnode, accchartnode;
wentry_t *nextwentry, *currwentry;
wentry_t *wentries[MAXCNODE-1];
unsigned int (*nextdefs)[MAXDEFS], (*currdefs)[MAXDEFS];
unsigned int deflettice[MAXCNODE-1][MAXDEFS];
FILE *pfs;
int bufptr;

//int maxlink;
//int fufiled;

wentry_t *dictionary[MAXWENTRY];

int hash(char *s){
  unsigned hashval;

  for (hashval=0;*s!='\0';s++)
      hashval=*s+31*hashval;

  return hashval % MAXWENTRY;
}

wentry_t *listsearch(int hashval, char *word){
  wentry_t *curwentry;

  for (curwentry=dictionary[hashval];curwentry!=NULL;curwentry=curwentry->nxt){
//	  link++;
//  	  if (link>maxlink)
		 //maxlink=link;
      if (strcmp(curwentry->word, word)==0)
         break;
  }

  return curwentry;
}

int listrelease(int hashval){
  wentry_t *pwentry, *qwentry;
  def_t *pdef, *qdef;

  for (pwentry=dictionary[hashval];pwentry!=NULL;pwentry=qwentry){
      qwentry=pwentry->nxt;
      for (pdef=pwentry->def;pdef!=NULL;pdef=qdef){
          qdef=pdef->nxt;
          free(pdef);
      }
      free(pwentry->word);
      free(pwentry);
  }
  return 0;
}

int dictrelease(){
  int i;

  for (i=0;i<MAXWENTRY;i++){
      listrelease(i);
      dictionary[i]=NULL;
  } 
  return 0;
}

wentry_t *dictsearch(char *word){
  return listsearch(hash(word), word);
}

wentry_t *dictinsert(char *word){
  int hashval;
  wentry_t *newwentry;

  hashval=hash(word);
  newwentry=listsearch(hashval, word);
  if (newwentry==NULL){
     newwentry=(wentry_t *)malloc(sizeof(wentry_t));
     newwentry->def=NULL;
     newwentry->word=(char *)malloc(strlen(word)+1);
     strcpy(newwentry->word, word);

     newwentry->nxt=dictionary[hashval];
//	 if (newwentry->nxt==NULL)
//		 fufiled++;
     dictionary[hashval]=newwentry;
	 
  } 
  return newwentry;
}

adddef(wentry_t *wentry, unsigned int cate){
  def_t *curdef, *newdef;

  for (curdef=wentry->def;curdef!=NULL;curdef=curdef->nxt)
      if (curdef->cate==cate)
         break;
  if (curdef==NULL){
     newdef=(def_t *)malloc(sizeof(def_t));
     newdef->cate=cate;
     newdef->nxt=wentry->def;
     wentry->def=newdef;
  }
  return 0;
}
/*
char *gettoken(){
  int c, pos=0;

  while ((c=fgetc(pfs))==' '||c=='\t')
    ;
  if (c==EOF || c=='\n')
	  endofsntnce=1;
  else{
     do{
       token[pos++]=(char)c;
     }while ((c=getc(pfs))!=EOF && c!=' ' && c!='\t' && c!='\n') ;
	 if (c=='\n')
	    ungetc(c, pfs);
  }
  token[pos]='\0';
  
  return token;
}
*/

filllattice(){
	int i,j,c,pos;
	char *stoken;
	def_t *pdef;

	endposofsntnce=-1;
	for (i=0; i<(MAXCNODE-1); i++){
		if (endposofsntnce>=0)
			break;
		pos=0;
		while (((c=sentbuf[bufptr++])==' ')||c=='\t')
			;
		if (c=='\n' || c=='\0')
			endposofsntnce=i;
		else{
			do{
				token[pos++]=(char)c;
			}while ((c=sentbuf[bufptr++])!='\0' && c!=' ' && c!='\t' && c!='\n') ;
			if (c=='\n'||c=='\0')
				bufptr--;
		}
		token[pos]='\0';

		if (*token=='\0')
			endposofsntnce=i;

		if (*token!='\0')
			stoken=strtok(token, "/");
		else
			stoken=token;
		wentries[i]=dictinsert(stoken);


		if (*token!='\0')
			stoken=strtok(NULL, "/");
		else
			stoken=NULL;

		if (stoken!=NULL){
			deflettice[i][0]=token2tcode(stoken);
			deflettice[i][1]=tcount;
		}
		else{
			for (j=0, pdef=wentries[i]->def;pdef!=NULL;pdef=pdef->nxt){
				deflettice[i][j++]=pdef->cate;
			}
			deflettice[i][j]=tcount;
		}

	}
	
	return 0;
}

lookahead(){
	
	nextwentry=wentries[curchartnode];
	nextdefs=&deflettice[curchartnode];
//	for (i=0; i<MAXDEFS; i++)
//		nextdefs[i]=deflettice[curchartnode][i];


	endofsntnce=(endposofsntnce==curchartnode);


  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -