1

bing や google などのいくつかのソースのメタ検索エンジンとして java を使用することを含むプロジェクトのプロトタイプを作成しようとしています。

依存関係のある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 を正しく使用していますか? 私はcarrot2のドキュメントを調べてみましたが、APIの使用法にはほとんど触れておらず、例もうまく機能していません.

ここで本当に助けを借りることができます

4

1 に答える 1

1

キャロット2メーリングリストのDawid Weissからの回答:

  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 を使用する予定がある場合は、必ず独自の appkey を使用してください (感謝します)。

問題の部分は次のとおりです。

ProcessingResult result = controller.process(attributes,
    Bing3DocumentSource.class, LingoClusteringAlgorithm.class);

代わりに次のように読む必要があります。

ProcessingResult result = controller.process(attributes,
            Bing3WebDocumentSource.class, LingoClusteringAlgorithm.class);
于 2014-10-28T21:45:48.730 に答える