盘古分词修改支持mono和lucene.net3.03
盘古分词平台兼容性
在使用Lucece.net,需要一个中文的分词组件,比较好的是盘古分词,但是我希望能够在mono的环境下运行,就使用moma检查了一下盘古分词
Assembly Version Missing Not Implemented Todo P/Invoke
PanGu.dll 2.3.1.0 3 0 5 0
Calling Method Method Missing from Mono
WordInfo> PreSegment (string) string Strings.StrConv (string, VbStrConv, int)
WordInfo> PreSegment (string) string Strings.StrConv (string, VbStrConv, int)
WordInfo> PreSegment (string) string Strings.StrConv (string, VbStrConv, int)
Calling Method Method with [MonoTodo] Reason
string ReadFileToString (string, Encoding) int Marshal.GetHRForException (Exception) SetErrorInfo
MemoryStream ReadFileToStream (string) int Marshal.GetHRForException (Exception) SetErrorInfo
void WriteStream (string, MemoryStream) int Marshal.GetHRForException (Exception) SetErrorInfo
void WriteLine (string, string) int Marshal.GetHRForException (Exception) SetErrorInfo
void WriteString (string, string, Encoding) int Marshal.GetHRForException (Exception) SetErrorInfo
是StrConv这个函数没有检查通过,发现作者使用了 Microsoft.VisualBasic.Strings.StrConv 这个类库来处理简体和繁体转换的问题,这个类用到了windows平台的特性,所以没有编译通过,于是写了个简单的简体繁体转换的类库:简体中文与繁体相互转换.
是一个Marshal.GetHRForException 用来做io处理出错的时候判断的,代码如下大概是出现了ERR_PROCESS_CANNOT_ACCESS_FILE错误时让线程稍等。代码如下
uint hResult = (uint)System.Runtime.InteropServices.Marshal.GetHRForException(e);
if (hResult == ERR_PROCESS_CANNOT_ACCESS_FILE)
{
if (times > 10)
{
//Maybe another program has some trouble with file
//We must exit now
throw e;
}System.Threading.Thread.Sleep(200);
times++;
}
else
{
throw e;
}
查找MSDN在Marshal,如何:映射 HRESULT 和异常 里面有一句话 :
COM 方法通过返回 HRESULT 来报告错误;.NET 方法则通过引发异常来报告错误。 运行时将处理这两者之间的转换。 .NET Framework 中的每个异常类都会映射到一个 HRESULT。
也就是说HRESULT是给com来报告错误的,.net本身通过引发异常来处理错误,而这个IOException对应出来的hresult是
文件“xxxx”正由另一进程使用,因此该进程无法访问此文件。
但是引起这个错误的异常根源就是IOException,内部有个私有的HResult无法访问。只能修改为所有的错都等待10次,10次之后抛出异常,所以把外面的if之外的代码都注释掉变成
if (times > 10)
{
//Maybe another program has some trouble with file
//We must exit now
throw e;
}
System.Threading.Thread.Sleep(200);
times++;
这样两个不兼容的问题就解决了。
盘古分词Lucene3.03支持
现在盘古分词给出的Lucene的示例是2.x的版本,而我希望能够用3.0的版本来集成,其中的区别是PanGuTokenizer.cs里面集成的时候会提示Next()方法没有找到合适的类来重写。原因是lucene中next()方法已改成incrementToken()方法.lucene的文档:
This method is called for every token of a document, so an efficient implementation is crucial for good performance. To avoid calls to AttributeSource.addAttribute(Class) and AttributeSource.getAttribute(Class), references to all AttributeImpls that this stream uses should be retrieved during instantiation.
所以只需要修改这个方法,改为使用addAttribute来实现:
这里有一个已经修改好了的pangu分词的版本https://github.com/JimLiu/Lucene.Net.Analysis.PanGu .主要代码如下,其中next还是原来的方法,去掉override.
添加属性
private ITermAttribute termAtt;
private IOffsetAttribute offsetAtt;
private IPositionIncrementAttribute posIncrAtt;
private ITypeAttribute typeAtt;
termAtt = AddAttribute<ITermAttribute>();
offsetAtt = AddAttribute<IOffsetAttribute>();
posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
typeAtt = AddAttribute<ITypeAttribute>();
方法实现
public override bool IncrementToken()
{
ClearAttributes();
Token word = Next();
if (word != null)
{
termAtt.SetTermBuffer(word.Term);
offsetAtt.SetOffset(word.StartOffset, word.EndOffset);
typeAtt.Type = word.Type;
return true;
}
End();
return false;
}
以上就是让lucene.net在mono下使用盘古分词出现的一些问题。
盘古分词修改支持mono和lucene.net3.03的更多相关文章
- lucene.net helper类 【结合盘古分词进行搜索的小例子(分页功能)】
转自:http://blog.csdn.net/pukuimin1226/article/details/17558247 添加:2013-12-25 更新:2013-12-26 新增分页功能. ...
- lucene.net 3.0.3、结合盘古分词进行搜索的小例子(转)
lucene.net 3.0.3.结合盘古分词进行搜索的小例子(分页功能) 添加:2013-12-25 更新:2013-12-26 新增分页功能. 更新:2013-12-27 新增按分类查询功能, ...
- lucene.net 3.0.3、结合盘古分词进行搜索的小例子(分页功能)
转自:http://blog.csdn.net/pukuimin1226/article/details/17558247 添加:2013-12-25 更新:2013-12-26 新增分页功能. 更新 ...
- Lucene.Net+盘古分词->开发自己的搜索引擎
//封装类 using System;using System.Collections.Generic;using System.Linq;using System.Web;using Lucene. ...
- 让盘古分词支持最新的Lucene.Net 3.0.3
原文:让盘古分词支持最新的Lucene.Net 3.0.3 好多年没升级过的Lucene.Net最近居然升级了,到了3.0.3后接口发生了很大变化,原来好多分词库都不能用了,所以上次我把MMSeg给修 ...
- 支持Mono的盘古分词(PanGu)
不废话,直接上下载地址http://files.cnblogs.com/files/RainbowInTheSky/PanGu.rar 群友在做项目移植到Mono+jexus上时遇到了问题,盘古分词无 ...
- Lucene.Net3.0.3+盘古分词器学习使用
一.Lucene.Net介绍 Lucene.net是Lucene的.net移植版本,是一个开源的全文检索引擎开发包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索 ...
- Lucene.Net+盘古分词
前言 各位朋友,谢谢大家的支持,由于文件过大,有考虑到版权的问题,故没有提供下载,本人已建立一个搜索技术交流群:77570783,源代码已上传至群共享,需要的朋友,请自行下载! 首先自问自答几个问题, ...
- lucene+盘古分词
一般的网站都会有都会有搜索的功能,一般实现搜索主要有三种方案 第一种是最差的,也是最不推荐的,使用数据库的模糊查询例如select * form table where 字段 like XXX,这种查 ...
随机推荐
- JUnit 3一个例子就懂
JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture f ...
- jmeter正则表达式提取器--关联
http://desert3.iteye.com/blog/1394934 1.http://www.cnblogs.com/quange/archive/2010/06/11/1756260.htm ...
- vue实现点击关注之后及时更新列表
如图,我要实现点击关注之后列表及时更新成最新的列表. 思路很简单,主要是两点: 1.在点击关注之后去执行一个请求新的关注列表的action: 2.在vue组件中watch监听已关注列表和推荐关注列表 ...
- ubuntu-14.04.2-desktop-i386.iso:ubuntu-14.04.2-desktop-i386:安装Oracle11gR2
ubuntu 桌面版的安装不介绍. 如何安装oracle:核心步骤和关键点. ln -sf /bin/bash /bin/sh ln -sf /usr/bin/basename /bin/basena ...
- 通过MyEclipse部署web应用程序开发环境
1.下载并安装MyEclipse10 2.配置java开发的jar包 3.配置tomcat服务器 4.部署tomcat服务器 点击Bronse可以查看部署后的文件夹目录 5.启动tomcat服务器 6 ...
- ajax之cache血与泪~~
场景:项目以ie5渲染页面,点击导出列表数据(Excel形式),点击导出发送get请求,后台生成Excel文件,返回文件地址信息 异常:ie第一次返回的信息正常,之后返回的都是第一次的结果,googl ...
- Eclipse------用Tomcat运行项目后出现:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
Eclipse中Tomcat运行项目后出现: 严重: Error configuring application listener of class org.springframework.web.c ...
- Xcode文件被锁定:The file ".xcodeproj" could not be unlocked
同事从svn上面checkout项目到本地,通过xcode打开的时候提示的这个问题. The file "xcodeproj" could not be unlocked. Cou ...
- Java 代码块:静态代码块、构造代码块、构造函数块
Class : StaticFa package edu.bai.du.lime.staticCode; public class StaticFa { // 随着类的声明而执行 static { S ...
- >>和<<<区别
1.>>表示右移(有符号右移),如:15>>2的结果是3,-31>>3的结果是-4,左边以该数的符号位补充,移出的部分将被抛弃. 转为二进制的形式可能更好理解(省略 ...