00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _KEYFILECLUSTERDB_HPP
00015 #define _KEYFILECLUSTERDB_HPP
00016
00017 #include "ClusterDB.hpp"
00018 #include "IndexedReal.hpp"
00019 #include "Keyfile.hpp"
00020 #include <string>
00023 class KeyfileClusterDB : public ClusterDB {
00024
00025 public:
00027 KeyfileClusterDB(const Index *ind,
00028 const string &name,
00029 double threshold = 0.25,
00030 enum ClusterParam::simTypes simType = ClusterParam::COS,
00031 enum ClusterParam::clusterTypes
00032 clusterType = ClusterParam::CENTROID,
00033 enum ClusterParam::docModes docMode = ClusterParam::DMAX);
00034
00036 virtual ~KeyfileClusterDB();
00037
00039 virtual vector<Cluster*> getDocCluster(DOCID_T docId) const ;
00040
00042 virtual int countClusters() const {
00043
00044 int clusterCount = 0, actual;
00045 clustersKey.get("NUMCLUSTERS", &clusterCount, actual, sizeof(int));
00046 return clusterCount;
00047 }
00048
00050 virtual int maxID() const {
00051
00052 int clusterIDCounter = 0, actual;
00053 clustersKey.get("MAXID", &clusterIDCounter, actual, sizeof(int));
00054 return clusterIDCounter;
00055 }
00056
00057
00059 virtual Cluster *getCluster(int clusterId) const ;
00060
00062 virtual vector<int> getDocClusterId(DOCID_T docId) const ;
00063
00065 virtual int addToCluster(DOCID_T docId, int clusterId, double score);
00066
00068 virtual int addToCluster(DOCID_T docId, Cluster *cluster, double score);
00069
00071 virtual int removeFromCluster(DOCID_T docId, int clusterID);
00072
00074 virtual int deleteCluster(int clusterID);
00075
00077 virtual int deleteCluster(Cluster * cluster);
00078
00080 virtual vector<int> splitCluster(int cid, int num = 2);
00081
00083 virtual int mergeClusters(int cid1, int cid2);
00084
00085 protected:
00087 virtual Cluster * newCluster();
00088
00089 private:
00091 mutable Keyfile doc2cluster;
00092 mutable Keyfile clustersKey;
00093 void init(const string &name);
00094 void addC2D(int cid, const vector<DOCID_T> &dids);
00095 };
00096 #endif