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

📄 dict.cpp

📁 本系统实现了分词和倒排索引
💻 CPP
字号:
#include "Dict.h"
#include <string.h>
Dict::Dict()
{
  OpenDict();
}

Dict::~Dict()
{
  dictMap.clear();
}

void Dict::OpenDict()
{
  FILE *fpDict;
  lexicon *hit_lexicon = new lexicon;
  //读二进制词典到内存中
  if((fpDict = fopen(DICTFILENAME, "rb")) == NULL)
  {
    printf("Can not open the Dictionary file!");
    exit(1);
  }
  fread(hit_lexicon,sizeof(lexicon),1,fpDict);
  int id, freq;
  char word[MAX_WORD_LEN];
  for(int i=0; i<HEAD_LEN; ++i)
  {
  	id = hit_lexicon->lexicon_head[i].word_id;
  	strcpy(word,hit_lexicon->lexicon_head[i].chinese_str);
  	freq = hit_lexicon->lexicon_head[i].freq;
  	dictMap.insert(map<string,int>::value_type(word,id));
  }

  fclose(fpDict);
  
}

bool Dict::IsWord(string& str) const
{
  if(dictMap.find(str) != dictMap.end())
    return true;
  return false;
}

int Dict::get_id(string &str)
{
	return dictMap[str];
}
/*
void Dict::AddFreq(string &str)
{
	//更新词频 
	//find word_id:dictMap[str]
	++word_freq[dictMap[str]];
	
}*/

⌨️ 快捷键说明

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