[storage] Normalize CountryTree keys

This commit is contained in:
tatiana-yan 2019-05-23 12:52:06 +03:00 committed by mpimenov
parent 28a21c83ee
commit 858b73e516
2 changed files with 19 additions and 7 deletions

View file

@ -50,16 +50,13 @@ UNIT_TEST(CountriesNamesTest)
// todo: (@t.yan) fix names for countries which have separate mwms.
set<string> const kIgnoreList = {"American Samoa",
"Sāmoa",
"Pitcairn",
"South Georgia and South Sandwich Islands",
"Lesotho",
"Eswatini",
"Republic of the Congo",
"Democratic Republic of the Congo",
"Aruba",
"Sint Maarten",
"Bahamas",
"Cabo Verde",
"Ivory Coast",
"Palestinian Territories",
@ -70,7 +67,6 @@ UNIT_TEST(CountriesNamesTest)
"Kosovo",
"Czechia",
"Transnistria",
"Republic of Belarus",
"Hong Kong",
"Guam",
// MAPSME-10611

View file

@ -4,6 +4,7 @@
#include "storage/storage_defines.hpp"
#include "base/assert.hpp"
#include "base/string_utils.hpp"
#include <algorithm>
#include <functional>
@ -179,7 +180,7 @@ public:
}
ASSERT(added, ());
m_countryTreeHashTable.insert(make_pair(value.Name(), added));
m_countryTreeHashTable.insert(make_pair(Normalize(value.Name()), added));
return added->Value();
}
@ -199,10 +200,11 @@ public:
if (IsEmpty())
return;
if (key == m_countryTree->Value().Name())
auto const normalizedKey = Normalize(key);
if (normalizedKey == Normalize(m_countryTree->Value().Name()))
found.push_back(m_countryTree.get());
auto const range = m_countryTreeHashTable.equal_range(key);
auto const range = m_countryTreeHashTable.equal_range(normalizedKey);
if (range.first == range.second)
return;
@ -218,6 +220,7 @@ public:
return nullptr;
std::vector<Node const *> found;
// |key| will be normalized inside Find.
Find(key, found);
if (found.empty())
return nullptr;
@ -235,6 +238,7 @@ public:
return nullptr;
std::vector<Node const *> found;
// |key| will be normalized inside Find.
Find(key, found);
for (auto node : found)
@ -248,6 +252,18 @@ public:
private:
using CountryTreeHashTable = std::multimap<CountryId, Node *>;
static CountryId Normalize(CountryId const & id)
{
auto normalized = strings::Normalize(id);
strings::MakeLowerCaseInplace(normalized);
if (strings::StartsWith(normalized, "the "))
normalized.erase(0, 4);
size_t pos = 0;
while ((pos = normalized.find(" the "), pos) != std::string::npos)
normalized.erase(pos, 4);
return normalized;
}
std::unique_ptr<Node> m_countryTree;
CountryTreeHashTable m_countryTreeHashTable;
};