diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2011-05-16 03:10:22 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:17:20 +0300 |
commit | cfd16d8c8b9b403c9afd2fc835f5b89ca0f6d607 (patch) | |
tree | 17858d250062f2b6f2d59a4a3fcd95f0a8a3c380 /generator/dumper.cpp | |
parent | 7449344cdb66ac2f27ea63f99976e5f9c103fcc9 (diff) |
[generator_tool] Added feature types dumper
Usage: ./generator_tool -dump_types -output=<mwmFileWithoutExt>
Diffstat (limited to 'generator/dumper.cpp')
-rw-r--r-- | generator/dumper.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/generator/dumper.cpp b/generator/dumper.cpp new file mode 100644 index 0000000000..ca91d3f4de --- /dev/null +++ b/generator/dumper.cpp @@ -0,0 +1,60 @@ +#include "dumper.hpp" + +#include "../indexer/feature_processor.hpp" +#include "../indexer/classificator.hpp" + +#include "../std/vector.hpp" +#include "../std/unordered_map.hpp" +#include "../std/iostream.hpp" + +namespace feature +{ + class TypesCollector + { + vector<uint32_t> m_currFeatureTypes; + + public: + typedef unordered_map<vector<uint32_t>, size_t> value_type; + value_type m_stats; + + void operator()(FeatureType & f, uint32_t) + { + m_currFeatureTypes.clear(); + f.ForEachTypeRef(*this); + CHECK(!m_currFeatureTypes.empty(), ("Feature without any type???")); + pair<value_type::iterator, bool> found = m_stats.insert(make_pair(m_currFeatureTypes, 1)); + if (!found.second) + found.first->second++; + } + + void operator()(uint32_t type) + { + m_currFeatureTypes.push_back(type); + } + }; + + typedef pair<vector<uint32_t>, size_t> stats_elem_type; + static bool SortFunc(stats_elem_type const & first, + stats_elem_type const & second) + { + return first.second > second.second; + } + + void DumpTypes(string const & datFile) + { + TypesCollector doClass; + feature::ForEachFromDat(datFile, doClass); + + typedef vector<stats_elem_type> vec_to_sort; + vec_to_sort vecToSort(doClass.m_stats.begin(), doClass.m_stats.end()); + sort(vecToSort.begin(), vecToSort.end(), SortFunc); + + for (vec_to_sort::iterator it = vecToSort.begin(); it != vecToSort.end(); ++it) + { + cout << it->second << " "; + for (size_t i = 0; i < it->first.size(); ++i) + cout << classif().GetFullObjectName(it->first[i]) << " "; + cout << endl; + } + } +} |