From 53eb49b007570a44d38fd6522b8e6dab588a6026 Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Fri, 9 Nov 2018 18:13:57 +0300 Subject: [generator] Added wikipedia descriptions generation. --- indexer/ftypes_matcher.cpp | 70 +++++++++++++++++++++- indexer/ftypes_matcher.hpp | 27 +++++++++ indexer/indexer_tests/checker_test.cpp | 102 +++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) (limited to 'indexer') diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp index e15649da25..352e1392b0 100644 --- a/indexer/ftypes_matcher.cpp +++ b/indexer/ftypes_matcher.cpp @@ -9,7 +9,10 @@ #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" +#include #include +#include +#include #include #include #include @@ -130,8 +133,10 @@ bool BaseChecker::IsMatched(uint32_t type) const bool BaseChecker::operator()(feature::TypesHolder const & types) const { for (uint32_t t : types) + { if (IsMatched(t)) return true; + } return false; } @@ -143,11 +148,12 @@ bool BaseChecker::operator()(FeatureType & ft) const bool BaseChecker::operator()(vector const & types) const { - for (size_t i = 0; i < types.size(); ++i) + for (uint32_t t : types) { - if (IsMatched(types[i])) + if (IsMatched(t)) return true; } + return false; } @@ -274,6 +280,66 @@ IsBuildingChecker::IsBuildingChecker() : BaseChecker(1 /* level */) m_types.push_back(classif().GetTypeByPath({"building"})); } +// static +set const IsPoiChecker::kPoiTypes = { + "amenity", + "shop", + "tourism", + "leisure", + "sport", + "craft", + "man_made", + "emergency", + "office", + "historic", + "railway", + "highway", + "aeroway" +}; + +IsPoiChecker::IsPoiChecker() : BaseChecker(1 /* level */) +{ + for (auto const & type : IsPoiChecker::kPoiTypes) + m_types.push_back(classif().GetTypeByPath({type})); +} + +// static +set> const WikiChecker::kTypesForWiki = { + {"amenity", "place_of_worship"}, + {"historic", "archaeological_site"}, + {"historic", "castle"}, + {"historic", "memorial"}, + {"historic", "monument"}, + {"historic", "museum"}, + {"historic", "ruins"}, + {"historic", "ship"}, + {"historic", "tomb"}, + {"tourism", "artwork"}, + {"tourism", "attraction"}, + {"tourism", "museum"}, + {"tourism", "gallery"}, + {"tourism", "viewpoint"}, + {"tourism", "zoo"}, + {"tourism", "theme_park"}, + {"leisure", "park"}, + {"leisure", "water_park"}, + {"highway", "pedestrian"}, + {"man_made", "lighthouse"}, + {"waterway", "waterfall"}, + {"leisure", "garden"}, +}; + +WikiChecker::WikiChecker() : BaseChecker(2 /* level */) +{ + for (auto const & t : kTypesForWiki) + m_types.push_back(classif().GetTypeByPath({t.first, t.second})); +} + +IsPlaceChecker::IsPlaceChecker() : BaseChecker(1 /* level */) +{ + m_types.push_back(classif().GetTypeByPath({"place"})); +} + IsBridgeChecker::IsBridgeChecker() : BaseChecker(3 /* level */) {} bool IsBridgeChecker::IsMatched(uint32_t type) const diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 1f237eeaaa..9774074d0f 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ public: bool operator()(feature::TypesHolder const & types) const; bool operator()(FeatureType & ft) const; bool operator()(std::vector const & types) const; + bool operator()(uint32_t type) const { return IsMatched(type); } static uint32_t PrepareToMatch(uint32_t type, uint8_t level); @@ -152,6 +154,31 @@ public: DECLARE_CHECKER_INSTANCE(IsBuildingChecker); }; +class IsPoiChecker : public BaseChecker +{ + IsPoiChecker(); +public: + static std::set const kPoiTypes; + + DECLARE_CHECKER_INSTANCE(IsPoiChecker); +}; + +class WikiChecker : public BaseChecker +{ + WikiChecker(); +public: + static std::set> const kTypesForWiki; + + DECLARE_CHECKER_INSTANCE(WikiChecker); +}; + +class IsPlaceChecker : public BaseChecker +{ + IsPlaceChecker(); +public: + DECLARE_CHECKER_INSTANCE(IsPlaceChecker); +}; + class IsBridgeChecker : public BaseChecker { virtual bool IsMatched(uint32_t type) const override; diff --git a/indexer/indexer_tests/checker_test.cpp b/indexer/indexer_tests/checker_test.cpp index b53c2e5fa2..9dc695893b 100644 --- a/indexer/indexer_tests/checker_test.cpp +++ b/indexer/indexer_tests/checker_test.cpp @@ -7,6 +7,14 @@ #include "base/logging.hpp" +#include +#include +#include +#include +#include + +using namespace std; + namespace { size_t const roadArrColumnCount = 3; @@ -21,6 +29,27 @@ vector GetTypes(char const * arr[][roadArrColumnCount], size_t const r return types; } +vector GetTypes(std::vector> const & t) +{ + Classificator const & c = classif(); + vector types; + + for (auto const & k : t) + types.push_back(c.GetTypeByPath({k.first, k.second})); + return types; +} + +vector GetTypes(std::vector const & t) +{ + Classificator const & c = classif(); + vector types; + + for (auto const & k : t) + types.push_back(c.GetTypeByPath({k})); + return types; +} + + vector GetStreetTypes() { char const * arr[][roadArrColumnCount] = @@ -80,7 +109,56 @@ vector GetBridgeAndTunnelTypes() }; return GetTypes(arr, ARRAY_SIZE(arr)); } + +vector GetPoiTypes() +{ + std::vector const types = { + "amenity", + "shop", + "tourism", + "leisure", + "sport", + "craft", + "man_made", + "emergency", + "office", + "historic", + "railway", + "highway", + "aeroway" + }; + return GetTypes(types); +} + +vector GetWikiTypes() +{ + vector> const types = { + {"amenity", "place_of_worship"}, + {"historic", "archaeological_site"}, + {"historic", "castle"}, + {"historic", "memorial"}, + {"historic", "monument"}, + {"historic", "museum"}, + {"historic", "ruins"}, + {"historic", "ship"}, + {"historic", "tomb"}, + {"tourism", "artwork"}, + {"tourism", "attraction"}, + {"tourism", "museum"}, + {"tourism", "gallery"}, + {"tourism", "viewpoint"}, + {"tourism", "zoo"}, + {"tourism", "theme_park"}, + {"leisure", "park"}, + {"leisure", "water_park"}, + {"highway", "pedestrian"}, + {"man_made", "lighthouse"}, + {"waterway", "waterfall"}, + {"leisure", "garden"} + }; + return GetTypes(types); } +} // namespace UNIT_TEST(IsTypeConformed) { @@ -162,3 +240,27 @@ UNIT_TEST(GetHighwayClassTest) types4.Add(c.GetTypeByPath({"highway"})); TEST_EQUAL(ftypes::GetHighwayClass(types4), ftypes::HighwayClass::Error, ()); } + +UNIT_TEST(IsPoiChecker) +{ + classificator::Load(); + Classificator const & c = classif(); + auto const & checker = ftypes::IsPoiChecker::Instance(); + + for (auto const & t : GetPoiTypes()) + TEST(checker(t), ()); + + TEST(!checker(c.GetTypeByPath({"building"})), ()); +} + +UNIT_TEST(IsWikiChecker) +{ + classificator::Load(); + Classificator const & c = classif(); + auto const & checker = ftypes::WikiChecker::Instance(); + + for (auto const & t : GetWikiTypes()) + TEST(checker(t), ()); + + TEST(!checker(c.GetTypeByPath({"route", "shuttle_train"})), ()); +} -- cgit v1.2.3