[geocoder] Print the address in the command line tool.

This commit is contained in:
Maxim Pimenov 2018-12-12 14:59:28 +03:00 committed by Tatiana Yan
parent 5bd46a0144
commit ef165be9f2
3 changed files with 40 additions and 4 deletions

View file

@ -1,6 +1,7 @@
#include "geocoder/geocoder.hpp"
#include "geocoder/result.hpp"
#include "base/internal/message.hpp"
#include "base/string_utils.hpp"
#include <fstream>
@ -17,7 +18,7 @@ DEFINE_string(hierarchy_path, "", "Path to the hierarchy file for the geocoder")
DEFINE_string(queries_path, "", "Path to the file with queries");
DEFINE_int32(top, 5, "Number of top results to show for every query, -1 to show all results");
void PrintResults(vector<Result> const & results)
void PrintResults(Hierarchy const & hierarchy, vector<Result> const & results)
{
cout << "Found results: " << results.size() << endl;
if (results.empty())
@ -27,7 +28,11 @@ void PrintResults(vector<Result> const & results)
{
if (FLAGS_top >= 0 && i >= FLAGS_top)
break;
cout << " " << DebugPrint(results[i]) << endl;
Hierarchy::Entry const * e = hierarchy.GetEntryForOsmId(results[i].m_osmId);
cout << " " << DebugPrint(results[i]);
if (e != nullptr)
cout << " " << DebugPrint(e->m_address);
cout << endl;
}
}
@ -48,7 +53,7 @@ void ProcessQueriesFromFile(string const & path)
cout << s << endl;
geocoder.ProcessQuery(s, results);
PrintResults(results);
PrintResults(geocoder.GetHierarchy(), results);
cout << endl;
}
}
@ -67,7 +72,7 @@ void ProcessQueriesFromCommandLine()
if (query == "q" || query == ":q" || query == "quit")
break;
geocoder.ProcessQuery(query, results);
PrintResults(results);
PrintResults(geocoder.GetHierarchy(), results);
}
}

View file

@ -9,6 +9,7 @@
#include "base/stl_helpers.hpp"
#include "base/string_utils.hpp"
#include <algorithm>
#include <fstream>
#include <utility>
@ -149,6 +150,12 @@ Hierarchy::Hierarchy(string const & pathToJsonHierarchy)
m_entriesStorage.emplace_back(move(entry));
}
if (stats.m_numLoaded % kLogBatch != 0)
LOG(LINFO, ("Read", stats.m_numLoaded, "entries"));
LOG(LINFO, ("Sorting entries..."));
sort(m_entriesStorage.begin(), m_entriesStorage.end());
LOG(LINFO, ("Indexing entries..."));
IndexEntries();
LOG(LINFO, ("Indexing houses..."));
@ -175,6 +182,20 @@ vector<Hierarchy::Entry *> const * const Hierarchy::GetEntries(Tokens const & to
return &it->second;
}
Hierarchy::Entry const * Hierarchy::GetEntryForOsmId(base::GeoObjectId const & osmId) const
{
auto const cmp = [](Hierarchy::Entry const & e, base::GeoObjectId const & id) {
return e.m_osmId < id;
};
auto it = lower_bound(m_entriesStorage.begin(), m_entriesStorage.end(), osmId, cmp);
if (it == m_entriesStorage.end() || it->m_osmId != osmId)
return nullptr;
return &(*it);
}
void Hierarchy::IndexEntries()
{
size_t numIndexed = 0;
@ -203,6 +224,9 @@ void Hierarchy::IndexEntries()
if (numIndexed % kLogBatch == 0)
LOG(LINFO, ("Indexed", numIndexed, "entries"));
}
if (numIndexed % kLogBatch != 0)
LOG(LINFO, ("Indexed", numIndexed, "entries"));
}
void Hierarchy::IndexStreet(Entry & e)
@ -245,5 +269,8 @@ void Hierarchy::IndexHouses()
if (numIndexed % kLogBatch == 0)
LOG(LINFO, ("Indexed", numIndexed, "houses"));
}
if (numIndexed % kLogBatch != 0)
LOG(LINFO, ("Indexed", numIndexed, "houses"));
}
} // namespace geocoder

View file

@ -59,6 +59,8 @@ public:
// Checks whether this entry is a parent of |e|.
bool IsParentTo(Entry const & e) const;
bool operator<(Entry const & rhs) const { return m_osmId < rhs.m_osmId; }
base::GeoObjectId m_osmId = base::GeoObjectId(base::GeoObjectId::kInvalid);
// Original name of the entry. Useful for debugging.
@ -86,6 +88,8 @@ public:
// be implemented to perform this type of queries.
std::vector<Entry *> const * const GetEntries(Tokens const & tokens) const;
Entry const * GetEntryForOsmId(base::GeoObjectId const & osmId) const;
private:
// Adds address information of entries to the index.
void IndexEntries();