
2.从nlpir官网下载相关资源,这里下载的是2013版本。下载地址:http://ictclas.nlpir.org/upload/20140324095815_ICTCLAS2014.rar
3.将下载文件解压缩,找到其中的Data文件夹、bin文件夹中的NLPIR.dll文件、include文件夹中的NLPIR.h文件、lib文件夹
中的NLPIR.lib文件,将这四个东西复制到刚刚的text-segmentation文件夹中的text-segmentation文件夹下,如下
效果:
4.点击text-segmentation文件夹下的text-segmentation.sln,在vs中打开这个项目。按照如下方式将NLPIR.h文件加入到头液李文件中。
5.点击project ->properties(快捷键ALT +
F7),按照下图所示的进行设置。别问我为什么这么设置,我也不懂,摸索了半天才摸索出来的,不这么圆埋宴设置就是搞不定。
6.在source里面新建程序新建c++源程序
7.接下来就可以在这里写代码了,下面附上一段我的代码作为例子。最关键的是前面的函数头部分,可以直接抄过去。
#ifndef OS_LINUX
#include
#pragma comment(lib, "NLPIR.lib")
#endif
#include
#include
#include
#include
#include
#include "NLPIR.h"
#include
using namespace std
void IfInit()//判断是否已经成功初始化
void IfExit()//是否成功退出
int main()
{
IfInit()//初始化程序
NLPIR_SetPOSmap(ICT_POS_MAP_SECOND)
int nitems//
nitems=NLPIR_ImportUserDict("H:\\sentence\\UserDict_manual.txt")
NLPIR_SaveTheUsrDic()
cout<<"import "<<nitems<<"
words"<<endl
//NLPIR_AddUserWord("A股")
//NLPIR_AddUserWord("沪指")
//int i
//char s[100]
//char s2[100]
//ifstream infile
////infile.open("H:\\sentence\\files to break
word.txt")
//infile.open("C:\\Users\\pc\\Desktop\\temp\\file_to.txt")
//ifstream infile2
////infile2.open("H:\\sentence\\files after break
word.txt")
//infile2.open("C:\\Users\\pc\\Desktop\\temp\\file_after.txt")
//for(i=0i<717696i++)//1798
//橘银{
// if (i<350000)
// {
// infile.getline(s,100)
// infile2.getline(s2,100)
// continue
// }
// infile.getline(s,100)
// infile2.getline(s2,100)
// NLPIR_FileProcess(s,s2,0)
// cout<<i+1<<endl
//}
NLPIR_FileProcess("try.txt","try_result.txt",0)
IfExit()//退出
system("pause")
return 0
}
void IfInit()//判断是否已经成功初始化
{
if(!NLPIR_Init(0,UTF8_CODE))
{
cout<<"Init fails"<<endl
exit(EXIT_FAILURE)
}
else
{
cout<<"Init ok"<<endl
}
}
void IfExit()//是否成功退出
{
if(!NLPIR_Exit())
{
cout<<"Exit fails"<<endl
}
else
{
cout<<"Exit ok"<<endl
}
}
8.若函数报错,可以去text-segmentation文件夹中的text-segmentation文件夹下查看log文件。常见的错误是Initial
Fail,这很可能是因为license过期了,解决方法可见http://blog.csdn.net/heyu158/article/details/17525753
。
没有挂网公布,需要咨询专业人士。
C语言是一门面向过程的、抽象化的通用程序设计语言,广泛应用于底层开发。C语言能以简易的方式编译、处理低级存储器。
C语言是仅产生少量的机器语言以及不需要任何运行环境支持便能运行的高档哪效率程序设计语言。尽管C语言提供了许多低级处理的功能,但仍然保持着跨平台的特性,以一个标准规格写出的C语言程序可在包括类似嵌入式处理器以及超级计算机等作业平台的许多计算机平台上进行编译。
C语言诞生于美国的贝尔实验室,由丹尼斯·里奇(Dennis MacAlistair Ritchie)以肯·汤普森(Kenneth Lane Thompson)设计拿指的B语言为基础发展而来,在它的主体设计完成后,汤普逊和里奇用它完全重写了UNIX,且随着UNIX的发展,c语言也得到了不断的完善。
为了利于C语言的全面推广,许多专家学者和硬件厂商联合组成了C语言标准行敏码委员会,并在之后的1989年,诞生了第一个完备的C标准,简称“C89”,也就是“ANSI C”,截至2020年,最新的C语言标准为2018年6月发布的“C18”。
public class Indexer {private IndexWriter writer
private Analyzer analyzer
public Indexer(String indexDir) throws IOException {
Directory dir = FSDirectory.open(new File(indexDir))
analyzer = new SmartChineseAnalyzer(Version.LUCENE_35, true)// 中文分词
writer = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED)
}
//纤丛 建立索引
public void indexFile(File f) throws Exception {
System.out.println("Indexing " + f.getCanonicalPath())
Document doc = getDocument(f)
writer.addDocument(doc)
}
// 输出关键词文本内容
public void getTermText(String fieldName, String text) {
TokenStream stream = analyzer.reusableTokenStream(fieldName, new StringReader(text))// 重用流,脊竖碰以便提速性樱谈能
CharTermAttribute charTerm = stream.addAttribute(CharTermAttribute.class)// 获取关键词
String word
while(stream.incrementToken()) {
word = charTerm.toString()
System.out.print(word + " ")
}
}
protected Document getDocument(File f) throws Exception {
Document doc = new Document()
doc.add(new Field("contents", new FileReader(f)))
doc.add(new Field("filename", f.getName(),
Field.Store.YES, Field.Index.NOT_ANALYZED))
doc.add(new Field("fullpath", f.getCanonicalPath(),
Field.Store.YES, Field.Index.NOT_ANALYZED))
return doc
}
}
imdict-chinese-analyzer - imdict智能词典所采用的智能中文分词程序
http://code.google.com/p/imdict-chinese-analyzer/
这些应该对你有用。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)