我正在尝试为一个项目编写原型,该项目涉及让java使用carrot2作为多个来源的元搜索引擎,例如bing和google等。
我有一个依赖的maven项目:
<dependency>
<groupId>org.carrot2</groupId>
<artifactId>carrot2-core</artifactId>
<version>3.9.3</version>
</dependency>
我正在尝试运行以下内容:
/* 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();
我得到的是:
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?我已经尝试过了胡萝卜2的文档,但它对API的使用很少,而且这些例子也没有找到工作。
真的可以在这里使用一些帮助
答案 0 :(得分:1)
在来自carrot2邮件列表的Dawid Weiss上回答:
您正在尝试实例化一个抽象类。除非,否则不会飞 你是查克诺里斯。
为什么不查看随项目分发的示例?有 在那里使用Bing的一个例子。
所有示例都在这里,打包并准备好: http://project.carrot2.org/download-java-api.html
有问题的部分是:
ProcessingResult result = controller.process(attributes,
Bing3DocumentSource.class, LingoClusteringAlgorithm.class);
应改为:
ProcessingResult result = controller.process(attributes,
Bing3WebDocumentSource.class, LingoClusteringAlgorithm.class);