Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-544 - Upgrade Carrot2 clustering plugin to the newest stable release (2.1). Contributed by Dawid Weiss.

Tacettin Guney2cc1934a1e3d
diff --git a/CHANGES.txt b/CHANGES.txt
index 8d78d34f5..f1e9a9456 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -120,6 +120,9 @@ Unreleased changes (1.0-dev)
40. NUTCH-439 - Top Level Domains Indexing / Scoring. Also adds
domain-related utilities. (Enis Soztutar via dogacan)
+41. NUTCH-544 - Upgrade Carrot2 clustering plugin to the newest stable
+ release (2.1). (Dawid Weiss via dogacan)
+
Release 0.9 - 2007-04-02
1. Changed log4j confiquration to log to stdout on commandline
diff --git a/src/plugin/clustering-carrot2/build.xml b/src/plugin/clustering-carrot2/build.xml
index 907bf0f44..5b44e70bb 100644
--- a/src/plugin/clustering-carrot2/build.xml
+++ b/src/plugin/clustering-carrot2/build.xml
@@ -16,7 +16,6 @@
limitations under the License.
-->
<project name="clustering-carrot2" default="jar-core">
-
<import file="../build-plugin.xml"/>
<!-- Build compilation dependencies -->
@@ -29,12 +28,19 @@
<fileset dir="${nutch.root}/build">
<include name="**/lib-nekohtml/*.jar" />
</fileset>
+ <fileset dir="${nutch.root}/lib">
+ <include name="commons-lang-*.jar" />
+ </fileset>
</path>
<!-- Deploy Unit test dependencies -->
<target name="deps-test">
<ant target="deploy" inheritall="false" dir="../lib-nekohtml"/>
- <ant target="deploy" inheritall="false" dir="../nutch-extensionpoints"/>
+ <ant target="deploy" inheritall="false" dir="../nutch-extensionpoints"/>
+
+ <copy toDir="${build.test}">
+ <fileset dir="${src.test}" excludes="**/*.java" />
+ </copy>
</target>
</project>
diff --git a/src/plugin/clustering-carrot2/lib/Jama-1.0.1-patched.jar b/src/plugin/clustering-carrot2/lib/Jama-1.0.1-patched.jar
deleted file mode 100644
index dba19a545..000000000
Binary files a/src/plugin/clustering-carrot2/lib/Jama-1.0.1-patched.jar and /dev/null differ
diff --git a/src/plugin/clustering-carrot2/lib/Jama-1.0.2.jar b/src/plugin/clustering-carrot2/lib/Jama-1.0.2.jar
new file mode 100644
index 000000000..2a34ba1fb
Binary files /dev/null and b/src/plugin/clustering-carrot2/lib/Jama-1.0.2.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/carrot2-filter-lingo.jar b/src/plugin/clustering-carrot2/lib/carrot2-filter-lingo.jar
index 777da2b77..56419e0ba 100644
Binary files a/src/plugin/clustering-carrot2/lib/carrot2-filter-lingo.jar and b/src/plugin/clustering-carrot2/lib/carrot2-filter-lingo.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/carrot2-local-core.jar b/src/plugin/clustering-carrot2/lib/carrot2-local-core.jar
index 752901824..a503f3146 100644
Binary files a/src/plugin/clustering-carrot2/lib/carrot2-local-core.jar and b/src/plugin/clustering-carrot2/lib/carrot2-local-core.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/carrot2-snowball-stemmers.jar b/src/plugin/clustering-carrot2/lib/carrot2-snowball-stemmers.jar
index 0e38c2dbe..0a3989831 100644
Binary files a/src/plugin/clustering-carrot2/lib/carrot2-snowball-stemmers.jar and b/src/plugin/clustering-carrot2/lib/carrot2-snowball-stemmers.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/carrot2-util-common.jar b/src/plugin/clustering-carrot2/lib/carrot2-util-common.jar
index c6aed5254..158fe0272 100644
Binary files a/src/plugin/clustering-carrot2/lib/carrot2-util-common.jar and b/src/plugin/clustering-carrot2/lib/carrot2-util-common.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/carrot2-util-tokenizer.jar b/src/plugin/clustering-carrot2/lib/carrot2-util-tokenizer.jar
index ea317974e..bd2554b5e 100644
Binary files a/src/plugin/clustering-carrot2/lib/carrot2-util-tokenizer.jar and b/src/plugin/clustering-carrot2/lib/carrot2-util-tokenizer.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/commons-collections-3.1-patched.jar b/src/plugin/clustering-carrot2/lib/commons-collections-3.1-patched.jar
deleted file mode 100644
index 300257c4f..000000000
Binary files a/src/plugin/clustering-carrot2/lib/commons-collections-3.1-patched.jar and /dev/null differ
diff --git a/src/plugin/clustering-carrot2/lib/commons-collections-3.2.jar b/src/plugin/clustering-carrot2/lib/commons-collections-3.2.jar
new file mode 100644
index 000000000..75580be25
Binary files /dev/null and b/src/plugin/clustering-carrot2/lib/commons-collections-3.2.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/commons-collections.LICENSE b/src/plugin/clustering-carrot2/lib/commons-collections.LICENSE
deleted file mode 100644
index 41bf7edfb..000000000
--- a/src/plugin/clustering-carrot2/lib/commons-collections.LICENSE
+++ /dev/null
@@ -1,53 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2004 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowledgement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgement may appear in the software itself,
- * if and wherever such third-party acknowledgements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact [email protected].
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
diff --git a/src/plugin/clustering-carrot2/lib/commons-pool-1.1.jar b/src/plugin/clustering-carrot2/lib/commons-pool-1.1.jar
deleted file mode 100644
index c61bde6c9..000000000
Binary files a/src/plugin/clustering-carrot2/lib/commons-pool-1.1.jar and /dev/null differ
diff --git a/src/plugin/clustering-carrot2/lib/commons-pool-1.3.jar b/src/plugin/clustering-carrot2/lib/commons-pool-1.3.jar
new file mode 100644
index 000000000..e8de3275c
Binary files /dev/null and b/src/plugin/clustering-carrot2/lib/commons-pool-1.3.jar differ
diff --git a/src/plugin/clustering-carrot2/lib/commons-pool.LICENSE b/src/plugin/clustering-carrot2/lib/commons-pool.LICENSE
index d77455945..1a51f0b64 100644
--- a/src/plugin/clustering-carrot2/lib/commons-pool.LICENSE
+++ b/src/plugin/clustering-carrot2/lib/commons-pool.LICENSE
@@ -1,60 +1,60 @@
-/*
- * $Revision: 1.2 $
- * $Date: 2004/06/19 16:26:16 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowledgement:
- * "This product includes software developed by the
- * Apache Software Foundation - http://www.apache.org/"
- * Alternately, this acknowledgement may appear in the software itself,
- * if and wherever such third-party acknowledgements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact [email protected].
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * http://www.apache.org/
- *
- */
+/*
+ * $Revision: 206 $
+ * $Date: 2004-06-19 18:26:22 +0200 (Sat, 19 Jun 2004) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation - http://www.apache.org/"
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact [email protected].
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * http://www.apache.org/
+ *
+ */
\ No newline at end of file
diff --git a/src/plugin/clustering-carrot2/plugin.xml b/src/plugin/clustering-carrot2/plugin.xml
index 9254c61c8..919d41c38 100644
--- a/src/plugin/clustering-carrot2/plugin.xml
+++ b/src/plugin/clustering-carrot2/plugin.xml
@@ -17,24 +17,29 @@
-->
<plugin
id="clustering-carrot2"
- name="Online Search Results Clustering using Carrot2's Lingo component"
- version="1.0.2"
- provider-name="carrot2.sourceforge.net">
+ name="Online Search Results Clustering using Carrot2's components"
+ version="1.0.3"
+ provider-name="www.carrot2.org">
<runtime>
<library name="clustering-carrot2.jar">
<export name="*"/>
</library>
+ <!--
+ The defaults for Lingo. If you plan to use another clustering
+ algorithm from the Carrot2 project, you'll need all the JARs
+ required for that algorithm.
+ -->
<library name="carrot2-filter-lingo.jar"/>
<library name="carrot2-local-core.jar"/>
<library name="carrot2-snowball-stemmers.jar"/>
<library name="carrot2-util-common.jar"/>
<library name="carrot2-util-tokenizer.jar"/>
- <library name="commons-collections-3.1-patched.jar"/>
- <library name="commons-pool-1.1.jar"/>
- <library name="Jama-1.0.1-patched.jar"/>
+ <library name="commons-collections-3.2.jar"/>
+ <library name="commons-pool-1.3.jar"/>
+ <library name="Jama-1.0.2.jar"/>
<library name="violinstrings-1.0.2.jar"/>
</runtime>
@@ -45,8 +50,7 @@
<extension id="org.apache.nutch.clustering.carrot2"
name="Carrot2 Clusterer"
point="org.apache.nutch.clustering.OnlineClusterer">
-
- <implementation id="Carrot2-Lingo"
+ <implementation id="Carrot2"
class="org.apache.nutch.clustering.carrot2.Clusterer"/>
</extension>
</plugin>
diff --git a/src/plugin/clustering-carrot2/readme.txt b/src/plugin/clustering-carrot2/readme.txt
index 121d92e2f..c58574c04 100644
--- a/src/plugin/clustering-carrot2/readme.txt
+++ b/src/plugin/clustering-carrot2/readme.txt
@@ -1,44 +1,7 @@
This plugin extension adds search results clustering capability to Nutch search
frontend.
-The user interface in Nutch is very limited and you'll most likely need something
-more application-specific. Look at http://www.carrot2.org or
-http://carrot.cs.put.poznan.pl for inspiration.
+Carrot2 JARs come from codebase in version: 2.1
-Libraries in this release are precompiled with stemming and stop words for various
-languages present in Carrot2 codebase (imported from the Snowball project). You
-must define the default language and supported languages in Nutch configuration
-file (nutch-site.xml). If nothing is given in Nutch configuration, English is
-taken by default.
-
-<!-- Carrot2 Clustering plugin configuration -->
-
-<property>
- <name>extension.clustering.carrot2.defaultLanguage</name>
- <value>en</value>
- <description>Two-letter ISO code of the language.
- http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</description>
-</property>
-
-<property>
- <name>extension.clustering.carrot2.languages</name>
- <value>en,nl,da,fi,fr,de,it,no,pl,pt,ru,es,sv</value>
- <description>All languages to be used by the clustering plugin.
- This list includes all currently supported languages (although not all of them
- will successfully instantiate -- support for Polish requires additional
- libraries for instance). Adjust to your needs, fewer languages take less
- memory.
-
- If you use the language recognizer plugin, then each hit will come with its
- own ISO language code. All hits with no explicit language take the default
- language specified in "extension.clustering.carrot2.defaultLanguage" property.
- </description>
-</property>
-
-
-If you need a different language/ clustering algorithm, you'll need to modify
-Nutch plugin code a bit (we don't want the plugin to outgrow Nutch, so we
-include just the essentials here). Ask on carrot@ developers mailing list for
-help if you need it.
-
-Carrot2 JARs come from codebase in version: 1.0.2
+See the WIKI for more information about configuration and installation
+of this plugin.
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
index 5e542a992..b96576108 100644
--- a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
+++ b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
@@ -16,43 +16,59 @@
*/
package org.apache.nutch.clustering.carrot2;
-import java.util.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.apache.nutch.clustering.HitsCluster;
import org.apache.nutch.clustering.OnlineClusterer;
import org.apache.nutch.searcher.HitDetails;
+import org.carrot2.core.DuplicatedKeyException;
+import org.carrot2.core.InitializationException;
+import org.carrot2.core.LocalComponent;
+import org.carrot2.core.LocalComponentFactory;
+import org.carrot2.core.LocalControllerBase;
+import org.carrot2.core.LocalProcess;
+import org.carrot2.core.LocalProcessBase;
+import org.carrot2.core.MissingComponentException;
+import org.carrot2.core.MissingProcessException;
+import org.carrot2.core.ProcessingResult;
+import org.carrot2.core.clustering.RawCluster;
+import org.carrot2.core.controller.ControllerHelper;
+import org.carrot2.core.controller.LoaderExtensionUnknownException;
+import org.carrot2.core.impl.ArrayOutputComponent;
+import org.carrot2.core.linguistic.Language;
+import org.carrot2.filter.lingo.local.LingoLocalFilterComponent;
+import org.carrot2.util.tokenizer.languages.AllKnownLanguages;
-import com.dawidweiss.carrot.core.local.*;
-import com.dawidweiss.carrot.core.local.clustering.RawCluster;
-import com.dawidweiss.carrot.core.local.impl.ClustersConsumerOutputComponent;
-import com.dawidweiss.carrot.core.local.linguistic.Language;
-import com.dawidweiss.carrot.util.tokenizer.languages.AllKnownLanguages;
-import com.stachoodev.carrot.filter.lingo.local.LingoLocalFilterComponent;
/**
- * An plugin providing an implementation of {@link OnlineClusterer}
+ * This plugin provides an implementation of {@link OnlineClusterer}
* extension using clustering components of the Carrot2 project
- * (<a href="http://carrot2.sourceforge.net">http://carrot2.sourceforge.net</a>).
+ * (<a href="http://www.carrot2.org">http://www.carrot2.org</a>).
*
- * We hardcode the following Carrot2 process:
+ * <p>This class hardcodes an equivalent of the following Carrot2 process:
* <pre><![CDATA[
* <local-process id="yahoo-lingo">
* <name>Yahoo Search API -- Lingo Classic Clusterer</name>
*
- * <input component-key="input-localnutch" />
+ * <input component-key="input-nutch" />
* <filter component-key="filter-lingo" />
* <output component-key="output-clustersConsumer" />
* </local-process>
* ]]></pre>
- *
- * @author Dawid Weiss
- * @version $Id: Clusterer.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
*/
public class Clusterer implements OnlineClusterer, Configurable {
/** Default language property name. */
@@ -69,7 +85,7 @@ public class Clusterer implements OnlineClusterer, Configurable {
public static final Log logger = LogFactory.getLog(Clusterer.class);
/** The LocalController instance used for clustering */
- private LocalController controller;
+ private LocalControllerBase controller;
/** Nutch configuration. */
private Configuration conf;
@@ -91,100 +107,22 @@ public class Clusterer implements OnlineClusterer, Configurable {
* of the clusterer.
*/
public Clusterer() {
- initialize();
- }
-
- private synchronized void initialize() {
- controller = new LocalControllerBase();
- addComponentFactories();
- addProcesses();
- }
-
- /** Adds the required component factories to a local Carrot2 controller. */
- private void addComponentFactories() {
- // * <input component-key="input-localnutch" />
- LocalComponentFactory nutchInputFactory = new LocalComponentFactoryBase() {
- public LocalComponent getInstance() {
- return new LocalNutchInputComponent(defaultLanguage);
- }
- };
- controller.addLocalComponentFactory("input-localnutch", nutchInputFactory);
-
- // * <filter component-key="filter-lingo" />
- LocalComponentFactory lingoFactory = new LocalComponentFactoryBase() {
- public LocalComponent getInstance() {
- HashMap defaults = new HashMap();
-
- // These are adjustments settings for the clustering algorithm.
- // If you try the live WebStart demo of Carrot2 you can see how they affect
- // the final clustering: http://www.carrot2.org/webstart
- defaults.put("lsi.threshold.clusterAssignment", "0.150");
- defaults.put("lsi.threshold.candidateCluster", "0.775");
-
- // Initialize a new Lingo clustering component.
- ArrayList languageList = new ArrayList(languages.length);
- for (int i = 0; i < languages.length; i++) {
- final String lcode = languages[i];
- try {
- Language lang = AllKnownLanguages.getLanguageForIsoCode(lcode);
- if (lang == null) {
- if (logger.isWarnEnabled()) {
- logger.warn("Language not supported in Carrot2: " + lcode);
- }
- } else {
- languageList.add(lang);
- if (logger.isDebugEnabled()) {
- logger.debug("Language loaded: " + lcode);
- }
- }
- } catch (Throwable t) {
- if (logger.isWarnEnabled()) {
- logger.warn("Language could not be loaded: " + lcode, t);
- }
- }
- }
- return new LingoLocalFilterComponent(
- (Language []) languageList.toArray(new Language [languageList.size()]), defaults);
- }
- };
- controller.addLocalComponentFactory("filter-lingo", lingoFactory);
-
- // * <output component-key="output-clustersConsumer" />
- LocalComponentFactory clusterConsumerOutputFactory = new LocalComponentFactoryBase() {
- public LocalComponent getInstance() {
- return new ClustersConsumerOutputComponent();
- }
- };
- controller.addLocalComponentFactory("output-clustersConsumer",
- clusterConsumerOutputFactory);
+ // Don't forget to call {@link #setConf(Configuration)}.
}
- /**
- * Adds a hardcoded clustering process to the local controller.
- */
- private void addProcesses() {
- LocalProcessBase process = new LocalProcessBase(
- "input-localnutch", // input
- "output-clustersConsumer", // output
- new String [] {"filter-lingo"}, // filters
- "The Lingo clustering algorithm (www.carrot2.org).",
- "");
-
- try {
- controller.addProcess(PROCESS_ID, process);
- } catch (Exception e) {
- throw new RuntimeException("Could not assemble clustering process.", e);
- }
- }
-
/**
* See {@link OnlineClusterer} for documentation.
*/
public HitsCluster [] clusterHits(HitDetails [] hitDetails, String [] descriptions) {
- Map requestParams = new HashMap();
- requestParams.put(LocalNutchInputComponent.NUTCH_INPUT_HIT_DETAILS_ARRAY,
+ if (this.controller == null) {
+ logger.error("initialize() not called.");
+ return new HitsCluster[0];
+ }
+
+ final Map requestParams = new HashMap();
+ requestParams.put(NutchInputComponent.NUTCH_INPUT_HIT_DETAILS_ARRAY,
hitDetails);
- requestParams.put(LocalNutchInputComponent.NUTCH_INPUT_SUMMARIES_ARRAY,
+ requestParams.put(NutchInputComponent.NUTCH_INPUT_SUMMARIES_ARRAY,
descriptions);
try {
@@ -192,8 +130,8 @@ public class Clusterer implements OnlineClusterer, Configurable {
final ProcessingResult result =
controller.query(PROCESS_ID, "no-query", requestParams);
- final ClustersConsumerOutputComponent.Result output =
- (ClustersConsumerOutputComponent.Result) result.getQueryResult();
+ final ArrayOutputComponent.Result output =
+ (ArrayOutputComponent.Result) result.getQueryResult();
final List outputClusters = output.clusters;
final HitsCluster [] clusters = new HitsCluster[ outputClusters.size() ];
@@ -218,7 +156,7 @@ public class Clusterer implements OnlineClusterer, Configurable {
*/
public void setConf(Configuration conf) {
this.conf = conf;
-
+
// Configure default language and other component settings.
if (conf.get(CONF_PROP_DEFAULT_LANGUAGE) != null) {
// Change the default language.
@@ -242,4 +180,151 @@ public class Clusterer implements OnlineClusterer, Configurable {
public Configuration getConf() {
return conf;
}
+
+ /**
+ * Initialize clustering processes and Carrot2 components.
+ */
+ private synchronized void initialize() {
+ // Initialize language list, temporarily switching off logging
+ // of warnings. This is a bit of a hack, but we don't want to
+ // redistribute the entire Carrot2 distro and this prevents
+ // nasty ClassNotFound warnings.
+ final Logger c2Logger = Logger.getLogger("org.carrot2");
+ final Level original = c2Logger.getLevel();
+ c2Logger.setLevel(Level.ERROR);
+ AllKnownLanguages.getLanguageCodes();
+ c2Logger.setLevel(original);
+
+ // Initialize the controller.
+ controller = new LocalControllerBase();
+
+ final Configuration nutchConf = getConf();
+ final String processResource = nutchConf.get(
+ "extension.clustering.carrot2.process-resource");
+
+ if (processResource == null) {
+ logger.info("Using default clustering algorithm (Lingo).");
+ addDefaultProcess();
+ } else {
+ logger.info("Using custom clustering process: " + processResource);
+ controller.setComponentAutoload(true);
+
+ final ControllerHelper helper = new ControllerHelper();
+ final InputStream is = Thread.currentThread()
+ .getContextClassLoader().getResourceAsStream(processResource);
+ if (is != null) {
+ try {
+ final LocalComponentFactory nutchInputFactory = new LocalComponentFactory() {
+ public LocalComponent getInstance() {
+ return new NutchInputComponent(defaultLanguage);
+ }
+ };
+ controller.addLocalComponentFactory("input-nutch", nutchInputFactory);
+
+ final LocalProcess process = helper.loadProcess(
+ helper.getExtension(processResource), is).getProcess();
+ controller.addProcess(PROCESS_ID, process);
+ is.close();
+ } catch (IOException e) {
+ logger.error("Could not load process resource: " + processResource, e);
+ } catch (LoaderExtensionUnknownException e) {
+ logger.error("Unrecognized extension of process resource: " + processResource);
+ } catch (InstantiationException e) {
+ logger.error("Could not instantiate process: " + processResource, e);
+ } catch (InitializationException e) {
+ logger.error("Could not initialize process: " + processResource, e);
+ } catch (DuplicatedKeyException e) {
+ logger.error("Duplicated key (unreachable?): " + processResource, e);
+ } catch (MissingComponentException e) {
+ logger.error("Some components are missing, could not initialize process: "
+ + processResource, e);
+ }
+ } else {
+ logger.error("Could not find process resource: " + processResource);
+ }
+ }
+ }
+
+ /**
+ * Adds a default clustering process using Lingo algorithm.
+ */
+ private void addDefaultProcess() {
+ try {
+ addComponentFactories();
+ addProcesses();
+ } catch (DuplicatedKeyException e) {
+ logger.fatal("Duplicated component or process identifier.", e);
+ }
+ }
+
+ /** Adds the required component factories to a local Carrot2 controller. */
+ private void addComponentFactories() throws DuplicatedKeyException {
+ // * <input component-key="input-nutch" />
+ LocalComponentFactory nutchInputFactory = new LocalComponentFactory() {
+ public LocalComponent getInstance() {
+ return new NutchInputComponent(defaultLanguage);
+ }
+ };
+ controller.addLocalComponentFactory("input-nutch", nutchInputFactory);
+
+ // * <filter component-key="filter-lingo" />
+ LocalComponentFactory lingoFactory = new LocalComponentFactory() {
+ public LocalComponent getInstance() {
+ final HashMap defaults = new HashMap();
+
+ // These are adjustments settings for the clustering algorithm.
+ // If you try the live WebStart demo of Carrot2 you can see how they affect
+ // the final clustering: http://www.carrot2.org
+ defaults.put("lsi.threshold.clusterAssignment", "0.150");
+ defaults.put("lsi.threshold.candidateCluster", "0.775");
+
+ // Initialize a new Lingo clustering component.
+ ArrayList languageList = new ArrayList(languages.length);
+ for (int i = 0; i < languages.length; i++) {
+ final String lcode = languages[i];
+ try {
+ final Language lang = AllKnownLanguages.getLanguageForIsoCode(lcode);
+ if (lang == null) {
+ logger.warn("Language not supported in Carrot2: " + lcode);
+ } else {
+ languageList.add(lang);
+ logger.debug("Language loaded: " + lcode);
+ }
+ } catch (Throwable t) {
+ logger.warn("Language could not be loaded: " + lcode, t);
+ }
+ }
+ return new LingoLocalFilterComponent(
+ (Language []) languageList.toArray(new Language [languageList.size()]), defaults);
+ }
+ };
+ controller.addLocalComponentFactory("filter-lingo", lingoFactory);
+
+ // * <output component-key="output-clustersConsumer" />
+ LocalComponentFactory clusterConsumerOutputFactory = new LocalComponentFactory() {
+ public LocalComponent getInstance() {
+ return new ArrayOutputComponent();
+ }
+ };
+ controller.addLocalComponentFactory("output-array",
+ clusterConsumerOutputFactory);
+ }
+
+ /**
+ * Adds a hardcoded clustering process to the local controller.
+ */
+ private void addProcesses() {
+ final LocalProcessBase process = new LocalProcessBase(
+ "input-nutch",
+ "output-array",
+ new String [] {"filter-lingo"},
+ "The Lingo clustering algorithm (www.carrot2.org).",
+ "");
+
+ try {
+ controller.addProcess(PROCESS_ID, process);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not assemble clustering process.", e);
+ }
+ }
}
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/HitsClusterAdapter.java b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/HitsClusterAdapter.java
index 7532da5b9..82103e20b 100644
--- a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/HitsClusterAdapter.java
+++ b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/HitsClusterAdapter.java
@@ -19,18 +19,14 @@ package org.apache.nutch.clustering.carrot2;
import java.util.Iterator;
import java.util.List;
-import com.dawidweiss.carrot.core.local.clustering.RawCluster;
-import com.dawidweiss.carrot.core.local.clustering.RawDocument;
-
import org.apache.nutch.clustering.HitsCluster;
import org.apache.nutch.searcher.HitDetails;
+import org.carrot2.core.clustering.RawCluster;
+import org.carrot2.core.clustering.RawDocument;
/**
* An adapter of Carrot2's {@link RawCluster} interface to
* {@link HitsCluster} interface.
- *
- * @author Dawid Weiss
- * @version $Id: HitsClusterAdapter.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
*/
public class HitsClusterAdapter implements HitsCluster {
private RawCluster rawCluster;
@@ -59,7 +55,7 @@ public class HitsClusterAdapter implements HitsCluster {
*/
public HitsCluster[] getSubclusters() {
if (this.subclusters == null) {
- List rawSubclusters = rawCluster.getSubclusters();
+ final List rawSubclusters = rawCluster.getSubclusters();
if (rawSubclusters == null || rawSubclusters.size() == 0) {
subclusters = null;
} else {
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchDocument.java b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchDocument.java
index 9e0c026c8..a570aef7f 100644
--- a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchDocument.java
+++ b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchDocument.java
@@ -17,15 +17,11 @@
package org.apache.nutch.clustering.carrot2;
import org.apache.nutch.searcher.HitDetails;
-
-import com.dawidweiss.carrot.core.local.clustering.RawDocument;
-import com.dawidweiss.carrot.core.local.clustering.RawDocumentBase;
+import org.carrot2.core.clustering.RawDocument;
+import org.carrot2.core.clustering.RawDocumentBase;
/**
* An adapter class that implements {@link RawDocument} required for Carrot2.
- *
- * @author Dawid Weiss
- * @version $Id: NutchDocument.java,v 1.2 2004/08/10 00:18:43 johnnx Exp $
*/
public class NutchDocument extends RawDocumentBase {
/**
@@ -39,28 +35,25 @@ public class NutchDocument extends RawDocumentBase {
* a <code>details</code> hit details.
*/
public NutchDocument(int id, HitDetails details, String summary, String defaultLanguage) {
- super.setProperty(RawDocument.PROPERTY_URL, details.getValue("url"));
- super.setProperty(RawDocument.PROPERTY_SNIPPET, summary);
+ super(details.getValue("url"), details.getValue("title"), summary);
- final String title = details.getValue("title");
- if (title != null && !"".equals(title)) {
- super.setProperty(RawDocument.PROPERTY_TITLE, title);
- }
-
+ // Handle document language -- attempt to extract it from the details,
+ // otherwise set to the default.
String lang = details.getValue("lang");
if (lang == null) {
// No default language. Take the default from the configuration file.
lang = defaultLanguage;
}
+
// Use this language for the snippet. Truncate longer ISO codes
// to only include two-letter language code.
if (lang.length() > 2) {
lang = lang.substring(0, 2);
}
- lang = lang.toLowerCase();
+ lang = lang.toLowerCase();
super.setProperty(RawDocument.PROPERTY_LANGUAGE, lang);
- this.id = new Integer(id);
+ this.id = Integer.valueOf(id);
}
/*
@@ -69,4 +62,4 @@ public class NutchDocument extends RawDocumentBase {
public Object getId() {
return id;
}
-}
+}
\ No newline at end of file
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/LocalNutchInputComponent.java b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchInputComponent.java
similarity index 71%
rename from src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/LocalNutchInputComponent.java
rename to src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchInputComponent.java
index 918d22c48..34067dea0 100644
--- a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/LocalNutchInputComponent.java
+++ b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/NutchInputComponent.java
@@ -16,35 +16,23 @@
*/
package org.apache.nutch.clustering.carrot2;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
import java.util.Map;
-
-import org.apache.xerces.parsers.AbstractSAXParser;
-import org.cyberneko.html.HTMLConfiguration;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
+import java.util.Set;
import org.apache.nutch.searcher.HitDetails;
-
-import com.dawidweiss.carrot.core.local.LocalInputComponentBase;
-import com.dawidweiss.carrot.core.local.ProcessingException;
-import com.dawidweiss.carrot.core.local.RequestContext;
-import com.dawidweiss.carrot.core.local.clustering.*;
+import org.carrot2.core.LocalInputComponentBase;
+import org.carrot2.core.ProcessingException;
+import org.carrot2.core.RequestContext;
+import org.carrot2.core.clustering.RawDocumentsConsumer;
+import org.carrot2.core.clustering.RawDocumentsProducer;
/**
- * A local input component that ignores the query passed from the
+ * An input component that ignores the query passed from the
* controller and instead looks for data stored in the request context.
* This enables us to reuse the same physical component implementation
- * for data that has already been acquired from Nutch.
- *
- * @author Dawid Weiss
- * @version $Id: LocalNutchInputComponent.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
+ * for data that has already been acquired from Nutch.
*/
-public class LocalNutchInputComponent extends LocalInputComponentBase {
+public class NutchInputComponent extends LocalInputComponentBase {
public final static String NUTCH_INPUT_HIT_DETAILS_ARRAY
= "NUTCH_INPUT_HIT_DETAILS_ARRAY";
@@ -52,12 +40,10 @@ public class LocalNutchInputComponent extends LocalInputComponentBase {
= "NUTCH_INPUT_SUMMARIES_ARRAY";
/** Capabilities required from the next component in the chain */
- private final static Set SUCCESSOR_CAPABILITIES
- = new HashSet(Arrays.asList(new Object [] { RawDocumentsConsumer.class }));
+ private final static Set SUCCESSOR_CAPABILITIES = toSet(RawDocumentsConsumer.class);
/** This component's capabilities */
- private final static Set COMPONENT_CAPABILITIES
- = new HashSet(Arrays.asList(new Object [] { RawDocumentsProducer.class }));
+ private final static Set COMPONENT_CAPABILITIES = toSet(RawDocumentsProducer.class);
/**
* Default language code for hits that don't have their own.
@@ -67,7 +53,7 @@ public class LocalNutchInputComponent extends LocalInputComponentBase {
/**
* Creates an input component with the given default language code.
*/
- public LocalNutchInputComponent(String defaultLanguage) {
+ public NutchInputComponent(String defaultLanguage) {
this.defaultLanguage = defaultLanguage;
}
@@ -89,19 +75,19 @@ public class LocalNutchInputComponent extends LocalInputComponentBase {
final Map params = context.getRequestParameters();
final HitDetails [] details = (HitDetails[]) params.get(NUTCH_INPUT_HIT_DETAILS_ARRAY);
final String [] summaries = (String[]) params.get(NUTCH_INPUT_SUMMARIES_ARRAY);
-
+
if (details == null)
throw new ProcessingException("Details array must not be null.");
if (summaries == null)
throw new ProcessingException("Summaries array must not be null.");
-
+
if (summaries.length != details.length)
throw new ProcessingException("Summaries and details must be of the same length.");
// produce 'documents' for successor components.
final RawDocumentsConsumer consumer = (RawDocumentsConsumer) next;
- for (int i=0;i<summaries.length;i++) {
+ for (int i = 0; i < summaries.length; i++) {
consumer.addDocument(new NutchDocument(i, details[i], summaries[i], defaultLanguage));
}
}
@@ -119,5 +105,4 @@ public class LocalNutchInputComponent extends LocalInputComponentBase {
public Set getRequiredSuccessorCapabilities() {
return SUCCESSOR_CAPABILITIES;
}
-
}
diff --git a/src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/ClustererTest.java b/src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/TestClusterer.java
similarity index 91%
rename from src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/ClustererTest.java
rename to src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/TestClusterer.java
index 06d89f1fc..cb9b9bee4 100644
--- a/src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/ClustererTest.java
+++ b/src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/TestClusterer.java
@@ -17,6 +17,7 @@
package org.apache.nutch.clustering.carrot2;
+import java.io.InputStream;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
@@ -24,6 +25,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
+import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.clustering.HitsCluster;
import org.apache.nutch.searcher.HitDetails;
import org.w3c.dom.Document;
@@ -33,26 +35,24 @@ import org.w3c.dom.NodeList;
/**
* A test case for the Carrot2-based clusterer plugin to Nutch.
- *
- * @author Dawid Weiss
- * @version $Id: ClustererTest.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
*/
-public class ClustererTest extends TestCase {
-
- public ClustererTest(String s) {
- super(s);
+public class TestClusterer extends TestCase {
+ private Clusterer c;
+
+ public TestClusterer(String testName) {
+ super(testName);
}
- public ClustererTest() {
- super();
+ protected void setUp() throws Exception {
+ c = new Clusterer();
+ c.setConf(new Configuration());
}
-
+
/**
* The clusterer should not fail on empty input, returning
* an empty array of {@link HitsCluster}.
*/
public void testEmptyInput() {
- final Clusterer c = new Clusterer();
final HitDetails [] hitDetails = new HitDetails[0];
final String [] descriptions = new String [0];
final HitsCluster [] clusters = c.clusterHits(hitDetails, descriptions);
@@ -65,8 +65,10 @@ public class ClustererTest extends TestCase {
public void testOnCachedData() throws Exception {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder parser = factory.newDocumentBuilder();
- final Document document = parser.parse(
- getClass().getResourceAsStream("test-input.xml"));
+ final InputStream is = getClass().getResourceAsStream("test-input.xml");
+ assertNotNull("test-input.xml not found", is);
+ final Document document = parser.parse(is);
+ is.close();
final Element data = document.getDocumentElement();
final NodeList docs = data.getElementsByTagName("document");
@@ -88,7 +90,6 @@ public class ClustererTest extends TestCase {
new String [] {toText(urlElement)}));
}
- final Clusterer c = new Clusterer();
HitsCluster [] clusters = c.clusterHits(
(HitDetails[]) hitDetails.toArray(new HitDetails[hitDetails.size()]),
(String[]) summaries.toArray(new String[summaries.size()]));
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/test-input.xml b/src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/test-input.xml
similarity index 100%
rename from src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/test-input.xml
rename to src/plugin/clustering-carrot2/src/test/org/apache/nutch/clustering/carrot2/test-input.xml