Plugin中心(翻译)
plugin(插件)为nutch提供了一些功能强大的部件,举个例子,HtmlParser就是使用比较普遍的用来分析nutch抓取的html文件的插件。
为什么nutch要使用这样的plugin系统?
有三个原因:
1:可扩展性
通过plugin,nutch允许任何人扩展它的功能,而我们要做的只是对给定的接口做简单的实现,举个例子:MSWordParser这个插件是用来分析wordwendang的,它就是一个对parser这个接口的实现
2:灵活性
因为每个人都可以根据自己的需求而写自己的plugin,这样plugin就会有一个很强大的资源库。这样对与应用nutch程序员来说,他可以在自己的搜索引擎上安装符合自己需求的插件,而这些插件就在nutch的plugins中。这对于正在应用nutch的开发者来说应该是一个巨大的福音,因为你有了更多的关于内容抽取的算法来选择,很容易就增加了pdf的分析。
3:可维护性
每个开发者只要关注自己的问题。对于内核的开发者在为引擎内核扩展的同时,为a plug添加一个描述它的接口就可以了。一个plugin的开发者只要关注这个plugin所要实现的功能,而不需要知道整个系统是怎么工作的。它们仅仅需要知道的是plugin和plug之间交换的数据类型。这使得内核更加简单,更容易维护。
plugin相关--什么是plugin,plugin的工作原理<o:p></o:p>
nutch的plugin系统是基于Eclipse 2.x中对插件的使用。plugins对nutch的工作是很重要的。所有的nutch中的parsing(分析),indexing(索引),searching(查询)都是通过不同的plugins来实现的。
在编写一个plugin的时候,你要为一个扩展点添加一个或者更多的扩展项。这些Nutch的扩展点是Nutch在一个plugin中已经定义好了,这个plugin是NutchExtensionPoints(所有的扩展点都会在NutchExtensionPoints plugin.xml这个文件中列出)。每一个扩展点都定义了一个接口,这个接口在扩展时必须被实现。这些扩展点如下:
onlineClusterer-为在线的查询结果提供分组算法的扩展点的接口
indexingFiltering-允许为所索引中的Field添加元数据。所有的实现了这个接口plugin会在分析的过程中顺序的逐个运行
Ontology Parser
实现这个接口的parser读取所抓取的document,摘取将被索引的数据。如果你要在nutch中为扩展分析一个新内容类型或者从现有的可分析的内容摘取更多的数据。
HtmlParseFilter
为html parser添加额外的元数据
protocol
实现Protocol的plugin可以使得nutch能使用更多的网络协议(ftp,http)去抓取数据
QueryFilter
为查询转换的扩展点
URLFileter
实现这个扩展点的plugin会对nutch要抓取的网页的urls进行限制,RegexURLFilter提供了通过正则表达式来对Nutch爬行网页的urls的控制。如果你对urls还有更加复杂的控制要求,你可以编写对这个urlfilter的实现
NutchAnalyser
为许多语言特定的分析器提供了扩展点
源文件
在plugin的源文件目录中你会找到以下的文件
plugin.xml 向nutch描述这个plugin的信息
build.xml 告诉ant怎样编译这个plugin
plugin的源码
在Nutch使用plugin
如果要在Nutch使用一个给定的plugin,你需要对conf/nutch-site.xml进行编辑并且把plugin的名字添加到plugin.includes中
Nutch plugin系统中的一些概念
<o:p> </o:p>
编写一个pluginExample
思考编写这样的一个plugin:我们想为一个给定的search term推荐一些与之相关的网页。举个例子,假设我们正在索引网页,当我们注意到有一组网页的内容是关于plugin的,所以我们想如果当某人查询 plugin的时候,我们可以推荐他到pluginCentral这个网页,但是同时,也要返回在一般逻辑中的查询结果所有的hits。所以我们将查询结果分成了推荐结果和一般查询结果。
你浏览你的网页然后把一个meta-tags加入网页中,它会告诉plugin这个网页是应该被推荐的。这个tags应该像这样<meta name="recommended" content="plugins" />为了达到目标我们需要写一个plugin,这个plugin扩展3个不同的扩展点,它们是:HTMLParser:从meta-tags得到推荐的termsIndexingFilter:增加一个推荐Field在索引中。QueryFilter:增加对索引中新Field的查询能力 要建立的文件 首先在plugin的目录中新建一个目录来盛放自己的的plugin,整个plugin我们取名为recommended,然后在这个目录里面 依次建立以下文件: a plugin.xml,这个文件用来向Nutch描述我们新建的plugin a build.xml这个文件告诉编译器应该怎样build这个plugin plugin的源代码则保存在/src/java/org/apache/nutch/parse/recommended/[这里] Plugin.xml
你所建立的plugin.xml应该这样:
<?xml version="1.0" encoding="UTF-8"?><plugin id="recommended" name="Recommended Parser/Filter" version="<st1:chsdate month="12" islunardate="False" day="30" year="1899" w:st="on" isrocdate="False">0.0.1</st1:chsdate>" provider-name="nutch.org"> <runtime> <!-- As defined in build.xml this plugin will end up bundled as recommended.jar --> <library name="recommended.jar"> <export name="*"/> </library> </runtime> <!-- The RecommendedParser extends the HtmlParseFilter to grab the contents of any recommended meta tags --> <extension id="org.apache.nutch.parse.recommended.recommendedfilter" name="Recommended Parser" point="org.apache.nutch.parse.HtmlParseFilter"> <implementation id="RecommendedParser" class="org.apache.nutch.parse.recommended.RecommendedParser"/> </extension> <!-- TheRecommendedIndexer extends the IndexingFilter in order to add the contents of the recommended meta tags (as found by the RecommendedParser) to the lucene index. --> <extension id="org.apache.nutch.parse.recommended.recommendedindexer" name="Recommended identifier filter" point="org.apache.nutch.indexer.IndexingFilter"> <implementation id="RecommendedIndexer" class="org.apache.nutch.parse.recommended.RecommendedIndexer"/> </extension> <!-- The RecommendedQueryFilter gets called when you perform a search. It runs a search for the user's query against the recommended fields. In order to get add this to the list of filters that gets run by default, you have to use "fields=DEFAULT". --> <extension id="org.apache.nutch.parse.recommended.recommendedSearcher" name="Recommended Search Query Filter" point="org.apache.nutch.searcher.QueryFilter"> <implementation id="RecommendedQueryFilter" class="org.apache.nutch.parse.recommended.RecommendedQueryFilter" fields="DEFAULT"/> </extension></plugin> Build.xml
<?xml version="1.0"?><project name="recommended" default="jar"> <import file="../build-plugin.xml"/></project>
<o:p> </o:p>
The HTML Parser Extension
这是对HtmlParserExtension这个扩展点的实现,它的作用是抓取那些标meta-tags的内容,这样把它们加入正在分析的document中。.
package org.apache.nutch.parse.recommended;// JDK importsimport java.util.Enumeration;import java.util.Properties;import java.util.logging.Logger;// Nutch importsimport org.apache.nutch.parse.HTMLMetaTags;import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.HtmlParseFilter;import org.apache.nutch.protocol.Content;import org.apache.nutch.util.LogFormatter;public class RecommendedParser implements HtmlParseFilter { private static final Logger LOG = LogFormatter .getLogger(RecommendedParser.class.getName()); /** The Recommended meta data attribute name */ public static final String META_RECOMMENDED_NAME="Recommended"; /** * 在html文件中寻找有没有标有meta-tags的内容 */ public Parse filter(Content content, Parse parse, HTMLMetaTags metaTags, DocumentFragment doc) { // Trying to find the document's recommended term String recommendation = null; Properties generalMetaTags = metaTags.getGeneralTags(); for (Enumeration tagNames = generalMetaTags.propertyNames(); tagNames.hasMoreElements(); ) { if (tagNames.nextElement().equals("recommended")) { recommendation = generalMetaTags.getProperty("recommended"); LOG.info("Found a Recommendation for " + recommendation); } } if (recommendation == null) { LOG.info("No Recommendataion"); } else { LOG.info("Adding Recommendation for " + recommendation); parse.getData().getMetadata().put(META_RECOMMENDED_NAME, recommendation); } return parse; }}The Indexer Extension
这是对索引点的扩展,如果查找到带有meta-tags的内容,就把它命名''recommended'的field中,然后加入document建立索引
package org.apache.nutch.parse.recommended;// JDK importimport java.util.logging.Logger;// Nutch importsimport org.apache.nutch.util.LogFormatter;import org.apache.nutch.fetcher.FetcherOutput;import org.apache.nutch.indexer.IndexingFilter;import org.apache.nutch.indexer.IndexingException;import org.apache.nutch.parse.Parse;// Lucene importsimport org.apache.lucene.document.Field;import org.apache.lucene.document.Document;public class RecommendedIndexer implements IndexingFilter { public static final Logger LOG = LogFormatter.getLogger(RecommendedIndexer.class.getName()); public RecommendedIndexer() { } public Document filter(Document doc, Parse parse, FetcherOutput fo) throws IndexingException { String recommendation = parse.getData().get("Recommended"); if (recommendation != null) { Field recommendedField = Field.Text("recommended", recommendation); recommendedField.setBoost(<st1:chmetcnv hasspace="False" numbertype="1" negative="False" sourcevalue="5" unitname="F" w:st="on" tcsc="0">5.0f</st1:chmetcnv>); doc.add(recommendedField); LOG.info("Added " + recommendation + " to the recommended Field"); } return doc; }}The QueryFilter
当用户进行查找操作的时候,QueryFilter就会被调用,而且对于recommeded中的boost值会影响查询结果的排序。
<o:p> </o:p>
package org.apache.nutch.parse.recommended;import org.apache.nutch.searcher.FieldQueryFilter;import java.util.logging.Logger;import org.apache.nutch.util.LogFormatter;public class RecommendedQueryFilter extends FieldQueryFilter { private static final Logger LOG = LogFormatter .getLogger(RecommendedParser.class.getName()); public RecommendedQueryFilter() { super("recommended", <st1:chmetcnv hasspace="False" numbertype="1" negative="False" sourcevalue="5" unitname="F" w:st="on" tcsc="0">5f</st1:chmetcnv>); LOG.info("Added a recommended query"); }} 让Nutch可以使用你的plugin为了让Nutch使用你的plugin,你需要对conf/nuthc-site.xml这个文件进行编辑,把以下的代码加入<property> <name>plugin.includes</name> <value>nutch-extensionpoints|protocol-http|urlfilter-regex|parse-(text|html)|index-basic|query-(basic|site|url)|recommended</value> <description>Regular expression naming plugin directory names to include. Any plugin not matching this expression is excluded. In any case you need at least include the nutch-extensionpoints plugin. By default Nutch includes crawling just HTML and plain text via HTTP, and basic indexing and search plugins. </description></property> 使用Ant对你的plugin进行编译在之前我们要编辑一下src/plugin/build.xml 这个文件,这是对编译和部署做一些设置你会看到有很多如下形式的行<ant dir="[plugin-name]" target="deploy" />在</target>前添加一新行 <ant dir="reccomended" target="deploy" />Running 'ant' in the root of your checkout directory should get everything compiled and jared up. The next time you run a crawl your parser and index filter should get used.
You'll need to run 'ant war' to compile a new ROOT.war file. Once you've deployed that, your query filter should get used when searches are performed.
<o:p> </o:p>
plugins和class加载到nutch的问题集合
对plugin开发者来说最棒的事情就是自由了,可以不去理会别的plugin的开发者在做什么,可以自由的使用第三方的jar库。
nutch是怎样解决类加载这个问题的?
Nutch使用了一个非常容易的方法,每一个plugin都有一个属于自己的类加载器,这个class-loader在plugin启动以前将会被初始化 写plugin-by stefan
nutch 0.7中的plugins
如果你要在nutch中应用这些插件,你只需要编辑conf/nutch-site.xml,把你所要用的plugin的名字加入plugin.includes的列表中
clustering-carrot2 - Online Search Results Clustering using Carrot2's Lingo component.
creativecommons - Support for crawling and searching Creative-Commons licensed content.
index-basic - Adds url, content and anchor fields to the index.
index-more - Adds date, content-length, contentType, primaryType and subtype fields to the index.
languageidentifier - Adds a lang field to the index and allows you to query against it.
ontology - Helps refine queries based on owl files.
parse-ext - A wrapper that invokes external command to do real parsing job.
parse-html - Parses HTML documents
parse-js - Parses JavaScript
parse-mp3 - Parses MP3s
parse-msword - Parses MS Word documents
parse-pdf - Parses PDFs
parse-rss - Parses RSS feeds
parse-rtf - Parses RTF files
parse-text - Parses text documents
protocol-file - Retreives documents from the filesystem
protocol-ftp - Retreives documents through ftp
protocol-http - Retreives documents through http
protocol-httpclient - Retreives documents through http and https
query-basic - Runs queries against content, url and anchor fields
query-more - Runs queries against date, content-length, contentType, primaryType and subType fields.
query-site - Runs queries against site field
query-url - Runs queries against url field.
urlfilter-prefix
urlfilter-regex
Additional Plugins in Dev Branch (0.8)
analysis-de
analysis-fr
lib-commons-httpclient
lib-http
lib-jakarta-poi
lib-log4j
lib-lucene-analyzers
lib-nekohtml
lib-parsems
parse-msexcel - Parses MS Excel documents
parse-mspowerpoint - Parses MS Powerpoint documents
parse-oo - Parses Open Office and Star Office documents (Extentsions: ODT, OTT, ODH, ODM, ODS, OTS, ODP, OTP, SXW, STW, SXC, STC, SXI, STI)
parse-swf - Parses Flash SWF files
microformats-reltag - Adds rel-tag fields to the index and runs queries against them.
parse-zip
clustering-carrot2
<o:p> </o:p>
分享到:
相关推荐
Nutch Htmlunit Plugin 重要说明: 当前项目基于Nutch 1.X系列已停止更新维护,转向Nutch 2.x系列版本的新项目:http://www.oschina.net/p/nutch-ajax 项目简介 基于Apache Nutch 1.8和Htmlunit...
Nutch 是一个开源的、Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。 目 录 1. nutch简介...1 1.1什么是nutch..1 1.2研究nutch的原因...1 1.3 nutch的目标..1 1.4 nutch VS lucene.....2 2....
nutch插件机制 实例讲解 轻松学习 扩展nutch功能 随意添加扩展
Nutch 1.x插件,允许对网页的入站和出站进行索引。 默认情况下,此插件会忽略那些主机与被索引网页的主机匹配的出站链接。 通过将以下内容添加到您的nutch-site.xml可以绕过此行为。 < name>outlinks.host.ignore...
Nutch 是一个开源的、Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。 目 录 1. nutch简介...1 1.1什么是nutch..1 1.2研究nutch的原因...1 1.3 nutch的目标..1 1.4 nutch VS lucene.....
-----------------------------Nutch Htmlunit Plugin项目简介基于Apache Nutch 1.8和Htmlunit组件,实现对于AJAX加载类型页面的完整页面内容抓取解析。According to the implementation of Apache Nutch 1.8, we ...
新闻提取器 Nutch插件,用于从格式良好的新闻网站中提取新闻报道。
Nutch AJAX page Fetch, Parse, Index Plugin项目简介基于Apache Nutch 2.3和Htmlunit, Selenium WebDriver等组件扩展,实现对于AJAX加载类型页面的完整页面内容抓取,以及特定数据项的解析和索引。According to the...
you will encouter problems with some imports in parse-mp3 and parse-rtf plugins in nutch project. please copy the jar files into src/plugin/parse-mp3/lib and src/plugin/parse-rtf/lib respectively.
rtf-parse.jar、jid3lib-0.5.4.jar,nutch编译需要的jar文件
Nutch插件 Jobs Crawler的Nutch插件。
Nutch AJAX page Fetch, Parse, Index Plugin项目简介基于Apache Nutch 2.3和Htmlunit, Selenium WebDriver等组件扩展,实现对于AJAX加载类型页面的完整页面内容抓取,以及特定数据项的解析和索引。According to the...
注意:此项目包括完整的 Nutch 1.6 版本,此插件放置在 /src/plugin/parse-anthAnthelion 使用在线学习方法来基于页面上下文预测富数据 Web 页面,从之前查看的页面提取的元数据获取反馈。主要有三个扩展:...
jid3lib-0.5.4.jar,编译nutch0.9,有两个plugin编译不能通过,mp3,rtf插件编译,找不到jar,这是其中一个