1

I'm trying to write a prototype for a project that involves having java use carrot2 as a metasearch engine for several sources, such as bing and google , etc.

I've got a maven project with dependency :

<dependency>
    <groupId>org.carrot2</groupId>
    <artifactId>carrot2-core</artifactId>
    <version>3.9.3</version>
</dependency>

I'm trying to run the following :

/* 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();

What I get is :

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

Am I using the API correctly ? I've tried going over the documentation of carrot2 but it goes very little into the usage of the API, and also the examples don't seam to work.

Could really use some help here

Fabio Cardoso
  • 1,181
  • 1
  • 14
  • 37
SysHex
  • 1,750
  • 2
  • 17
  • 27

1 Answers1

1

Answer from Dawid Weiss on the carrot2 mailing list:

  1. You're trying to instantiate an abstract class. Won't fly unless you're Chuck Norris.

  2. Why not look at the examples distributed with the project? There is an example that uses Bing there.

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

All the examples are here, packaged and ready: http://project.carrot2.org/download-java-api.html

  1. If you're planning to use Bing make sure you use your own appkey, please (and thanks).

The part in question is :

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

That should instead read :

ProcessingResult result = controller.process(attributes,
            Bing3WebDocumentSource.class, LingoClusteringAlgorithm.class);
Community
  • 1
  • 1
SysHex
  • 1,750
  • 2
  • 17
  • 27