<commit_before>#include "indexer/classificator.hpp"
#include "indexer/feature.hpp"

#include "indexer/classificator.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/feature_loader_base.hpp"
#include "indexer/feature_visibility.hpp"
#include "indexer/osm_editor.hpp"

#include "geometry/distance.hpp"
#include "geometry/robust_orientation.hpp"

#include "platform/preferred_languages.hpp"

#include "base/range_iterator.hpp"

#include "std/algorithm.hpp"

using namespace feature;

///////////////////////////////////////////////////////////////////////////////////////////////////
// FeatureBase implementation
///////////////////////////////////////////////////////////////////////////////////////////////////

void FeatureBase::Deserialize(feature::LoaderBase * pLoader, TBuffer buffer)
{
  m_pLoader = pLoader;
  m_pLoader->Init(buffer);

  m_limitRect = m2::RectD::GetEmptyRect();
  m_bTypesParsed = m_bCommonParsed = false;
  m_header = m_pLoader->GetHeader();
}

// TODO(mgsergio): No need to create feature from xml, can go with patchig for now.
//@{
// FeatureType FeatureType::FromXML(string const & xml)
// {
//   pugi::xml_document document;
//   document.load(xml.data());
//   return FromXML(document);
// }

// FeatureType FeatureType::FromXML(editor::XMLFeature const & xml)
// {
//   FeatureType feature;
//   // Should be set to true. Or later call to ParseGeometry will lead to crash.
//   feature.m_bTrianglesParsed = feature.m_bPointsParsed = true;
//   feature.m_center = xml.GetCenter();

//   // Preset type for header calculation later in ApplyPatch.
//   feature.m_header = HEADER_GEOM_POINT;

//   auto const & types = osm::Editor::Instance().GetTypesOfFeature(xml);
//   copy(begin(types), end(types), begin(feature.m_types));
//   feature.m_bTypesParsed = true;

//   feature.ApplyPatch(xml);

//   return feature;
// }
//@}
void FeatureType::ApplyPatch(editor::XMLFeature const & xml)
{
  xml.ForEachName([this](string const & lang, string const & name)
                  {
                    m_params.name.AddString(lang, name);
                  });

  string const house = xml.GetHouse();
  if (!house.empty())
    m_params.house.Set(house);

  // TODO(mgsergio):
  // m_params.ref =
  // m_params.layer =
  // m_params.rank =
  m_bCommonParsed = true;

  for (auto const i : my::UpTo(1u, static_cast<uint32_t>(feature::Metadata::FMD_COUNT)))
  {
    auto const type = static_cast<feature::Metadata::EType>(i);
    auto const attributeName = DebugPrint(type);
    if (xml.HasTag(attributeName))
      m_metadata.Set(type, xml.GetTagValue(attributeName));
  }
  m_bMetadataParsed = true;

  // TODO(mgsergio): Get types count from xml.
  auto constexpr kOnlyOneTypeCount = 1;
  m_header = CalculateHeader(kOnlyOneTypeCount, Header() & HEADER_GEOTYPE_MASK, m_params);
  m_bHeader2Parsed = true;
}

editor::XMLFeature FeatureType::ToXML() const
{
  editor::XMLFeature feature(GetFeatureType() == feature::GEOM_POINT
                                 ? editor::XMLFeature::Type::Node
                                 : editor::XMLFeature::Type::Way);

  // Only Poins are completely serialized and deserialized.
  // Other types could only be patched.<commit_msg>[editor] Correct feature types count.<commit_after>#include "indexer/classificator.hpp"
#include "indexer/feature.hpp"

#include "indexer/classificator.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/feature_loader_base.hpp"
#include "indexer/feature_visibility.hpp"
#include "indexer/osm_editor.hpp"

#include "geometry/distance.hpp"
#include "geometry/robust_orientation.hpp"

#include "platform/preferred_languages.hpp"

#include "base/range_iterator.hpp"

#include "std/algorithm.hpp"

using namespace feature;

///////////////////////////////////////////////////////////////////////////////////////////////////
// FeatureBase implementation
///////////////////////////////////////////////////////////////////////////////////////////////////

void FeatureBase::Deserialize(feature::LoaderBase * pLoader, TBuffer buffer)
{
  m_pLoader = pLoader;
  m_pLoader->Init(buffer);

  m_limitRect = m2::RectD::GetEmptyRect();
  m_bTypesParsed = m_bCommonParsed = false;
  m_header = m_pLoader->GetHeader();
}

// TODO(mgsergio): No need to create feature from xml, can go with patchig for now.
//@{
// FeatureType FeatureType::FromXML(string const & xml)
// {
//   pugi::xml_document document;
//   document.load(xml.data());
//   return FromXML(document);
// }

// FeatureType FeatureType::FromXML(editor::XMLFeature const & xml)
// {
//   FeatureType feature;
//   // Should be set to true. Or later call to ParseGeometry will lead to crash.
//   feature.m_bTrianglesParsed = feature.m_bPointsParsed = true;
//   feature.m_center = xml.GetCenter();

//   // Preset type for header calculation later in ApplyPatch.
//   feature.m_header = HEADER_GEOM_POINT;

//   auto const & types = osm::Editor::Instance().GetTypesOfFeature(xml);
//   copy(begin(types), end(types), begin(feature.m_types));
//   feature.m_bTypesParsed = true;

//   feature.ApplyPatch(xml);

//   return feature;
// }
//@}
void FeatureType::ApplyPatch(editor::XMLFeature const & xml)
{
  xml.ForEachName([this](string const & lang, string const & name)
                  {
                    m_params.name.AddString(lang, name);
                  });

  string const house = xml.GetHouse();
  if (!house.empty())
    m_params.house.Set(house);

  // TODO(mgsergio):
  // m_params.ref =
  // m_params.layer =
  // m_params.rank =
  m_bCommonParsed = true;

  for (auto const i : my::UpTo(1u, static_cast<uint32_t>(feature::Metadata::FMD_COUNT)))
  {
    auto const type = static_cast<feature::Metadata::EType>(i);
    auto const attributeName = DebugPrint(type);
    if (xml.HasTag(attributeName))
      m_metadata.Set(type, xml.GetTagValue(attributeName));
  }
  m_bMetadataParsed = true;

  m_header = CalculateHeader(GetTypesCount(), Header() & HEADER_GEOTYPE_MASK, m_params);
  m_bHeader2Parsed = true;
}

editor::XMLFeature FeatureType::ToXML() const
{
  editor::XMLFeature feature(GetFeatureType() == feature::GEOM_POINT
                                 ? editor::XMLFeature::Type::Node
                                 : editor::XMLFeature::Type::Way);

  // Only Poins are completely serialized and deserialized.
  // Other types could only be patched.
{'fraction_non_alphanumeric': 0.18983746252169797, 'fraction_numerical': 0.001735837146914944, 'mean_word_length': 2.8020395920815835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 27}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5679650', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1905, 'n_words': 387}