1 2 3 4 package net.nutch.clustering.carrot2; 5 6 import java.util.Iterator ; 7 import java.util.List ; 8 9 import com.dawidweiss.carrot.core.local.clustering.RawCluster; 10 import com.dawidweiss.carrot.core.local.clustering.RawDocument; 11 12 import net.nutch.clustering.HitsCluster; 13 import net.nutch.searcher.HitDetails; 14 15 22 public class HitsClusterAdapter implements HitsCluster { 23 24 private RawCluster rawCluster; 25 private HitDetails [] hits; 26 27 30 private HitsCluster [] subclusters; 31 32 35 private HitDetails [] documents; 36 37 40 public HitsClusterAdapter(RawCluster rawCluster, HitDetails [] hits) { 41 this.rawCluster = rawCluster; 42 this.hits = hits; 43 } 44 45 48 public HitsCluster[] getSubclusters() { 49 if (this.subclusters == null) { 50 List rawSubclusters = rawCluster.getSubclusters(); 51 if (rawSubclusters == null || rawSubclusters.size() == 0) { 52 subclusters = null; 53 } else { 54 subclusters = new HitsCluster[rawSubclusters.size()]; 55 int j = 0; 56 for (Iterator i = rawSubclusters.iterator(); i.hasNext(); j++) { 57 RawCluster c = (RawCluster) i.next(); 58 subclusters[j] = new HitsClusterAdapter(c, hits); 59 } 60 } 61 } 62 63 return subclusters; 64 } 65 66 69 public HitDetails[] getHits() { 70 if (documents == null) { 71 List rawDocuments = this.rawCluster.getDocuments(); 72 documents = new HitDetails[ rawDocuments.size() ]; 73 74 int j = 0; 75 for (Iterator i = rawDocuments.iterator(); i.hasNext(); j++) { 76 RawDocument doc = (RawDocument) i.next(); 77 Integer offset = (Integer ) doc.getId(); 78 documents[j] = this.hits[offset.intValue()]; 79 } 80 } 81 82 return documents; 83 } 84 85 88 public String [] getDescriptionLabels() { 89 List phrases = this.rawCluster.getClusterDescription(); 90 return (String []) phrases.toArray( new String [ phrases.size() ]); 91 } 92 93 96 public boolean isJunkCluster() { 97 return rawCluster.getProperty(RawCluster.PROPERTY_JUNK_CLUSTER) != null; 98 } 99 } 100 101 | Popular Tags |