Welcome to mirror list, hosted at ThFree Co, Russian Federation.

search_model.cpp « v2 « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5117d6e3a7483d343d22f4597086d63ee0630676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "search/v2/search_model.hpp"

#include "indexer/classificator.hpp"
#include "indexer/feature.hpp"

#include "base/macros.hpp"

using namespace ftypes;

namespace search
{
namespace v2
{
TwoLevelPOIChecker::TwoLevelPOIChecker() : ftypes::BaseChecker(2 /* level */)
{
  Classificator const & c = classif();
  StringIL arr[] = {
    {"highway", "bus_stop"},
    {"highway", "speed_camera"},
    {"waterway", "waterfall"},
    {"natural", "volcano"},
    {"natural", "cave_entrance"},
    {"natural", "beach"}
  };

  for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
    m_types.push_back(c.GetTypeByPath(arr[i]));
}

namespace
{
/// Should be similar with ftypes::IsAddressObjectChecker object classes.
class OneLevelPOIChecker : public ftypes::BaseChecker
{
public:
  OneLevelPOIChecker() : ftypes::BaseChecker(1 /* level */)
  {
    Classificator const & c = classif();

    auto paths = {"amenity", "historic", "office", "railway", "shop", "sport", "tourism", "craft"};
    for (auto const & path : paths)
      m_types.push_back(c.GetTypeByPath({path}));
  }
};

class IsPoiChecker
{
public:
  IsPoiChecker() {}

  static IsPoiChecker const & Instance()
  {
    static const IsPoiChecker inst;
    return inst;
  }

  bool operator()(FeatureType const & ft) const { return m_oneLevel(ft) || m_twoLevel(ft); }

private:
  OneLevelPOIChecker const m_oneLevel;
  TwoLevelPOIChecker const m_twoLevel;
};

class CustomIsBuildingChecker
{
public:
  static CustomIsBuildingChecker const & Instance()
  {
    static const CustomIsBuildingChecker inst;
    return inst;
  }

  bool operator()(FeatureType const & ft) const
  {
    return !ft.GetHouseNumber().empty() || IsBuildingChecker::Instance()(ft);
  }

private:
  CustomIsBuildingChecker() {}
};
}  // namespace

// static
SearchModel const & SearchModel::Instance()
{
  static SearchModel model;
  return model;
}

SearchModel::SearchType SearchModel::GetSearchType(FeatureType const & feature) const
{
  static auto const & buildingChecker = CustomIsBuildingChecker::Instance();
  static auto const & streetChecker = IsStreetChecker::Instance();
  static auto const & localityChecker = IsLocalityChecker::Instance();
  static auto const & poiChecker = IsPoiChecker::Instance();

  if (buildingChecker(feature))
    return SEARCH_TYPE_BUILDING;

  if (streetChecker(feature))
    return SEARCH_TYPE_STREET;

  if (localityChecker(feature))
  {
    Type type = localityChecker.GetType(feature);
    switch (type)
    {
    case NONE:
      ASSERT(false, ("Unknown locality."));
      return SEARCH_TYPE_UNCLASSIFIED;
    case STATE:
      return SEARCH_TYPE_STATE;
    case COUNTRY:
      return SEARCH_TYPE_COUNTRY;
    case CITY:
    case TOWN:
      return SEARCH_TYPE_CITY;
    case VILLAGE:
      return SEARCH_TYPE_VILLAGE;
    case LOCALITY_COUNT:
      return SEARCH_TYPE_UNCLASSIFIED;
    }
  }

  if (poiChecker(feature))
    return SEARCH_TYPE_POI;

  return SEARCH_TYPE_UNCLASSIFIED;
}

string DebugPrint(SearchModel::SearchType type)
{
  switch (type)
  {
  case SearchModel::SEARCH_TYPE_POI: return "POI";
  case SearchModel::SEARCH_TYPE_BUILDING: return "Building";
  case SearchModel::SEARCH_TYPE_STREET: return "Street";
  case SearchModel::SEARCH_TYPE_CITY: return "City";
  case SearchModel::SEARCH_TYPE_VILLAGE: return "Village";
  case SearchModel::SEARCH_TYPE_STATE: return "State";
  case SearchModel::SEARCH_TYPE_COUNTRY: return "Country";
  case SearchModel::SEARCH_TYPE_UNCLASSIFIED: return "Unclassified";
  case SearchModel::SEARCH_TYPE_COUNT: return "Count";
  }
  ASSERT(false, ("Unknown search type:", static_cast<int>(type)));
  return string();
}
}  // namespace v2
}  // namespace search