[generator] Change feature id to osm id mapping type from uint32_t->vector<GeoObjectId> to uint32_t->GeoObjectId

This commit is contained in:
tatiana-yan 2019-04-19 16:21:39 +03:00 committed by mpimenov
parent 9a0b1fb87c
commit 0bda46a66d
8 changed files with 32 additions and 39 deletions

View file

@ -39,8 +39,7 @@ namespace generator
{
namespace
{
bool ParseFeatureIdToTestIdMapping(string const & path,
unordered_map<uint32_t, vector<uint64_t>> & mapping)
bool ParseFeatureIdToTestIdMapping(string const & path, unordered_map<uint32_t, uint64_t> & mapping)
{
bool success = true;
feature::ForEachFromDat(path, [&](FeatureType & feature, uint32_t fid) {
@ -53,7 +52,7 @@ bool ParseFeatureIdToTestIdMapping(string const & path,
success = false;
return;
}
mapping[fid].push_back(tid);
mapping.emplace(fid, tid);
});
return success;
}
@ -86,11 +85,8 @@ bool BuildCitiesBoundaries(string const & dataPath, BoundariesTable & table,
auto it = mapping->find(base::asserted_cast<uint32_t>(fid));
if (it != mapping->end())
{
for (auto const & id : it->second)
{
auto const & b = table.Get(id);
bs.insert(bs.end(), b.begin(), b.end());
}
auto const & b = table.Get(it->second);
bs.insert(bs.end(), b.begin(), b.end());
}
all.emplace_back(move(bs));
@ -107,7 +103,7 @@ bool BuildCitiesBoundaries(string const & dataPath, BoundariesTable & table,
bool BuildCitiesBoundaries(string const & dataPath, string const & osmToFeaturePath,
OsmIdToBoundariesTable & table)
{
using Mapping = unordered_map<uint32_t, vector<base::GeoObjectId>>;
using Mapping = unordered_map<uint32_t, base::GeoObjectId>;
return BuildCitiesBoundaries(dataPath, table, [&]() -> unique_ptr<Mapping> {
Mapping mapping;
@ -122,7 +118,7 @@ bool BuildCitiesBoundaries(string const & dataPath, string const & osmToFeatureP
bool BuildCitiesBoundariesForTesting(string const & dataPath, TestIdToBoundariesTable & table)
{
using Mapping = unordered_map<uint32_t, vector<uint64_t>>;
using Mapping = unordered_map<uint32_t, uint64_t>;
return BuildCitiesBoundaries(dataPath, table, [&]() -> unique_ptr<Mapping> {
Mapping mapping;

View file

@ -55,10 +55,10 @@ WikidataHelper::WikidataHelper(std::string const & mwmPath, std::string const &
boost::optional<std::string> WikidataHelper::GetWikidataId(uint32_t featureId) const
{
auto const itFeatureIdToOsmId = m_featureIdToOsmId.find(featureId);
if (itFeatureIdToOsmId == std::end(m_featureIdToOsmId) || itFeatureIdToOsmId->second.size() == 0)
if (itFeatureIdToOsmId == std::end(m_featureIdToOsmId))
return {};
auto const osmId = itFeatureIdToOsmId->second[0];
auto const osmId = itFeatureIdToOsmId->second;
auto const itOsmIdToWikidataId = m_osmIdToWikidataId.find(osmId);
return itOsmIdToWikidataId == std::end(m_osmIdToWikidataId) ?
boost::optional<std::string>() : itOsmIdToWikidataId->second;

View file

@ -24,7 +24,6 @@
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <boost/optional.hpp>
@ -46,7 +45,7 @@ public:
private:
std::string m_mwmPath;
std::string m_idToWikidataPath;
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> m_featureIdToOsmId;
std::unordered_map<uint32_t, base::GeoObjectId> m_featureIdToOsmId;
std::unordered_map<base::GeoObjectId, std::string> m_osmIdToWikidataId;
};

View file

@ -71,7 +71,7 @@ bool BuildPopularPlacesMwmSection(std::string const & srcFilename, std::string c
LOG(LINFO, ("Build Popular Places section"));
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> featureIdToOsmId;
std::unordered_map<uint32_t, base::GeoObjectId> featureIdToOsmId;
if (!ParseFeatureIdToOsmIdMapping(osmToFeatureFilename, featureIdToOsmId))
return false;
@ -88,9 +88,9 @@ bool BuildPopularPlacesMwmSection(std::string const & srcFilename, std::string c
PopularityIndex rank = 0;
auto const it = featureIdToOsmId.find(featureId);
// Non-OSM features (coastlines, sponsored objects) are not used.
if (it != featureIdToOsmId.cend() && it->second.size() != 0)
if (it != featureIdToOsmId.cend())
{
auto const placesIt = places.find(it->second[0]);
auto const placesIt = places.find(it->second);
if (placesIt != places.cend())
{

View file

@ -24,7 +24,7 @@ bool BuildRatingsMwmSection(std::string const & srcDbFilename, std::string const
{
LOG(LINFO, ("Build Ratings section"));
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> featureToOsmId;
std::unordered_map<uint32_t, base::GeoObjectId> featureToOsmId;
if (!ParseFeatureIdToOsmIdMapping(osmToFeatureFilename, featureToOsmId))
return false;
@ -34,12 +34,11 @@ bool BuildRatingsMwmSection(std::string const & srcDbFilename, std::string const
uint8_t constexpr kNoRating = 0;
feature::ForEachFromDat(mwmFile, [&](FeatureType & f, uint32_t featureId) {
auto const it = featureToOsmId.find(featureId);
CHECK(it != featureToOsmId.cend() && !it->second.empty(),
("FeatureID", featureId, "is not found in", osmToFeatureFilename));
ugc::UGC ugc;
if (GetUgcForFeature(it->second[0], feature::TypesHolder(f), translator, ugc))
auto const it = featureToOsmId.find(featureId);
// Non-OSM features (coastlines, sponsored objects) are not used.
if (it != featureToOsmId.cend() &&
GetUgcForFeature(it->second, feature::TypesHolder(f), translator, ugc))
{
content.emplace_back(ugc.GetPackedRating());
haveUgc = true;

View file

@ -24,7 +24,7 @@ bool BuildUgcMwmSection(std::string const & srcDbFilename, std::string const & m
LOG(LINFO, ("Build UGC section"));
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> featureToOsmId;
std::unordered_map<uint32_t, base::GeoObjectId> featureToOsmId;
if (!ParseFeatureIdToOsmIdMapping(osmToFeatureFilename, featureToOsmId))
return false;
@ -34,11 +34,12 @@ bool BuildUgcMwmSection(std::string const & srcDbFilename, std::string const & m
feature::ForEachFromDat(mwmFile, [&](FeatureType & f, uint32_t featureId) {
auto const it = featureToOsmId.find(featureId);
CHECK(it != featureToOsmId.cend() && it->second.size() != 0,
("FeatureID", featureId, "is not found in", osmToFeatureFilename));
// Non-OSM features (coastlines, sponsored objects) are not used.
if (it == featureToOsmId.cend())
return;
ugc::UGC result;
if (!GetUgcForFeature(it->second[0], feature::TypesHolder(f), translator, result))
if (!GetUgcForFeature(it->second, feature::TypesHolder(f), translator, result))
return;
content.emplace_back(featureId, result);

View file

@ -7,6 +7,8 @@
#include "base/assert.hpp"
#include "base/logging.hpp"
#include <vector>
namespace generator
{
// SingleMwmDataSource -----------------------------------------------------------------------------
@ -26,7 +28,7 @@ SingleMwmDataSource::SingleMwmDataSource(std::string const & mwmPath)
void LoadDataSource(DataSource & dataSource)
{
vector<platform::LocalCountryFile> localFiles;
std::vector<platform::LocalCountryFile> localFiles;
Platform & platform = GetPlatform();
platform::FindAllLocalMapsInDirectoryAndCleanup(platform.WritableDir(), 0 /* version */,
@ -45,13 +47,11 @@ void LoadDataSource(DataSource & dataSource)
}
}
bool ParseFeatureIdToOsmIdMapping(
std::string const & path,
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> & mapping)
bool ParseFeatureIdToOsmIdMapping(std::string const & path,
std::unordered_map<uint32_t, base::GeoObjectId> & mapping)
{
return ForEachOsmId2FeatureId(path,
[&](base::GeoObjectId const & osmId, uint32_t const featureId) {
mapping[featureId].push_back(osmId);
});
return ForEachOsmId2FeatureId(path, [&](base::GeoObjectId const & osmId, uint32_t const featureId) {
CHECK(mapping.emplace(featureId, osmId).second, ("Several osm ids for feature", featureId, "in file", path));
});
}
} // namespace generator

View file

@ -17,7 +17,6 @@
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>
namespace generator
{
@ -63,7 +62,6 @@ bool ForEachOsmId2FeatureId(std::string const & path, ToDo && toDo)
return true;
}
bool ParseFeatureIdToOsmIdMapping(
std::string const & path,
std::unordered_map<uint32_t, std::vector<base::GeoObjectId>> & mapping);
bool ParseFeatureIdToOsmIdMapping(std::string const & path,
std::unordered_map<uint32_t, base::GeoObjectId> & mapping);
} // namespace generator