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

opentable_dataset.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 80cfaf2424afefc32430d5f4d5443d473de4894f (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
#include "generator/opentable_dataset.hpp"

#include "generator/feature_builder.hpp"
#include "generator/sponsored_scoring.hpp"

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

#include "base/logging.hpp"
#include "base/string_utils.hpp"

#include <iomanip>
#include <iostream>

#include "boost/algorithm/string/replace.hpp"

namespace generator
{
// OpentableRestaurant ------------------------------------------------------------------------------
OpentableRestaurant::OpentableRestaurant(std::string const & src)
{
  vector<std::string> rec;
  strings::ParseCSVRow(src, '\t', rec);
  CHECK_EQUAL(rec.size(), FieldsCount(), ("Error parsing restaurants.tsv line:",
                                          boost::replace_all_copy(src, "\t", "\\t")));

  CLOG(LDEBUG, strings::to_uint(rec[FieldIndex(Fields::Id)], m_id.Get()), ());
  CLOG(LDEBUG, strings::to_double(rec[FieldIndex(Fields::Latitude)], m_latLon.lat), ());
  CLOG(LDEBUG, strings::to_double(rec[FieldIndex(Fields::Longtitude)], m_latLon.lon), ());

  m_name = rec[FieldIndex(Fields::Name)];
  m_address = rec[FieldIndex(Fields::Address)];
  m_descUrl = rec[FieldIndex(Fields::DescUrl)];
}

// OpentableDataset ---------------------------------------------------------------------------------
template <>
bool OpentableDataset::NecessaryMatchingConditionHolds(FeatureBuilder1 const & fb) const
{
  if (fb.GetName(StringUtf8Multilang::kDefaultCode).empty())
    return false;

  return ftypes::IsEatChecker::Instance()(fb.GetTypes());
}

template <>
void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, FeatureBuilder1 & fb,
                                                  function<void(FeatureBuilder1 &)> const fn) const
{
  auto const & restaurant = m_storage.GetObjectById(matchedObjId);
  auto & metadata = fb.GetMetadata();
  metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(restaurant.m_id.Get()));

  FeatureParams & params = fb.GetParams();
  // params.AddAddress(restaurant.address);
  // TODO(mgsergio): addr:full ???

  params.AddName(StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kDefaultCode),
                 restaurant.m_name);

  auto const & clf = classif();
  params.AddType(clf.GetTypeByPath({"sponsored", "opentable"}));

  fn(fb);
}

template <>
OpentableDataset::ObjectId OpentableDataset::FindMatchingObjectIdImpl(FeatureBuilder1 const & fb) const
{
  auto const name = fb.GetName(StringUtf8Multilang::kDefaultCode);

  if (name.empty())
    return Object::InvalidObjectId();

  // Find |kMaxSelectedElements| nearest values to a point.
  auto const nearbyIds = m_storage.GetNearestObjects(MercatorBounds::ToLatLon(fb.GetKeyPoint()));

  for (auto const objId : nearbyIds)
  {
    if (sponsored_scoring::Match(m_storage.GetObjectById(objId), fb).IsMatched())
      return objId;
  }

  return Object::InvalidObjectId();
}
}  // namespace generator