Skip to content

Commit

Permalink
[indexer][generator][editor] Return postcodes to metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana-yan authored and mpimenov committed Oct 2, 2020
1 parent 12021ce commit dd24ed3
Show file tree
Hide file tree
Showing 31 changed files with 139 additions and 382 deletions.
2 changes: 2 additions & 0 deletions editor/editor_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static unordered_map<string, EType> const kNamesToFMD = {
// {"", feature::Metadata::FMD_TURN_LANES_FORWARD},
// {"", feature::Metadata::FMD_TURN_LANES_BACKWARD},
{"email", feature::Metadata::FMD_EMAIL},
{"postcode", feature::Metadata::FMD_POSTCODE},
{"wikipedia", feature::Metadata::FMD_WIKIPEDIA},
// {"", feature::Metadata::FMD_MAXSPEED},
{"flats", feature::Metadata::FMD_FLATS},
Expand Down Expand Up @@ -133,6 +134,7 @@ bool EditorConfig::GetTypeDescription(vector<string> classificatorTypes,
{
outDesc.m_address = isBuilding = true;
outDesc.m_editableFields.push_back(feature::Metadata::FMD_BUILDING_LEVELS);
outDesc.m_editableFields.push_back(feature::Metadata::FMD_POSTCODE);
classificatorTypes.erase(it);
break;
}
Expand Down
5 changes: 0 additions & 5 deletions editor/editor_tests/xml_feature_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ UNIT_TEST(XMLFeature_Setters)
feature.SetName("int_name", "Gorky Park");

feature.SetHouse("10");
feature.SetPostcode("127001");
feature.SetTagValue("opening_hours", "Mo-Fr 08:15-17:30");
feature.SetTagValue("amenity", "atm");

Expand All @@ -75,7 +74,6 @@ UNIT_TEST(XMLFeature_Setters)
<tag k="name:ru" v="Парк Горького" />
<tag k="int_name" v="Gorky Park" />
<tag k="addr:housenumber" v="10" />
<tag k="addr:postcode" v="127001" />
<tag k="opening_hours" v="Mo-Fr 08:15-17:30" />
<tag k="amenity" v="atm" />
</node>
Expand Down Expand Up @@ -169,7 +167,6 @@ auto const kTestNode = R"(<?xml version="1.0"?>
<tag k="name:ru" v="Парк Горького" />
<tag k="int_name" v="Gorky Park" />
<tag k="addr:housenumber" v="10" />
<tag k="addr:postcode" v="127001" />
<tag k="opening_hours" v="Mo-Fr 08:15-17:30" />
<tag k="amenity" v="atm" />
</node>
Expand All @@ -189,7 +186,6 @@ UNIT_TEST(XMLFeature_FromXml)
TEST(!feature.HasKey("FooBarBaz"), ());

TEST_EQUAL(feature.GetHouse(), "10", ());
TEST_EQUAL(feature.GetPostcode(), "127001", ());
TEST_EQUAL(feature.GetCenter(), ms::LatLon(55.7978998, 37.4745280), ());
TEST_EQUAL(feature.GetName(), "Gorki Park", ());
TEST_EQUAL(feature.GetName("default"), "Gorki Park", ());
Expand Down Expand Up @@ -367,7 +363,6 @@ UNIT_TEST(XMLFeature_FromXMLAndBackToXML)
<tag k="name:en" v="Gorki Park" />
<tag k="name:ru" v="Парк Горького" />
<tag k="addr:housenumber" v="10" />
<tag k="addr:postcode" v="127001" />
</node>
)";

Expand Down
3 changes: 0 additions & 3 deletions editor/osm_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ bool AreObjectsEqualButStreet(osm::EditableMapObject const & lhs,
if (lhs.GetHouseNumber() != rhs.GetHouseNumber())
return false;

if (lhs.GetPostcode() != rhs.GetPostcode())
return false;

if (lhs.GetCuisines() != rhs.GetCuisines())
return false;

Expand Down
17 changes: 0 additions & 17 deletions editor/xml_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ constexpr char const * kUploadTimestamp = "upload_timestamp";
constexpr char const * kUploadStatus = "upload_status";
constexpr char const * kUploadError = "upload_error";
constexpr char const * kHouseNumber = "addr:housenumber";
constexpr char const * kPostcode = "addr:postcode";
constexpr char const * kCuisine = "cuisine";

constexpr char const * kUnknownType = "unknown";
Expand Down Expand Up @@ -289,10 +288,6 @@ string XMLFeature::GetHouse() const { return GetTagValue(kHouseNumber); }

void XMLFeature::SetHouse(string const & house) { SetTagValue(kHouseNumber, house); }

string XMLFeature::GetPostcode() const { return GetTagValue(kPostcode); }

void XMLFeature::SetPostcode(string const & postcode) { SetTagValue(kPostcode, postcode); }

string XMLFeature::GetCuisine() const { return GetTagValue(kCuisine); }

void XMLFeature::SetCuisine(string const & cuisine) { SetTagValue(kCuisine, cuisine); }
Expand Down Expand Up @@ -430,10 +425,6 @@ void ApplyPatch(XMLFeature const & xml, osm::EditableMapObject & object)
if (!house.empty())
object.SetHouseNumber(house);

auto const postcode = xml.GetPostcode();
if (!postcode.empty())
object.SetPostcode(postcode);

auto const cuisineStr = xml.GetCuisine();
if (!cuisineStr.empty())
{
Expand Down Expand Up @@ -469,10 +460,6 @@ XMLFeature ToXML(osm::EditableMapObject const & object, bool serializeType)
if (!house.empty())
toFeature.SetHouse(house);

auto const postcode = object.GetPostcode();
if (!postcode.empty())
toFeature.SetPostcode(postcode);

auto const cuisines = object.GetCuisines();
if (!cuisines.empty())
{
Expand Down Expand Up @@ -552,10 +539,6 @@ bool FromXML(XMLFeature const & xml, osm::EditableMapObject & object)
if (!house.empty())
object.SetHouseNumber(house);

auto const postcode = xml.GetPostcode();
if (!postcode.empty())
object.SetPostcode(postcode);

auto const cuisineStr = xml.GetCuisine();
if (!cuisineStr.empty())
{
Expand Down
3 changes: 0 additions & 3 deletions editor/xml_feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ class XMLFeature
std::string GetHouse() const;
void SetHouse(std::string const & house);

std::string GetPostcode() const;
void SetPostcode(std::string const & postcode);

std::string GetCuisine() const;
void SetCuisine(std::string const & cuisine);

Expand Down
4 changes: 2 additions & 2 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(
boost_helpers.hpp
borders.cpp
borders.hpp
boundary_postcodes_enricher.cpp
boundary_postcodes_enricher.hpp
brands_loader.cpp
brands_loader.hpp
camera_info_collector.cpp
Expand Down Expand Up @@ -163,8 +165,6 @@ set(
popular_places_section_builder.hpp
postcode_points_builder.cpp
postcode_points_builder.hpp
postcodes_section_builder.cpp
postcodes_section_builder.hpp
processor_booking.hpp
processor_coastline.cpp
processor_coastline.hpp
Expand Down
57 changes: 57 additions & 0 deletions generator/boundary_postcodes_enricher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "generator/boundary_postcodes_enricher.hpp"

#include "indexer/ftypes_matcher.hpp"

#include "platform/platform.hpp"

#include "geometry/point2d.hpp"

namespace generator
{
BoundaryPostcodesEnricher::BoundaryPostcodesEnricher(std::string const & boundaryPostcodesFilename)
{
// May be absent for tests because TestMwmBuilder cannot collect data from osm elements.
if (Platform::IsFileExistsByFullPath(boundaryPostcodesFilename))
{
FileReader reader(boundaryPostcodesFilename);
ReaderSource<FileReader> src(reader);

while (src.Size() > 0)
{
std::string postcode;
utils::ReadString(src, postcode);
std::vector<m2::PointD> geometry;
rw::ReadVectorOfPOD(src, geometry);
m_boundaryPostcodes.emplace_back(std::move(postcode), std::move(geometry));
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1,
m_boundaryPostcodes.back().second.GetRect());
}
}
};

void BoundaryPostcodesEnricher::Enrich(feature::FeatureBuilder & fb) const
{
if (!ftypes::IsAddressObjectChecker::Instance()(fb.GetTypes()))
return;

auto const hasName = !fb.GetMultilangName().IsEmpty();

auto const hasHouseNumber = !fb.GetParams().house.Get().empty();

// We do not save postcodes for unnamed features without house number to reduce amount of data.
// For example with this filter we have +100Kb for Turkey_Marmara Region_Istanbul.mwm, without
// filter we have +3Mb because of huge amount of unnamed houses without number.
if (!hasName && !hasHouseNumber)
return;

auto const center = fb.GetKeyPoint();
m_boundariesTree.ForAnyInRect(m2::RectD(center, center), [&](size_t i) {
CHECK_LESS(i, m_boundaryPostcodes.size(), ());
if (!m_boundaryPostcodes[i].second.Contains(center))
return false;

fb.GetMetadata().Set(feature::Metadata::FMD_POSTCODE, m_boundaryPostcodes[i].first);
return true;
});
}
} // namespace generator
25 changes: 25 additions & 0 deletions generator/boundary_postcodes_enricher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "generator/feature_builder.hpp"

#include "geometry/region2d.hpp"
#include "geometry/tree4d.hpp"

#include <string>
#include <utility>
#include <vector>

namespace generator
{
class BoundaryPostcodesEnricher
{
public:
explicit BoundaryPostcodesEnricher(std::string const & boundaryPostcodesFilename);

void Enrich(feature::FeatureBuilder & fb) const;

private:
std::vector<std::pair<std::string, m2::RegionD>> m_boundaryPostcodes;
m4::Tree<size_t> m_boundariesTree;
};
} // namespace generator
15 changes: 12 additions & 3 deletions generator/feature_sorter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "generator/feature_sorter.hpp"

#include "generator/borders.hpp"
#include "generator/boundary_postcodes_enricher.hpp"
#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
#include "generator/gen_mwm_info.hpp"
Expand Down Expand Up @@ -54,10 +55,11 @@ class FeaturesCollector2 : public FeaturesCollector
public:
static uint32_t constexpr kInvalidFeatureId = std::numeric_limits<uint32_t>::max();

FeaturesCollector2(string const & filename, DataHeader const & header,
RegionData const & regionData, uint32_t versionDate)
FeaturesCollector2(string const & filename, string const & boundaryPostcodesFilename,
DataHeader const & header, RegionData const & regionData, uint32_t versionDate)
: FeaturesCollector(filename + FEATURES_FILE_TAG)
, m_filename(filename)
, m_boundaryPostcodesEnricher(boundaryPostcodesFilename)
, m_header(header)
, m_regionData(regionData)
, m_versionDate(versionDate)
Expand Down Expand Up @@ -241,7 +243,10 @@ class FeaturesCollector2 : public FeaturesCollector
fb.GetAddressData().SerializeForMwmTmp(*m_addrFile);

if (!fb.GetMetadata().Empty())
{
m_boundaryPostcodesEnricher.Enrich(fb);
m_metadataBuilder.Put(featureId, fb.GetMetadata());
}

if (fb.HasOsmIds())
m_osm2ft.AddIds(generator::MakeCompositeId(fb), featureId);
Expand Down Expand Up @@ -299,6 +304,7 @@ class FeaturesCollector2 : public FeaturesCollector
// Temporary files for sections.
TmpFiles m_geoFile, m_trgFile;

generator::BoundaryPostcodesEnricher m_boundaryPostcodesEnricher;
indexer::MetadataBuilder m_metadataBuilder;

DataHeader m_header;
Expand Down Expand Up @@ -353,7 +359,10 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na
// FeaturesCollector2 will create temporary file `dataFilePath + FEATURES_FILE_TAG`.
// We cannot remove it in ~FeaturesCollector2(), we need to remove it in SCOPE_GUARD.
SCOPE_GUARD(_, [&]() { Platform::RemoveFileIfExists(dataFilePath + FEATURES_FILE_TAG); });
FeaturesCollector2 collector(dataFilePath, header, regionData, info.m_versionDate);
auto const boundaryPostcodesFilename =
info.GetIntermediateFileName(BOUNDARY_POSTCODE_TMP_FILENAME);
FeaturesCollector2 collector(dataFilePath, boundaryPostcodesFilename, header, regionData,
info.m_versionDate);

for (auto const & point : midPoints.GetVector())
{
Expand Down
3 changes: 3 additions & 0 deletions generator/generator_tests_support/test_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ void TestFeature::Serialize(FeatureBuilder & fb) const
});

if (!m_postcode.empty())
{
fb.GetParams().AddPostcode(m_postcode);
fb.GetMetadata().Set(Metadata::FMD_POSTCODE, m_postcode);
}
}

// TestCountry -------------------------------------------------------------------------------------
Expand Down
6 changes: 0 additions & 6 deletions generator/generator_tests_support/test_mwm_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "generator/feature_sorter.hpp"
#include "generator/generator_tests_support/test_feature.hpp"
#include "generator/postcode_points_builder.hpp"
#include "generator/postcodes_section_builder.hpp"
#include "generator/search_index_builder.hpp"

#include "indexer/city_boundary.hpp"
Expand Down Expand Up @@ -150,11 +149,6 @@ void TestMwmBuilder::Finish()

CHECK(indexer::BuildIndexFromDataFile(path, path), ("Can't build geometry index."));

// We do not have boundaryPostcodesFilename because we do not have osm elements stage.
CHECK(BuildPostcodesSection(m_file.GetDirectory(), m_file.GetCountryName(),
"" /* boundaryPostcodesFilename */),
("Can't build postcodes section."));

CHECK(indexer::BuildSearchIndexFromDataFile(m_file.GetDirectory(), m_file.GetCountryName(),
true /* forceRebuild */, 1 /* threadsCount */),
("Can't build search index."));
Expand Down
6 changes: 0 additions & 6 deletions generator/generator_tool/generator_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "generator/platform_helpers.hpp"
#include "generator/popular_places_section_builder.hpp"
#include "generator/postcode_points_builder.hpp"
#include "generator/postcodes_section_builder.hpp"
#include "generator/processor_factory.hpp"
#include "generator/ratings_section_builder.hpp"
#include "generator/raw_generator.hpp"
Expand Down Expand Up @@ -368,11 +367,6 @@ MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv)
if (!feature::BuildOffsetsTable(dataFile))
continue;

auto const boundaryPostcodesFilename =
genInfo.GetIntermediateFileName(BOUNDARY_POSTCODE_TMP_FILENAME);
if (!BuildPostcodesSection(path, country, boundaryPostcodesFilename))
LOG(LCRITICAL, ("Error generating postcodes section."));

if (mapType == MapType::Country)
{
string const metalinesFilename = genInfo.GetIntermediateFileName(METALINES_FILENAME);
Expand Down
2 changes: 2 additions & 0 deletions generator/osm2meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ string MetadataTagProcessorImpl::ValidateAndFormat_email(string const & v) const
return v;
}

string MetadataTagProcessorImpl::ValidateAndFormat_postcode(string const & v) const { return v; }

string MetadataTagProcessorImpl::ValidateAndFormat_flats(string const & v) const
{
return v;
Expand Down
3 changes: 2 additions & 1 deletion generator/osm2meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct MetadataTagProcessorImpl
std::string ValidateAndFormat_turn_lanes_forward(std::string const & v) const;
std::string ValidateAndFormat_turn_lanes_backward(std::string const & v) const;
std::string ValidateAndFormat_email(std::string const & v) const;
std::string ValidateAndFormat_postcode(std::string const & v) const;
std::string ValidateAndFormat_flats(std::string const & v) const;
std::string ValidateAndFormat_internet(std::string v) const;
std::string ValidateAndFormat_height(std::string const & v) const;
Expand Down Expand Up @@ -76,6 +77,7 @@ class MetadataTagProcessor : private MetadataTagProcessorImpl
case Metadata::FMD_TURN_LANES_FORWARD: valid = ValidateAndFormat_turn_lanes_forward(v); break;
case Metadata::FMD_TURN_LANES_BACKWARD: valid = ValidateAndFormat_turn_lanes_backward(v); break;
case Metadata::FMD_EMAIL: valid = ValidateAndFormat_email(v); break;
case Metadata::FMD_POSTCODE: valid = ValidateAndFormat_postcode(v); break;
case Metadata::FMD_WIKIPEDIA: valid = ValidateAndFormat_wikipedia(v); break;
case Metadata::FMD_FLATS: valid = ValidateAndFormat_flats(v); break;
case Metadata::FMD_MIN_HEIGHT: // The same validator as for height.
Expand All @@ -89,7 +91,6 @@ class MetadataTagProcessor : private MetadataTagProcessorImpl
case Metadata::FMD_DURATION: valid = ValidateAndFormat_duration(v); break;
// Used for old data compatibility only and should not be set:
case Metadata::FMD_CUISINE:
case Metadata::FMD_POSTCODE: CHECK(false, (mdType, "used for compatibility, should not be set."));
// Metadata types we do not get from OSM.
case Metadata::FMD_SPONSORED_ID:
case Metadata::FMD_PRICE_RATE:
Expand Down
2 changes: 0 additions & 2 deletions generator/osm2type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,6 @@ void GetNameAndType(OsmElement * p, FeatureBuilderParams & params,
{"addr:postcode", "*",
[&params](string & k, string & v) {
params.AddPostcode(v);
k.clear();
v.clear();
}},
{"population", "*",
[&params](string & k, string & v) {
Expand Down
Loading

0 comments on commit dd24ed3

Please sign in to comment.