Carrot2 in action 初步印象

RawCluster聚类中的类别单位

RawCluster.getDocuments():获得该类的文档列表

RawDocument:每个类的文档单位

STC:后缀树表示法

 

2008-11-13

Carrot2的组建(components)的介绍:

1.        输入(input):产生聚类文本的组建。Carrot2针对目前的几个主要搜索引擎(Yahoo:carrot2-input-yahooapi.jar, Google, MSN Search)和开源搜索引擎(lucene:carrot2-input-lucene.jar)以及XMLs接口 (such as RSS or OpenSearch:carrot2-input-xml.jar).,提供了几个默认的输入组建。除此之外,你也可以自己重写自己的输入组建。

LocalComponentFactory

LuceneLocalInputComponentConfig

LuceneLocalInputComponentFactoryConfig

// Create Lucene input component factory.

        //

        final LocalComponentFactory input = new LocalComponentFactory() {

            public LocalComponent getInstance() {

                returnnew LuceneLocalInputComponent(luceneConfig);

            }

        };

 

        // add lucene input as 'lucene-myindex'

        controller.addLocalComponentFactory("lucene-myindex", input);

 

 

2.      过滤器(filters: Carrot2中的过滤器其实就是聚类组建和一些过滤操作的集合。Carrot2自带有一定数量的过滤器,每一个过滤器都执行一个不同的算法(如lingo,k-mean and so on),并且根据处理链中,在它之前的过滤器的不同和以及自身配置的不同,每个过滤器会有一些不同的要求设置。Eg:carrot2-filter-lingo.jar,carrot2-filter-haog.jar,carrot2-filter-stc.jar

    final LocalComponentFactory lingo = new LocalComponentFactory() {

            public LocalComponent getInstance() {

                // we will use the defaults here, see {@link Example}

                // for more verbose configuration.

                returnnewChineseLingoLocalFilterComponent();

            }

        };

 

        // add the clustering component as "lingo-classic"

        controller.addLocalComponentFactory("lingo-classic", lingo);

3.      输出(output):当从聚类器获得结果的时候,carrot2用输出组件去对这些结果进行一些处理操作。实际上输出组件处理的是接口“RawCluster”的实例。最简单的处理方式就是把哲学聚类结果保存没在一个数组中,直到所有的聚类操作完成;一个更高级一点的方式就是,聚类结果出来一个马上进行输出处理,而不是放在一个数组中最后统一处理,这种凡是的实质就是一个与聚类操作(filter)的同步。

   final LocalComponentFactory output = new LocalComponentFactory() {

            public LocalComponent getInstance() {

                returnnew ArrayOutputComponent();

            }

        };

        // add the output component as "buffer"

        controller.addLocalComponentFactory("buffer", output);

 

话外话:carrot2中之所以很多地方都用到”Local”来命名,这其实是由于历史原因:在carrot2中曾经设计过一个用于远程通信的并行组建,虽然现在弃用了,但是与之相对的本地组建用“Local”命名的方式一直沿用着。

 

2008-11-14

设计概要

1.       carrot2LocalComponent是一下三种本地组建的超级几口:

LocalInputComponent:用于接受用户的查询和处理初始数据

LocalFilterComponent:用于改变或者丰富数据

LocalOutputComponent:收集聚类结果或者对结果做一些处理,如用可视化组建显示这些结果等等

2.       组建初始化

在任何处理操作之前,组件和处理器(processesLocalProcessBase)被添加到一个组建容器,同时它们也会被一个控制(controller)组件所引用。这个控制组件不会再核心框架中被明确指定,因为它更有可能是应用相关的,即属于应用层,已经超出了限定的范围。然而,在框架中却指定了一个LocalControllerContext接口,并且它会传递给每一个实例化的组建。其实LocalControllerContext主要是用来证实每个组建和处理器之间的兼容性的,同时也为实现一些别的组件类型提供了可能性。

3.      处理器

一个本地处理器包含了处理查询和在处理链中装配组件的逻辑过程。这个接口(LocalProcess)的实例必须由框架的使用者来定义(也就是应用相关),因为他要决定哪些组建要被用于处理查询而他们之间又是如何联系的。LocalProcess的行为规范是十分复杂的,一般鼓励开发者去使用它的子类LocalProcessBase,可以重载它里面的钩子(Hook)函数。

     //

        // In the final step, assemble a process from the above.

        //

        try{

            controller.addProcess("lucene-lingo",

                    new LocalProcessBase("lucene-myindex", "buffer", new String [] {"lingo-classic"}));

        } catch (InitializationException e) {

            // This exception is thrown during verification of the added component chain,

            // when a component cannot properly initialize for some reason. We don't

            // expect it here, so rethrow it as runtime exception.

            thrownew RuntimeException(e);

        } catch (MissingComponentException e) {

            // If you give an identifier of a component for which factory has not been

            // added to the controller, you'll get this exception. Impossible in our

            // example.

            thrownew RuntimeException(e);

        }

 

4.      查询执行

当所有的处理器和组建都添加到控制器之后。控制器就会用一个query()(旧版如下)将一个查询请求传递给本地处理实例。

public void Object query(RequestContext context, String query) throws Exception

  一个处理就会请求一个组件实例并将它同一个处理链联系起来,然后执行查询请求。(转自:http://blog.sina.com.cn/s/blog_43b8e6dd0100ne5z.html)

原文地址:https://www.cnblogs.com/fengweixin/p/3597914.html