KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
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 /**
16  * An adapter of Carrot2's {@link RawCluster} interface to
17  * {@link HitsCluster} interface.
18  *
19  * @author Dawid Weiss
20  * @version $Id: HitsClusterAdapter.java,v 1.1 2004/08/09 23:23:53 johnnx Exp $
21  */

22 public class HitsClusterAdapter implements HitsCluster {
23
24   private RawCluster rawCluster;
25   private HitDetails [] hits;
26
27   /**
28    * Lazily initialized subclusters array.
29    */

30   private HitsCluster [] subclusters;
31   
32   /**
33    * Lazily initialized documents array.
34    */

35   private HitDetails [] documents;
36   
37   /**
38    * Creates a new adapter.
39    */

40   public HitsClusterAdapter(RawCluster rawCluster, HitDetails [] hits) {
41     this.rawCluster = rawCluster;
42     this.hits = hits;
43   }
44
45   /*
46    * @see net.nutch.clustering.HitsCluster#getSubclusters()
47    */

48   public HitsCluster[] getSubclusters() {
49     if (this.subclusters == null) {
50       List JavaDoc 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 JavaDoc 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   /*
67    * @see net.nutch.clustering.HitsCluster#getHits()
68    */

69   public HitDetails[] getHits() {
70     if (documents == null) {
71       List JavaDoc rawDocuments = this.rawCluster.getDocuments();
72       documents = new HitDetails[ rawDocuments.size() ];
73       
74       int j = 0;
75       for (Iterator JavaDoc i = rawDocuments.iterator(); i.hasNext(); j++) {
76         RawDocument doc = (RawDocument) i.next();
77         Integer JavaDoc offset = (Integer JavaDoc) doc.getId();
78         documents[j] = this.hits[offset.intValue()];
79       }
80     }
81
82     return documents;
83   }
84
85   /*
86    * @see net.nutch.clustering.HitsCluster#getDescriptionLabels()
87    */

88   public String JavaDoc[] getDescriptionLabels() {
89     List JavaDoc phrases = this.rawCluster.getClusterDescription();
90     return (String JavaDoc []) phrases.toArray( new String JavaDoc [ phrases.size() ]);
91   }
92
93   /*
94    * @see net.nutch.clustering.HitsCluster#isJunkCluster()
95    */

96   public boolean isJunkCluster() {
97     return rawCluster.getProperty(RawCluster.PROPERTY_JUNK_CLUSTER) != null;
98   }
99 }
100
101
Popular Tags