首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Carrot2 API和ComponentInitializationException:无法实例化组件类

使用Carrot2 API和ComponentInitializationException:无法实例化组件类
EN

Stack Overflow用户
提问于 2014-10-24 12:23:37
回答 1查看 251关注 0票数 1

我正试图为一个项目编写一个原型,该项目涉及让java将carrot2用作多个来源的元搜索引擎,例如必应和谷歌等。

我有一个具有依赖性的maven项目:

代码语言:javascript
复制
<dependency>
    <groupId>org.carrot2</groupId>
    <artifactId>carrot2-core</artifactId>
    <version>3.9.3</version>
</dependency>

我试着运行以下内容:

代码语言:javascript
复制
/* A controller to manage the processing pipeline. */
Controller controller = ControllerFactory.createSimple();

/* Input data for clustering, the query and number of results in this case. */
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(AttributeNames.QUERY, "sugar");
attributes.put(AttributeNames.RESULTS, 100);

/* Perform processing */
ProcessingResult result = controller.process(attributes,
        Bing3DocumentSource.class, LingoClusteringAlgorithm.class);

/* Documents fetched from the document source, clusters created by Carrot2. */
List<Document> documents = result.getDocuments();
List<Cluster> clusters = result.getClusters();

我得到的是:

代码语言:javascript
复制
Exception in thread "main" org.carrot2.core.ComponentInitializationException: Could not instantiate component class: org.carrot2.source.microsoft.Bing3DocumentSource
    at org.carrot2.core.SimpleProcessingComponentManager.prepare(SimpleProcessingComponentManager.java:68)
    at org.carrot2.core.Controller.process(Controller.java:341)
    at org.carrot2.core.Controller.process(Controller.java:246)
    at com.jbaysolutions.metasearch.Test.main(Test.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.InstantiationException: org.carrot2.source.microsoft.Bing3DocumentSource
    at java.lang.Class.newInstance(Class.java:359)
    at org.carrot2.core.SimpleProcessingComponentManager.prepare(SimpleProcessingComponentManager.java:55)
    ... 8 more

我正确地使用了API吗?我已经尝试过查看carrot2的文档,但是它很少涉及API的使用,而且这些示例也无法正常工作。

在这里真的需要帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-28 21:45:48

Dawid Weiss在carrot2邮件列表中的回答:

  1. 您正在尝试实例化一个抽象类。除非你是恰克·诺里斯否则不会飞。
  2. 为什么不看一下随项目一起分发的示例呢?这里有一个使用Bing的例子。

https://github.com/carrot2/carrot2/blob/master/applications/carrot2-examples/examples/org/carrot2/examples/clustering/ClusteringDataFromDocumentSources.java#L111

所有示例都在这里,打包并准备好:http://project.carrot2.org/download-java-api.html

  1. 如果您计划使用Bing,请确保使用您自己的应用程序,请(谢谢)。

所涉及的部分是:

代码语言:javascript
复制
ProcessingResult result = controller.process(attributes,
    Bing3DocumentSource.class, LingoClusteringAlgorithm.class);

改为:

代码语言:javascript
复制
ProcessingResult result = controller.process(attributes,
            Bing3WebDocumentSource.class, LingoClusteringAlgorithm.class);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26547802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档