1 2 3 4 package net.nutch.clustering.carrot2; 5 6 import java.io.File ; 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 25 public class ClustererTest extends TestCase { 26 27 public ClustererTest(String 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 [] descriptions = new String [0]; 40 41 HitsCluster [] clusters = c.clusterHits(hitDetails, descriptions); 42 assertTrue( clusters != null && clusters.length == 0 ); 43 } 44 45 71 72 private void dump(int level, HitsCluster cluster) { 73 String [] 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 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 |