噼里啪啦调了两周,网上的资源各种试,终于在今天下午调试成功。由于只需要nutch的索引功能,因此,nutch选择了1.0版本,在myeclipse中调试,具体过程如下:

1.配置java环境,网上资料巨多,不再赘述,这步不成功,就不用往下了;

2.下载Cygwin工具:http://www.cygwin.com并安装Cygwin.安装成功后,记得在我的电脑属性中配置环境变量:编辑path属性,加入d:cygwin/bin到path中.注:这步的环境变量不配置,后期运行会出错哦,找不到bash什么的(如果在Cygwin下运行,可以cd进入到bin下运行,但在myeclipse中运行,最好还是配置一下环境变量)

3.下载nutch软件包:http://labs.renren.com/apache-mirror//nutch/,这里下载的是nutch1.0版本

4.下载Javacc(用于在添加中文分词时编译NutchAnalysis.jj)

5.下载imdict-chinese-analyzer(中科院java版的分词工具)

6.将nutch导入myeclipse中,具体操作如下:

6.1File》New》Project...选择“Java Project from Existing Ant Buildfile”,点击“next”,在Ant buildfile的Browse...中选择nutch软件包中的build.xml,Project  name 随意了,然后“finish”!

6.2.修改nutch工程conf文件夹下的nutch-site.xml,本人的文件如下:

<span style="font-size:18px;"><?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!-- Put site-specific property overrides in this file. --><configuration>
<property>
<name>http.agent.name</name>
<value>Nutch</value>
<description>HTTP'User-Agent'request header.MUST NOT be empty-please set this to a single word uniquely related to your organization.
NOTE:You should also check other related properties:
http.robots.agents
http.agent.description
http.agent.url
http.agent.email
http.agent.version
and set their values appropriately.
</description>
</property>
<!--file properties-->
<property>
<name>searcher.dir</name>
<value>D:\nutch-1.0\localweb</value>
<description></description>
</property>
<property><name>http.robots.agents</name><value>Nutch,*</value><description>The agent strings we'll look for in robots.txt files,comma-separated, in decreasing order of precedence.You should put the value of http.agent.name as the first agent name, and keep the default * at the end of the list.E.g:BlurflDev,Blurfl,*
</description>
</property>
<property><name>http.agent.description</name><value>Nutch Search Engineer</value><description>Further description of our bot-this text is used in the User-Agent header.It appears in parenthesis after the agent name.</description>
</property>
<property><name>http.agent.url</name><value>http://lucene.apache.org/nutch/bot.html</value><description>A URL to advertise in the User-Agent header. This will appear in parenthesis after the agent name. Custom dictates that this should be a URL of a page explaining the purpose and behavior of this crawler.</description>
</property>
<property><name>http.agent.email</name><value>nutch-agent@lucene.apache.org</value><description>An email address to advertise in the HTTP 'From' request header and User-Agent header.A good practice is to mangle this address(e.g.'info at example dot com')to avoid spamming.</description>
</property>
<property><name>http.agent.version</name><value>1.0</value>
</property>
</configuration>
</span>

6.3修改crawl-urlfilter.txt,本人文件如下:

<span style="font-size:18px;"># The url filter file used by the crawl command.# Better for intranet crawling.
# Be sure to change MY.DOMAIN.NAME to your domain name.# Each non-comment, non-blank line contains a regular expression
# prefixed by '+' or '-'.  The first matching pattern in the file
# determines whether a URL is included or ignored.  If no pattern
# matches, the URL is ignored.# skip file:, ftp:, & mailto: urls
-^(file|ftp|mailto):# skip image and other suffixes we can't yet parse
-\.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$# skip URLs containing certain characters as probable queries, etc.
-[?*!@=]# skip URLs with slash-delimited segment that repeats 3+ times, to break loops
-.*(/.+?)/.*?\1/.*?\1/# accept hosts in MY.DOMAIN.NAME
+^</span>

6.4nutch工程根目录下建立weburls.txt,里面输入待检索的地址如:http://www.baidu.com,可以多个,一行写一个哦

备注:关于6.2,6.3,6.4处有问题的亲们,请自行百度,这部分资源很丰富
6.5nutch工程右键选择build path》Configure build path,Libraries中选择Add Class Folder...选择conf文件(这步很重要)

7.运行一下,在Run confgurations中Main class 处输入org.apache.nutch.crawl.Crawl,Arguments中的Program arguments中写入:weburls.txt -dir localweb -depth 3 -topN 100,VM arguments中写入:-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log -Xms256m -Xmx1024m

8.至此,完成了nutch在myeclipse中的部署运行,运行完成后,可以借助luke工具查看根目录下localweb文件夹中生成的索引。接下来开始增加中文分词功能:

首先,需要在myeclipse中把imdict-chinese-analyzer打包成jar包。

下载来的imdict-chinese-analyzer-java5.zip里面只是一个eclipse工程,我们要利用这个工程生成一个jar来用,或者也可以直接放到nutch的源代码项目中。这里注意的是如果要编译imdict-chinese-analyzer-java5.zip需要在项目中加入lucene-core-2.4.0.jar  和junit-4.1.jar。同时,需要在org.apache.lucene.analysis.cn包下建立stopwords.txt文件,在org.apache.lucene.analysis.cn.smart.hhmm下需要有bigramdict.mem和coredict.mem文件,这两个文件网上都可以下载到。全部添加完成之后再导出为chinese-analyzer.jar

其次,将jar放入nutch的lib文件夹下,并build path 配置路径

第三,添加中文分词

  1. 修改org.apache.nutch.analysis下NutchAnalysis.jj文件。

    | <SIGRAM: <CJK> >
    改成
    | <SIGRAM: (<CJK>)+ >

    然后用javacc编译NutchAnalysis.jj文件,编译出7个java源文件。(编译方法:CMD进入到javacc的bin文件夹下,javacc NutchAnalysis.jj)

  2. 将这7个文件放到nutch的源工程中,修改org.apache.nutch.analysis.ParseException.java。
    原来是

    Java代码  
    1. public class ParseException extends Exception

    改成

    Java代码  
    1. public class ParseException extends java.io.IOException

    因为nutch原来的这个源文件就是这么写的,用jj文件编译出来的源文件就不对,不改的话会提示ParseException 未被捕获。

  3. 确保这7个文件放入工程后还能都编译过去。
  4. 修改org.apache.nutch.analysis.NutchDocumentAnalyzer.java
    将源文件最后的那个函数修改为下面
    就是使用了新的分词程序。
  5. Java代码  
    1. /** Returns a new token stream for text from the named field. */
    2. public TokenStream tokenStream(String fieldName, Reader reader) {
    3. Analyzer analyzer;
    4. /*
    5. if ("anchor".equals(fieldName))
    6. analyzer = ANCHOR_ANALYZER;
    7. else
    8. analyzer = CONTENT_ANALYZER;
    9. */
    10. analyzer = new org.apache.lucene.analysis.cn.SmartChineseAnalyzer(true);
    11. //
    12. return analyzer.tokenStream(fieldName, reader);
    13. }
  6. 在build.xml中添加chinese-analyzer.jar,如下:
<span style="font-size:18px;"><lib dir="${lib.dir}"><include name="lucene*.jar"/><include name="taglibs-*.jar"/><include name="hadoop-*.jar"/><include name="dom4j-*.jar"/><include name="xerces-*.jar"/><include name="tika-*.jar"/><include name="apache-solr-*.jar"/><include name="commons-httpclient-*.jar"/><include name="commons-codec-*.jar"/><include name="commons-collections-*.jar"/><include name="commons-beanutils-*.jar"/><include name="commons-cli-*.jar"/><include name="commons-lang-*.jar"/><include name="commons-logging-*.jar"/><include name="log4j-*.jar"/><include name="chinese-analyzer.jar"/></lib><lib dir="${lib.dir}"><include name="lucene*.jar"/><include name="taglibs-*.jar"/><include name="hadoop-*.jar"/><include name="dom4j-*.jar"/><include name="xerces-*.jar"/><include name="tika-*.jar"/><include name="apache-solr-*.jar"/><include name="commons-httpclient-*.jar"/><include name="commons-codec-*.jar"/><include name="commons-collections-*.jar"/><include name="commons-beanutils-*.jar"/><include name="commons-cli-*.jar"/><include name="commons-lang-*.jar"/><include name="commons-logging-*.jar"/><include name="log4j-*.jar"/><include name="chinese-analyzer.jar"/></lib></span>
到这里,还差一步,把bigramdict.dct文件放在根目录下,否则会报错,由于找不到bigramdict.dct文件而抛出异常!!!
OK了,用刚才同样的方法运行吧,可以看到已经实现中文分词了哦
说明:爬取的起点链接会影响到分词效果,如果没有看到分词效果,可以尝试换个链接,本人的测试时链接只使用http://www.sina.com.cn时看不到分词效果,增加链接http://www.csdn.net后看到了分词效果!

nutch添加imdict-chinese-analyzer实现中文分词相关推荐

  1. java Analyzer_Java实现使用IK Analyzer实现中文分词

    lucene-core-3.6.0.jar 什么都不用改 示例代码如下(使用IK Analyzer): [java] view plaincopy package com.haha.test; imp ...

  2. jieba库 python2.7 安装_Python中文分词工具大合集:安装、使用和测试

    这篇文章事实上整合了前面两篇文章的相关介绍,同时添加一些其他的Python中文分词相关资源,甚至非Python的中文分词工具,仅供参考. 首先介绍之前测试过的8款中文分词工具,这几款工具可以直接在AI ...

  3. 资源 | Python中文分词工具大合集

    跟着博主的脚步,每天进步一点点 这篇文章事实上整合了之前文章的相关介绍,同时添加一些其他的Python中文分词相关资源,甚至非Python的中文分词工具,仅供参考. 首先介绍之前测试过的8款中文分词工 ...

  4. Python中文分词工具大合集:安装、使用和测试

    转自:AINLP 这篇文章事实上整合了之前文章的相关介绍,同时添加一些其他的Python中文分词相关资源,甚至非Python的中文分词工具,仅供参考. 首先介绍之前测试过的8款中文分词工具,这几款工具 ...

  5. python 分词工具训练_Python中文分词工具大合集:安装、使用和测试

    这篇文章事实上整合了前面两篇文章的相关介绍,同时添加一些其他的Python中文分词相关资源,甚至非Python的中文分词工具,仅供参考. 首先介绍之前测试过的8款中文分词工具,这几款工具可以直接在AI ...

  6. 给solr配置中文分词器

    Solr的中文分词器 中文分词在solr里面是没有默认开启的,需要我们自己配置一个中文分词器. 目前可用的分词器有smartcn,IK,Jeasy,庖丁.其实主要是两种,一种是基于中科院ICTCLAS ...

  7. SOLR配置默认的一元分词与安装主流的中文分词扩展

    引言:SOLR用的好不好,分词是关键,分词分的好不好,词库是关键.没有完美的分词和词库,只有更适合你网站的分词和词库. 目前网络上主流的SOLR分词模块: 1.庖丁分词:PAODING 参考地址:ht ...

  8. 大创项目学习日志(一)——中文分词软件的选择与尝试

    我现在愈发觉得,互联网应该有一个垃圾回收机制--技术性的博客因为软件版本的更新早已不再适用,但却仍然占据着搜索的结果.也许以后会有一种新的计算机职业--网络清洁工.他们可以熟练地运用各种技术手段保持网 ...

  9. 四款python中文分词系统简单测试

    四款python中文分词系统简单测试: 注:中科院分词可采用调用C库的方式使用 纠正下:中科院分词2012支持关键词提取 准确率测试(使用对应项目提供在线测试,未添加用户自定义词典) 结巴中文分词ht ...

  10. Nutch 分词 中文分词 paoding 疱丁

    Nutch中文分词总结 2009年06月10日 星期三 22:38 1 中文分词介绍 中文分词是在做检索类系统时需要重点考虑的一个因素.Nutch的本土化过程也需要更改对中文分词的支持.目前,Nutc ...

最新文章

  1. pandas loc iloc用法
  2. 12岁女孩零编程经验开发系统千人用,80岁初代程序员300多天打卡学AI
  3. java监控队列_java-Spring Rabbit监听输出队列或接收
  4. c语言程序开发中连接是,C语言中等待socket连接和对socket定位的方法
  5. Visual Studio 2015安装教程(附激活码)
  6. 智慧树omg期末测试答案_智慧树答案广告文案写作单元期末见面课知到章节测试答案...
  7. RabbitMQ之惰性队列(Lazy Queue)
  8. Mysql数据库(三)——mysql数据库高级操作
  9. CCF201403-2 窗口
  10. 简易版的strutsdemo
  11. 25年面试官首次揭秘——世界500强面试题之微软面试题
  12. labview用户登录与管理界面设计
  13. 云计算虚拟化特点和了解
  14. 无插件使用Eclipse和Resin调试WEB应用(Debug Web App In Ecli...
  15. 支付宝扫五福,你扫了吗
  16. python控制流实例_python学习笔记系列----(二)控制流
  17. 阿里云服务器ECS开放8080端口
  18. Leetcode 1774. Closest Dessert Cost 枚举法 vector 中的insert方法
  19. java怎么获取索引值,Java 实例 - 获取向量元素的索引值
  20. 什么是et文件?如何将et文件转成PDF格式

热门文章

  1. 图片转Excel表格 文字识别 表格识别
  2. PS2019工具介绍笔记(一)
  3. 网络1711班 C语言第七次作业批改总结
  4. 直流斩波电路在matlab中的建模与仿真,毕业设计直流斩波电路的MATLAB建模与仿真...
  5. 使用postfix和roundcube搭建webemail
  6. 在windows系统调试ydlidar详细记录(物联网机器人方向)
  7. 用java实现皮尔逊相关系数计算
  8. PS教程:如何设置水彩效果?
  9. 日系P2P原理探究(二) — Winny, 日本崛起
  10. BKMGT你懂吗?那么RPWT你懂吗?