Tree Compression with Top Trees Revisited
strip.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 
4 #include "Edges.h"
5 #include "Nodes.h"
6 #include "OrderedTree.h"
7 
8 #include "XML.h"
9 
10 #include "ArgParser.h"
11 
12 using std::cout;
13 using std::endl;
14 using std::string;
15 
16 int main(int argc, char **argv) {
18 
19  Labels<string> labels(0);
20 
21  ArgParser argParser(argc, argv);
22  string filename = argParser.get<string>("i", "data/1998statistics.xml");
23  string outputfolder = argParser.get<string>("o", "/tmp");
24  const bool indent = argParser.isSet("p");
25 
26  // Read input file
27  XmlParser<OrderedTree<TreeNode, TreeEdge>>::parse(filename, t, labels);
28 
29  const int nodes(t._numNodes), height(t.height());
30  const double avgDepth(t.avgDepth());
31  cout << t.summary() << "; Height: " << height << " Avg depth: " << avgDepth << endl;
32 
33  // Dump input file for comparison of output
34  Timer timer;
35  auto pos = filename.find_last_of("/\\");
36  string outname = outputfolder + "/" + filename.substr(pos + 1) + ".stripped";
37  XmlWriter<OrderedTree<TreeNode, TreeEdge>>::write(t, labels, outname, indent);
38 
39  cout << "Wrote trimmed XML file in " << timer.getAndReset() << "ms: " << t.summary() << endl;
40 
41  // Get size
42  std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
43  auto origSize = in.tellg();
44  std::ifstream in2(outname, std::ifstream::ate | std::ifstream::binary);
45  auto strippedSize = in2.tellg();
46 
47  cout << "RESULT"
48  << " file=" << filename
49  << " origSize=" << origSize
50  << " strippedSize=" << strippedSize
51  << " nodes=" << nodes
52  << " height=" << height
53  << " avgDepth=" << avgDepth
54  << endl;
55 
56  return 0;
57 }
int height() const
Definition: OrderedTree.h:571
int main(int argc, char **argv)
Definition: strip.cpp:16
Ordered tree data structure.
Definition: OrderedTree.h:37
double avgDepth() const
Definition: OrderedTree.h:579
bool isSet(const string &arg) const
check whether an argument was set
Definition: ArgParser.h:58
Read an XML file into a tree, using RapidXml.
Definition: XML.h:23
Parse command-line arguments.
Definition: ArgParser.h:21
T get(const string &key, const T defaultValue=T())
Definition: ArgParser.h:44
string summary() const
A one-line summary of the tree.
Definition: OrderedTree.h:348
A flexible timer.
Definition: Timer.h:14
XML tree writer (empty template for overloading)
Definition: XML.h:68
ReturnType getAndReset()
Definition: Timer.h:29
A key-value label storage.
Definition: Labels.h:107