📄 clustboost.cpp
字号:
/* Text Clustering Copyright (C) 2004 Debora "Barbara" Donato, Antonio Gulli This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "dictionary.h"#include "docvectors.h"#include "k-mean-clusters.h"#include "shingle-clustering.h"#include "Reader.h"#include "Clustering.h"#include <stdio.h>#include <getopt.h>void test1(){ vectorSpace vs1; document d_temp0; document d_temp1; document d_temp2; DOCUMENT::iterator d_temp_iter; double distance; //vector<tuple *> nums; //vector<tuple *>::iterator nums_iter; //nums.push_back (new tuple(1,4)); //nums.push_back (new tuple(2,7)); //nums.push_back (new tuple(10,10)); d_temp0.add(new tuple(1,4)); d_temp0.add(new tuple(2,7)); d_temp0.add(new tuple(10,10)); cout << endl << "Vector 'd_temp0' now becomes:" << endl; for (d_temp_iter=d_temp0.begin(); d_temp_iter!=d_temp0.end(); d_temp_iter++){ cout << (*d_temp_iter) << endl; } cout << endl; d_temp1.add(new tuple(2,4)); d_temp1.add(new tuple(3,7)); cout << endl << "Vector 'd_temp1' now becomes:" << endl; for (d_temp_iter=d_temp1.begin(); d_temp_iter!=d_temp1.end(); d_temp_iter++){ cout << (*d_temp_iter) << endl; } cout << endl; d_temp2.add(new tuple(1,5)); d_temp2.add(new tuple(3,3)); d_temp2.add(new tuple(7,2)); cout << endl << "Vector 'd_temp2' now becomes:" << endl; for (d_temp_iter=d_temp2.begin(); d_temp_iter!=d_temp2.end(); d_temp_iter++){ cout << (*d_temp_iter) << endl; } cout << endl; vs1.pushVector(d_temp0); vs1.pushVector(d_temp1); vs1.pushVector(d_temp2); distance = d_temp0.distance(d_temp1); cout << endl << "Distance (0,1):" << endl; cout << distance << endl; cout << endl; distance = d_temp1.distance(d_temp2); cout << endl << "Distance (1,2):" << endl; cout << distance << endl; cout << endl; distance = d_temp0.distance(d_temp2); cout << endl << "Distance (0,2):" << endl; cout << distance << endl; cout << endl; vector<kmCluster> clusters; // a collection of clusters kmCluster * a_cluster; // a cluster ptr a_cluster = new kmCluster(); // create new cluster a_cluster->addDocument(&d_temp0); a_cluster->addDocument(&d_temp1); a_cluster->addDocument(&d_temp2); a_cluster->do_centroid(); cout << "Centroid is " << a_cluster->getCentroid(); }inline void usage(){ cerr << "Usage: test -k[kmeans]|-s[shingle]" <<endl; exit(0);}int main(int argc, char** argv){ int option_char; bool shingleStart, kmeansStart; shingleStart = kmeansStart = false; while((option_char = getopt(argc, argv, "sk")) != -1){ switch(option_char){ case 's' :shingleStart = true; break; case 'k' : kmeansStart = true; break; case '?' : usage(); break; default: break; } } if ((shingleStart && kmeansStart) || (!shingleStart && !kmeansStart)) { usage();} Clustering * clusterAlgo; if (shingleStart){ clusterAlgo = new SHINGLES(); // invoke the cluster algo cout << "Shingling"<< endl; } else { clusterAlgo = new KMEANS(); // invoke the cluster algo cout << "Kmeaning"<< endl; } Reader * reader = new simpleReader(); // a simple reader clusterAlgo->initialize(); reader->loadDataSet(clusterAlgo); // load the dataset clusterAlgo->do_clustering(); // do the clustering}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -