KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > clustering > carrot2 > ClustererTest


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.clustering.carrot2;
5
6 import java.io.File JavaDoc;
7
8 import net.nutch.clustering.HitsCluster;
9 import net.nutch.searcher.Hit;
10 import net.nutch.searcher.HitDetails;
11 import net.nutch.searcher.Hits;
12 import net.nutch.searcher.NutchBean;
13 import net.nutch.searcher.Query;
14 import junit.framework.TestCase;
15
16 /**
17  * A test case for the Carrot2-based clusterer plugin to Nutch.
18  *
19  * <p><b>This test case is mostly commented-out because I don't know
20  * how to integrate a test that requires an existing Nutch index.</b></p>
21  *
22  * @author Dawid Weiss
23  * @version $Id: ClustererTest.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
24  */

25 public class ClustererTest extends TestCase {
26
27   public ClustererTest(String JavaDoc s) {
28     super(s);
29   }
30   
31   public ClustererTest() {
32     super();
33   }
34
35   public void testEmptyInput() {
36     Clusterer c = new Clusterer();
37     
38     HitDetails [] hitDetails = new HitDetails[0];
39     String JavaDoc [] descriptions = new String JavaDoc [0];
40
41     HitsCluster [] clusters = c.clusterHits(hitDetails, descriptions);
42     assertTrue( clusters != null && clusters.length == 0 );
43   }
44
45   /*
46   
47   UNCOMMENT THIS IF YOU HAVE A NUTCH INDEX AVAILABLE. REPLACE
48   THE HARDCODED PATH TO IT.
49   
50   public void testSomeInput() throws Exception {
51     Clusterer c = new Clusterer();
52
53     NutchBean bean = new NutchBean(
54       new File("c:\\dweiss\\data\\mozdex-nutch\\nutch-mozdex\\resin"));
55     Query q = Query.parse( "blog" );
56     Hits hits = bean.search(q, 100);
57
58     Hit[] show = hits.getHits(0, 100);
59     HitDetails[] details = bean.getDetails(show);
60     String[] summaries = bean.getSummary(details, q);
61
62     HitsCluster [] clusters = c.clusterHits(details, summaries);
63     assertTrue( clusters != null );
64     
65     for (int i=0;i<clusters.length;i++) {
66         HitsCluster cluster = clusters[i];
67         dump(0, cluster);
68     }
69   }
70   */

71   
72   private void dump(int level, HitsCluster cluster) {
73     String JavaDoc [] labels = cluster.getDescriptionLabels();
74     for (int indent = 0; indent<level; indent++) {
75       System.out.print( " " );
76     }
77     System.out.print(">> ");
78     if (cluster.isJunkCluster()) System.out.print("(Junk) ");
79     System.out.print("CLUSTER: ");
80     for (int i=0;i<labels.length;i++) {
81       System.out.print( labels[i] + "; " );
82     }
83     System.out.println();
84     
85     HitsCluster [] subclusters = cluster.getSubclusters();
86     if (subclusters != null) {
87       for (int i=0;i<subclusters.length;i++) {
88         dump(level + 1, subclusters[i]);
89       }
90     }
91     
92     // dump documents.
93
HitDetails [] hits = cluster.getHits();
94     if (hits != null) {
95       for (int i=0;i<hits.length;i++ ) {
96         for (int indent = 0; indent<level; indent++) {
97           System.out.print( " " );
98         }
99         System.out.print( hits[i].getValue("url") );
100         System.out.print( "; " );
101         System.out.println( hits[i].getValue("title") );
102       }
103     }
104   }
105 }
106
Popular Tags