diff options
author | Maksim Andrianov <maksimandrianov1@gmail.com> | 2018-11-09 18:13:57 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-12-03 17:38:09 +0300 |
commit | 53eb49b007570a44d38fd6522b8e6dab588a6026 (patch) | |
tree | 8a6e85eedf9146d5200127e23d96d4a81569d790 /indexer | |
parent | 8bf96f5ee0156d4da6c71cb0c2845aecb05c7035 (diff) |
[generator] Added wikipedia descriptions generation.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/ftypes_matcher.cpp | 70 | ||||
-rw-r--r-- | indexer/ftypes_matcher.hpp | 27 | ||||
-rw-r--r-- | indexer/indexer_tests/checker_test.cpp | 102 |
3 files changed, 197 insertions, 2 deletions
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 <algorithm> #include <cmath> +#include <functional> +#include <iterator> #include <map> #include <sstream> #include <unordered_map> @@ -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<uint32_t> 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<string> 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<pair<string, string>> 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 <cstdint> #include <functional> #include <initializer_list> +#include <set> #include <string> #include <type_traits> #include <utility> @@ -41,6 +42,7 @@ public: bool operator()(feature::TypesHolder const & types) const; bool operator()(FeatureType & ft) const; bool operator()(std::vector<uint32_t> 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<std::string> const kPoiTypes; + + DECLARE_CHECKER_INSTANCE(IsPoiChecker); +}; + +class WikiChecker : public BaseChecker +{ + WikiChecker(); +public: + static std::set<std::pair<std::string, std::string>> 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 <cstddef> +#include <cstdint> +#include <string> +#include <utility> +#include <vector> + +using namespace std; + namespace { size_t const roadArrColumnCount = 3; @@ -21,6 +29,27 @@ vector<uint32_t> GetTypes(char const * arr[][roadArrColumnCount], size_t const r return types; } +vector<uint32_t> GetTypes(std::vector<std::pair<std::string, std::string>> const & t) +{ + Classificator const & c = classif(); + vector<uint32_t> types; + + for (auto const & k : t) + types.push_back(c.GetTypeByPath({k.first, k.second})); + return types; +} + +vector<uint32_t> GetTypes(std::vector<std::string> const & t) +{ + Classificator const & c = classif(); + vector<uint32_t> types; + + for (auto const & k : t) + types.push_back(c.GetTypeByPath({k})); + return types; +} + + vector<uint32_t> GetStreetTypes() { char const * arr[][roadArrColumnCount] = @@ -80,7 +109,56 @@ vector<uint32_t> GetBridgeAndTunnelTypes() }; return GetTypes(arr, ARRAY_SIZE(arr)); } + +vector<uint32_t> GetPoiTypes() +{ + std::vector<std::string> const types = { + "amenity", + "shop", + "tourism", + "leisure", + "sport", + "craft", + "man_made", + "emergency", + "office", + "historic", + "railway", + "highway", + "aeroway" + }; + return GetTypes(types); +} + +vector<uint32_t> GetWikiTypes() +{ + vector<pair<string, string>> 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"})), ()); +} |