Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2018-12-12 14:59:28 +0300
committerTatiana Yan <tatiana.kondakova@gmail.com>2018-12-13 17:40:37 +0300
commitef165be9f2a08b816cd051f7d7b9bfce648a6c96 (patch)
treeb6375916550a7008300fc513ef17a73ea642d26a /geocoder
parent5bd46a0144339fb35e9c1cba55050dcdadc7a67f (diff)
[geocoder] Print the address in the command line tool.
Diffstat (limited to 'geocoder')
-rw-r--r--geocoder/geocoder_cli/geocoder_cli.cpp13
-rw-r--r--geocoder/hierarchy.cpp27
-rw-r--r--geocoder/hierarchy.hpp4
3 files changed, 40 insertions, 4 deletions
diff --git a/geocoder/geocoder_cli/geocoder_cli.cpp b/geocoder/geocoder_cli/geocoder_cli.cpp
index 629d830cfe..bf7da7b589 100644
--- a/geocoder/geocoder_cli/geocoder_cli.cpp
+++ b/geocoder/geocoder_cli/geocoder_cli.cpp
@@ -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);
}
}
diff --git a/geocoder/hierarchy.cpp b/geocoder/hierarchy.cpp
index 0a92899221..bf8c43ecab 100644
--- a/geocoder/hierarchy.cpp
+++ b/geocoder/hierarchy.cpp
@@ -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
diff --git a/geocoder/hierarchy.hpp b/geocoder/hierarchy.hpp
index 8880b5460b..0197279d4e 100644
--- a/geocoder/hierarchy.hpp
+++ b/geocoder/hierarchy.hpp
@@ -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();