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:
authortatiana-yan <tatiana.kondakova@gmail.com>2019-05-24 15:19:15 +0300
committermpimenov <mpimenov@users.noreply.github.com>2019-05-27 17:08:42 +0300
commite08a9d988ea63fd625bdcdaac646bfac41060c43 (patch)
tree14cbf7d7df2e3f3f599294b1d1ff04f48ec6da6b /storage
parent3cd6936c9e04bc1a0a886fd4644cce3f0fb40eea (diff)
[storage] Add optional country_name_synonyms parameter to countries.txt to find corresponding CountryId by country name without countries.txt keys modification.
Diffstat (limited to 'storage')
-rw-r--r--storage/country_tree.cpp45
-rw-r--r--storage/country_tree.hpp8
-rw-r--r--storage/storage.cpp8
-rw-r--r--storage/storage.hpp3
-rw-r--r--storage/storage_defines.hpp4
5 files changed, 54 insertions, 14 deletions
diff --git a/storage/country_tree.cpp b/storage/country_tree.cpp
index 6ca3d728fb..bf6b47a207 100644
--- a/storage/country_tree.cpp
+++ b/storage/country_tree.cpp
@@ -33,6 +33,7 @@ public:
CountryId const & parent) = 0;
virtual void InsertOldMwmMapping(CountryId const & newId, CountryId const & oldId) = 0;
virtual void InsertAffiliation(CountryId const & countryId, string const & affilation) = 0;
+ virtual void InsertCountryNameSynonym(CountryId const & countryId, string const & synonym) = 0;
virtual OldMwmMapping GetMapping() const = 0;
};
@@ -40,11 +41,15 @@ class StoreCountriesSingleMwms : public StoreSingleMwmInterface
{
CountryTree & m_countries;
Affiliations & m_affiliations;
+ CountryNameSynonyms & m_countryNameSynonyms;
OldMwmMapping m_idsMapping;
public:
- StoreCountriesSingleMwms(CountryTree & countries, Affiliations & affiliations)
- : m_countries(countries), m_affiliations(affiliations)
+ StoreCountriesSingleMwms(CountryTree & countries, Affiliations & affiliations,
+ CountryNameSynonyms & countryNameSynonyms)
+ : m_countries(countries)
+ , m_affiliations(affiliations)
+ , m_countryNameSynonyms(countryNameSynonyms)
{
}
~StoreCountriesSingleMwms()
@@ -81,6 +86,17 @@ public:
m_affiliations[affilation].push_back(countryId);
}
+ void InsertCountryNameSynonym(CountryId const & countryId, string const & synonym) override
+ {
+ ASSERT(!synonym.empty(), ());
+ ASSERT(!countryId.empty(), ());
+ ASSERT(m_countryNameSynonyms.find(synonym) == m_countryNameSynonyms.end(),
+ ("Synonym must identify CountryTree node where the country is located. Country cannot be "
+ "located at multiple nodes."));
+
+ m_countryNameSynonyms[synonym] = countryId;
+ }
+
OldMwmMapping GetMapping() const override { return m_idsMapping; }
};
@@ -104,10 +120,17 @@ public:
}
void InsertOldMwmMapping(CountryId const & /* newId */, CountryId const & /* oldId */) override {}
+
void InsertAffiliation(CountryId const & /* countryId */,
string const & /* affilation */) override
{
}
+
+ void InsertCountryNameSynonym(CountryId const & /* countryId */,
+ string const & /* synonym */) override
+ {
+ }
+
OldMwmMapping GetMapping() const override
{
ASSERT(false, ());
@@ -122,6 +145,11 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(size_t depth, json_t * node, CountryId
CountryId id;
FromJSONObject(node, "id", id);
+ vector<string> countryNameSynonyms;
+ FromJSONObjectOptionalField(node, "country_name_synonyms", countryNameSynonyms);
+ for (auto const & synonym : countryNameSynonyms)
+ store.InsertCountryNameSynonym(id, synonym);
+
// Mapping two component (big) mwms to one componenst (small) ones.
vector<string> oldIds;
FromJSONObjectOptionalField(node, "old", oldIds);
@@ -199,7 +227,8 @@ class StoreCountriesTwoComponentMwms : public StoreTwoComponentMwmInterface
CountryTree & m_countries;
public:
- StoreCountriesTwoComponentMwms(CountryTree & countries, Affiliations & /* affiliations */)
+ StoreCountriesTwoComponentMwms(CountryTree & countries, Affiliations & /* affiliations */,
+ CountryNameSynonyms & /* countryNameSynonyms */)
: m_countries(countries)
{
}
@@ -308,6 +337,7 @@ bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer,
int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countries,
Affiliations & affiliations,
+ CountryNameSynonyms & countryNameSynonyms,
OldMwmMapping * mapping /* = nullptr */)
{
countries.Clear();
@@ -321,7 +351,7 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri
if (version::IsSingleMwm(version))
{
- StoreCountriesSingleMwms store(countries, affiliations);
+ StoreCountriesSingleMwms store(countries, affiliations, countryNameSynonyms);
if (!LoadCountriesSingleMwmsImpl(jsonBuffer, store))
return -1;
if (mapping)
@@ -329,7 +359,7 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri
}
else
{
- StoreCountriesTwoComponentMwms store(countries, affiliations);
+ StoreCountriesTwoComponentMwms store(countries, affiliations, countryNameSynonyms);
if (!LoadCountriesTwoComponentMwmsImpl(jsonBuffer, store))
return -1;
}
@@ -342,11 +372,12 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri
}
int64_t LoadCountriesFromFile(string const & path, CountryTree & countries,
- Affiliations & affiliations, OldMwmMapping * mapping)
+ Affiliations & affiliations,
+ CountryNameSynonyms & countryNameSynonyms, OldMwmMapping * mapping)
{
string json;
ReaderPtr<Reader>(GetPlatform().GetReader(path)).ReadAsString(json);
- return LoadCountriesFromBuffer(json, countries, affiliations, mapping);
+ return LoadCountriesFromBuffer(json, countries, affiliations, countryNameSynonyms, mapping);
}
void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryInfo> & id2info,
diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp
index 6d266d298b..18c2ac1554 100644
--- a/storage/country_tree.hpp
+++ b/storage/country_tree.hpp
@@ -254,9 +254,13 @@ private:
/// @return version of country file or -1 if error was encountered
int64_t LoadCountriesFromBuffer(std::string const & buffer, CountryTree & countries,
- Affiliations & affiliations, OldMwmMapping * mapping = nullptr);
+ Affiliations & affiliations,
+ CountryNameSynonyms & countryNameSynonyms,
+ OldMwmMapping * mapping = nullptr);
int64_t LoadCountriesFromFile(std::string const & path, CountryTree & countries,
- Affiliations & affiliations, OldMwmMapping * mapping = nullptr);
+ Affiliations & affiliations,
+ CountryNameSynonyms & countryNameSynonyms,
+ OldMwmMapping * mapping = nullptr);
void LoadCountryFile2CountryInfo(std::string const & jsonBuffer,
std::map<std::string, CountryInfo> & id2info, bool & isSingleMwm);
diff --git a/storage/storage.cpp b/storage/storage.cpp
index 6b3ddcd35d..f830a01262 100644
--- a/storage/storage.cpp
+++ b/storage/storage.cpp
@@ -141,8 +141,8 @@ Storage::Storage(string const & referenceCountriesTxtJsonForTesting,
, m_downloadMapOnTheMap(nullptr)
, m_maxMwmSizeBytes(0)
{
- m_currentVersion =
- LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations);
+ m_currentVersion = LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries,
+ m_affiliations, m_countryNameSynonyms);
CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file"));
CalcMaxMwmSizeBytes();
}
@@ -762,8 +762,8 @@ void Storage::LoadCountriesFile(string const & pathToCountriesFile, string const
if (m_countries.IsEmpty())
{
- m_currentVersion =
- LoadCountriesFromFile(pathToCountriesFile, m_countries, m_affiliations, mapping);
+ m_currentVersion = LoadCountriesFromFile(pathToCountriesFile, m_countries, m_affiliations,
+ m_countryNameSynonyms, mapping);
LOG_SHORT(LINFO, ("Loaded countries list for version:", m_currentVersion));
if (m_currentVersion < 0)
LOG(LERROR, ("Can't load countries file", pathToCountriesFile));
diff --git a/storage/storage.hpp b/storage/storage.hpp
index 1ac3322ba0..dd36b1a2a0 100644
--- a/storage/storage.hpp
+++ b/storage/storage.hpp
@@ -263,6 +263,7 @@ private:
// Once filled |m_affiliations| is not changed.
// Note. |m_affiliations| is empty in case of countries_obsolete.txt.
Affiliations m_affiliations;
+ CountryNameSynonyms m_countryNameSynonyms;
MwmSize m_maxMwmSizeBytes;
@@ -469,6 +470,8 @@ public:
Affiliations const & GetAffiliations() const { return m_affiliations; }
+ CountryNameSynonyms const & GetCountryNameSynonyms() const { return m_countryNameSynonyms; }
+
/// \brief Calls |toDo| for each node for subtree with |root|.
/// For example ForEachInSubtree(GetRootId()) calls |toDo| for every node including
/// the result of GetRootId() call.
diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp
index c720dda172..4d4cefd36a 100644
--- a/storage/storage_defines.hpp
+++ b/storage/storage_defines.hpp
@@ -19,8 +19,10 @@ using CountriesSet = std::set<CountryId>;
using CountriesVec = std::vector<CountryId>;
using LocalFilePtr = std::shared_ptr<platform::LocalCountryFile>;
using OldMwmMapping = std::map<CountryId, CountriesSet>;
-/// Map from key affiliation words into MWM IDs (file names).
+/// Map from key affiliation words into CountryIds.
using Affiliations = std::unordered_map<std::string, std::vector<CountryId>>;
+/// Map from country name synonyms and old names into CountryId.
+using CountryNameSynonyms = std::unordered_map<std::string, CountryId>;
extern const storage::CountryId kInvalidCountryId;