-
Notifications
You must be signed in to change notification settings - Fork 85
/
resave.cpp
87 lines (72 loc) · 2.02 KB
/
resave.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Copyright (C) 2013,2014 Wei Dong <wdong@wdong.org>. All Rights Reserved.
*/
#include <sys/time.h>
#include <cctype>
#include <random>
#include <iomanip>
#include <type_traits>
#include <boost/timer/timer.hpp>
#include <boost/tr1/random.hpp>
#include <boost/format.hpp>
#include <boost/program_options.hpp>
#include "kgraph.h"
#include "kgraph-data.h"
using namespace std;
using namespace boost;
using namespace boost::timer;
using namespace kgraph;
namespace po = boost::program_options;
class DummyIndexOracle: public IndexOracle {
public:
/// Returns the size of the dataset.
virtual unsigned size () const {
throw 0;
return 0;
}
/// Computes similarity
/**
* 0 <= i, j < size() are the index of two objects in the dataset.
* This method return the distance between objects i and j.
*/
virtual float operator () (unsigned i, unsigned j) const {
throw 0;
return 0;
}
};
int main (int argc, char *argv[]) {
string input_path;
string output_path;
int format = 0;
int prune = 0;
po::options_description desc("General options");
desc.add_options()
("help,h", "produce help message.")
("input", po::value(&input_path), "")
("output", po::value(&output_path), "")
("prune", po::value(&prune), "")
("no-dist", "")
;
po::positional_options_description p;
p.add("input", 1);
p.add("output", 1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help") || vm.count("input") == 0) {
cout << desc << endl;
return 0;
}
if (vm.count("no-dist")) format |= kgraph::KGraph::FORMAT_NO_DIST;
KGraph *kgraph = kgraph::KGraph::create();
kgraph->load(input_path.c_str());
if (vm.count("prune")) {
DummyIndexOracle o;
kgraph->prune(o, prune);
}
if (vm.count("output")) {
kgraph->save(output_path.c_str(), format);
}
delete kgraph;
return 0;
}