Exemplo n.º 1
0
void CategoriesHolder::AddCategory(Category & cat, vector<uint32_t> & types)
{
  if (!cat.m_synonyms.empty() && !types.empty())
  {
    shared_ptr<Category> p(new Category());
    p->Swap(cat);

    for (size_t i = 0; i < types.size(); ++i)
      m_type2cat.insert(make_pair(types[i], p));

    for (size_t i = 0; i < p->m_synonyms.size(); ++i)
    {
      ASSERT(p->m_synonyms[i].m_locale != kUnsupportedLocaleCode, ());

      StringT const uniName = search::NormalizeAndSimplifyString(p->m_synonyms[i].m_name);

      vector<StringT> tokens;
      SplitUniString(uniName, MakeBackInsertFunctor(tokens), search::Delimiters());

      for (size_t j = 0; j < tokens.size(); ++j)
        for (size_t k = 0; k < types.size(); ++k)
          if (ValidKeyToken(tokens[j]))
            m_name2type.insert(
                make_pair(make_pair(p->m_synonyms[i].m_locale, tokens[j]), types[k]));
    }
  }
Exemplo n.º 2
0
    bool operator()(int8_t langCode, string const & name)
    {
        CHECK(!name.empty(), ("Feature name is empty"));

        vector<strings::UniString> tokens;
        search::SplitUniString(search::NormalizeAndSimplifyString(name),
                               MakeBackInsertFunctor(tokens), search::Delimiters());

        if (tokens.empty())
            return true;

        for (size_t i = 1; i < tokens.size(); ++i)
        {
            strings::UniString s;
            for (size_t numTokens = 0; numTokens < i; ++numTokens)
            {
                s.append(tokens[numTokens].begin(), tokens[numTokens].end());
                s.push_back(' ');
            }
            pair<TokensContainerT::mapped_type::iterator, bool> found =
                m_stats[langCode].insert(make_pair(s, make_pair(1U, name)));
            if (!found.second)
                found.first->second.first++;
        }
        return true;
    }
Exemplo n.º 3
0
bool TokenizeStringAndCheckIfLastTokenIsPrefix(strings::UniString const & s,
                                               ContainerT & tokens,
                                               DelimsT const & delimiter)
{
  SplitUniString(s, MakeBackInsertFunctor(tokens), delimiter);
  return !s.empty() && !delimiter(s.back());
}
Exemplo n.º 4
0
NameScore GetNameScore(string const & name, TSlice const & slice)
{
  if (slice.Empty())
    return NAME_SCORE_ZERO;

  vector<strings::UniString> tokens;
  SplitUniString(NormalizeAndSimplifyString(name), MakeBackInsertFunctor(tokens), Delimiters());
  return GetNameScore(tokens, slice);
}
Exemplo n.º 5
0
void StreetVicinityLoader::LoadStreet(uint32_t featureId, Street & street)
{
  FeatureType feature;
  if (!m_context->GetFeature(featureId, feature))
    return;

  if (feature.GetFeatureType() != feature::GEOM_LINE)
    return;

  vector<m2::PointD> points;
  feature.ForEachPoint(MakeBackInsertFunctor(points), FeatureType::BEST_GEOMETRY);
  ASSERT(!points.empty(), ());

  for (auto const & point : points)
    street.m_rect.Add(MercatorBounds::RectByCenterXYAndSizeInMeters(point, m_offsetMeters));

  covering::CoveringGetter coveringGetter(street.m_rect, covering::ViewportWithLowLevels);
  auto const & intervals = coveringGetter.Get(m_scale);
  m_context->ForEachIndex(intervals, m_scale, MakeBackInsertFunctor(street.m_features));

  street.m_calculator = make_unique<ProjectionOnStreetCalculator>(points);
}
Exemplo n.º 6
0
void BannerSet::Add(Banner const & banner, string const & type)
{
  vector<string> v;
  strings::Tokenize(type, "-", MakeBackInsertFunctor(v));
  uint32_t const ctype = classif().GetTypeByPathSafe(v);
  if (ctype == 0)
  {
    LOG(LWARNING, ("Missing type", type, "for a banner"));
  }
  else
  {
    CHECK(m_banners.find(ctype) == m_banners.end(), ("Duplicate banner type", type));
    m_banners.emplace(make_pair(ctype, banner));
  }
}
Exemplo n.º 7
0
void EditorDialog::OnSave()
{
  // Store all edits.
  if (m_feature.IsNameEditable())
  {
    StringUtf8Multilang names;
    for (int8_t langCode = StringUtf8Multilang::kDefaultCode;
         langCode < StringUtf8Multilang::kMaxSupportedLanguages; ++langCode)
    {
      QLineEdit * le = findChild<QLineEdit *>(StringUtf8Multilang::GetLangByCode(langCode));
      if (!le)
        continue;
      string const name = le->text().toStdString();
      if (!name.empty())
        names.AddString(langCode, name);
    }
    m_feature.SetName(names);
  }

  if (m_feature.IsAddressEditable())
  {
    m_feature.SetHouseNumber(findChild<QLineEdit *>(kHouseNumberObjectName)->text().toStdString());
    QString const editedStreet = findChild<QComboBox *>(kStreetObjectName)->currentText();
    QStringList const names = editedStreet.split(" / ", QString::SkipEmptyParts);
    QString const localized = names.size() > 1 ? names.at(1) : QString();
    if (!names.empty())
      m_feature.SetStreet({names.at(0).toStdString(), localized.toStdString()});
    else
      m_feature.SetStreet({});
    m_feature.SetPostcode(findChild<QLineEdit *>(kPostcodeObjectName)->text().toStdString());
  }

  for (osm::Props const prop : m_feature.GetEditableProperties())
  {
    if (prop == osm::Props::Internet)
    {
      QComboBox * cmb = findChild<QComboBox *>(kInternetObjectName);
      string const str = cmb->currentText().toStdString();
      osm::Internet v = osm::Internet::Unknown;
      if (str == DebugPrint(osm::Internet::Wlan))
        v = osm::Internet::Wlan;
      else if (str == DebugPrint(osm::Internet::Wired))
        v = osm::Internet::Wired;
      else if (str == DebugPrint(osm::Internet::No))
        v = osm::Internet::No;
      else if (str == DebugPrint(osm::Internet::Yes))
        v = osm::Internet::Yes;
      m_feature.SetInternet(v);
      continue;
    }

    QLineEdit * editor = findChild<QLineEdit *>(QString::fromStdString(DebugPrint(prop)));
    if (!editor)
      continue;

    string const v = editor->text().toStdString();
    switch (prop)
    {
    case osm::Props::Phone: m_feature.SetPhone(v); break;
    case osm::Props::Fax: m_feature.SetFax(v); break;
    case osm::Props::Email: m_feature.SetEmail(v); break;
    case osm::Props::Website: m_feature.SetWebsite(v); break;
    case osm::Props::Internet: ASSERT(false, ("Is handled separately above."));
    case osm::Props::Cuisine:
    {
      vector<string> cuisines;
      strings::Tokenize(v, ";", MakeBackInsertFunctor(cuisines));
      m_feature.SetCuisines(cuisines);
    }
    break;
    case osm::Props::OpeningHours: m_feature.SetOpeningHours(v); break;
    case osm::Props::Stars:
    {
      int num;
      if (strings::to_int(v, num))
        m_feature.SetStars(num);
    }
    break;
    case osm::Props::Operator: m_feature.SetOperator(v); break;
    case osm::Props::Elevation:
    {
      double ele;
      if (strings::to_double(v, ele))
        m_feature.SetElevation(ele);
    }
    break;
    case osm::Props::Wikipedia: m_feature.SetWikipedia(v); break;
    case osm::Props::Flats: m_feature.SetFlats(v); break;
    case osm::Props::BuildingLevels: m_feature.SetBuildingLevels(v); break;
    }
  }
  accept();
}
Exemplo n.º 8
0
int main(int argc, char * argv[])
{
  google::SetUsageMessage("SRTM coverage checker.");
  google::ParseCommandLineFlags(&argc, &argv, true);

  Platform & platform = GetPlatform();
  if (!FLAGS_mwm_path.empty())
    platform.SetWritableDirForTests(FLAGS_mwm_path);

  if (FLAGS_srtm_path.empty())
  {
    LOG(LERROR, ("SRTM files directory is not specified."));
    return -1;
  }

  LOG(LINFO, ("writable dir =", platform.WritableDir()));
  LOG(LINFO, ("srtm dir =", FLAGS_srtm_path));

  vector<platform::LocalCountryFile> localFiles;
  platform::FindAllLocalMapsAndCleanup(numeric_limits<int64_t>::max() /* latestVersion */,
                                       localFiles);

  auto fetcher = integration::CreateFeaturesFetcher(localFiles);
  generator::SrtmTileManager manager(FLAGS_srtm_path);

  for (auto & file : localFiles)
  {
    file.SyncWithDisk();
    if (file.GetFiles() != MapOptions::MapWithCarRouting)
    {
      LOG(LINFO, ("Warning! Routing file not found for:", file.GetCountryName()));
      continue;
    }

    FilesMappingContainer container(file.GetPath(MapOptions::CarRouting));
    if (!container.IsExist(ROUTING_FTSEG_FILE_TAG))
    {
      LOG(LINFO, ("Warning! Mwm file has not routing ftseg section:", file.GetCountryName()));
      continue;
    }

    routing::TDataFacade dataFacade;
    dataFacade.Load(container);

    OsrmFtSegMapping segMapping;
    segMapping.Load(container, file);
    segMapping.Map(container);

    size_t all = 0;
    size_t good = 0;

    for (size_t i = 0; i < dataFacade.GetNumberOfNodes(); ++i)
    {
      buffer_vector<OsrmMappingTypes::FtSeg, 8> buffer;
      segMapping.ForEachFtSeg(i, MakeBackInsertFunctor(buffer));

      vector<m2::PointD> path;
      for (size_t k = 0; k < buffer.size(); ++k)
      {
        auto const & segment = buffer[k];
        if (!segment.IsValid())
          continue;
        // Load data from drive.
        FeatureType ft;
        Index::FeaturesLoaderGuard loader(
            fetcher->GetIndex(), fetcher->GetIndex().GetMwmIdByCountryFile(file.GetCountryFile()));
        loader.GetFeatureByIndex(segment.m_fid, ft);
        ft.ParseGeometry(FeatureType::BEST_GEOMETRY);

        // Get points in proper direction.
        auto const startIdx = segment.m_pointStart;
        auto const endIdx = segment.m_pointEnd;
        for (auto idx = min(startIdx, endIdx); idx <= max(startIdx, endIdx); ++idx)
          path.push_back(ft.GetPoint(idx));

        all += path.size();
        for (auto const & point : path)
        {
          auto const height = manager.GetHeight(MercatorBounds::ToLatLon(point));
          if (height != generator::SrtmTile::kInvalidHeight)
            good++;
        }
      }
    }

    auto const bad = all - good;
    auto const percent = all == 0 ? 0.0 : bad * 100.0 / all;
    if (percent > 10.0)
    {
      LOG(LINFO, ("Huge error rate in:", file.GetCountryName(), "good:", good, "bad:", bad, "all:",
                  all, "%:", percent));
    }
  }

  return 0;
}
Exemplo n.º 9
0
void NormalizeAndTokenizeString(string const & s, TCont & tokens, TDelims const & delims)
{
  SplitUniString(NormalizeAndSimplifyString(s), MakeBackInsertFunctor(tokens), delims);
}