<commit_before>#ifndef OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#define OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_

#include "util/simple_logger.hpp"

#include <cstdint>

#include <string>
#include <unordered_map>

// Forward Declaration to allow usage of external osmium::Way
namespace osmium
{
class Way;
}

namespace osrm
{
namespace extractor
{
namespace guidance
{

enum class FunctionalRoadClass : std::uint8_t
{
    UNKNOWN = 0,
    MOTORWAY,
    MOTORWAY_LINK,
    TRUNK,
    TRUNK_LINK,
    PRIMARY,
    PRIMARY_LINK,
    SECONDARY,
    SECONDARY_LINK,
    TERTIARY,
    TERTIARY_LINK,
    UNCLASSIFIED,
    RESIDENTIAL,
    SERVICE,
    LIVING_STREET,
    LOW_PRIORITY_ROAD // a road simply included for connectivity. Should be avoided at all cost
};

inline FunctionalRoadClass functionalRoadClassFromTag(std::string const &value)
{
    // FIXME at some point this should be part of the profiles
    const static auto initializeClassHash = []()
    {
        std::unordered_map<std::string, FunctionalRoadClass> hash;
        hash["motorway"] = FunctionalRoadClass::MOTORWAY;
        hash["motorway_link"] = FunctionalRoadClass::MOTORWAY_LINK;
        hash["trunk"] = FunctionalRoadClass::TRUNK;
        hash["trunk_link"] = FunctionalRoadClass::TRUNK_LINK;
        hash["primary"] = FunctionalRoadClass::PRIMARY;
        hash["primary_link"] = FunctionalRoadClass::PRIMARY_LINK;
        hash["secondary"] = FunctionalRoadClass::SECONDARY;
        hash["secondary_link"] = FunctionalRoadClass::SECONDARY_LINK;
        hash["tertiary"] = FunctionalRoadClass::TERTIARY;
        hash["tertiary_link"] = FunctionalRoadClass::TERTIARY_LINK;
        hash["unclassified"] = FunctionalRoadClass::UNCLASSIFIED;
        hash["residential"] = FunctionalRoadClass::RESIDENTIAL;
        hash["service"] = FunctionalRoadClass::SERVICE;
        hash["living_street"] = FunctionalRoadClass::LIVING_STREET;
        hash["track"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["road"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["path"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["driveway"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        return hash;
    };

    static const std::unordered_map<std::string, FunctionalRoadClass> class_hash =
        initializeClassHash();

    if (class_hash.find(value) != class_hash.end())
    {
        return class_hash.find(value)->second;
    }
    else
    {
        util::SimpleLogger().Write(logDEBUG) << "Unknown road class encountered: " << value;
        return FunctionalRoadClass::UNKNOWN;
    }
}

inline bool isRampClass(const FunctionalRoadClass road_class)
{
    // Primary Roads and down are usually too small to announce their links as ramps
    return road_class == FunctionalRoadClass::MOTORWAY_LINK ||
           road_class == FunctionalRoadClass::TRUNK_LINK;
}

// TODO augment this with all data required for guidance generation
struct RoadClassificationData
{
    FunctionalRoadClass road_class = FunctionalRoadClass::UNKNOWN;

    void augment(const osmium::Way &way);
};

inline bool operator==(const RoadClassificationData lhs, const RoadClassificationData rhs)
{
    return lhs.road_class == rhs.road_class;
}

} // namespace guidance
} // namespace extractor
} // namespace osrm

#endif // OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
<commit_msg>Inline initialize functional road classification hash table<commit_after>#ifndef OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#define OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_

#include "util/simple_logger.hpp"

#include <cstdint>

#include <string>
#include <unordered_map>

// Forward Declaration to allow usage of external osmium::Way
namespace osmium
{
class Way;
}

namespace osrm
{
namespace extractor
{
namespace guidance
{

enum class FunctionalRoadClass : std::uint8_t
{
    UNKNOWN = 0,
    MOTORWAY,
    MOTORWAY_LINK,
    TRUNK,
    TRUNK_LINK,
    PRIMARY,
    PRIMARY_LINK,
    SECONDARY,
    SECONDARY_LINK,
    TERTIARY,
    TERTIARY_LINK,
    UNCLASSIFIED,
    RESIDENTIAL,
    SERVICE,
    LIVING_STREET,
    LOW_PRIORITY_ROAD // a road simply included for connectivity. Should be avoided at all cost
};

inline FunctionalRoadClass functionalRoadClassFromTag(std::string const &value)
{
    // FIXME at some point this should be part of the profiles
    const static auto class_hash = []
    {
        std::unordered_map<std::string, FunctionalRoadClass> hash;
        hash["motorway"] = FunctionalRoadClass::MOTORWAY;
        hash["motorway_link"] = FunctionalRoadClass::MOTORWAY_LINK;
        hash["trunk"] = FunctionalRoadClass::TRUNK;
        hash["trunk_link"] = FunctionalRoadClass::TRUNK_LINK;
        hash["primary"] = FunctionalRoadClass::PRIMARY;
        hash["primary_link"] = FunctionalRoadClass::PRIMARY_LINK;
        hash["secondary"] = FunctionalRoadClass::SECONDARY;
        hash["secondary_link"] = FunctionalRoadClass::SECONDARY_LINK;
        hash["tertiary"] = FunctionalRoadClass::TERTIARY;
        hash["tertiary_link"] = FunctionalRoadClass::TERTIARY_LINK;
        hash["unclassified"] = FunctionalRoadClass::UNCLASSIFIED;
        hash["residential"] = FunctionalRoadClass::RESIDENTIAL;
        hash["service"] = FunctionalRoadClass::SERVICE;
        hash["living_street"] = FunctionalRoadClass::LIVING_STREET;
        hash["track"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["road"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["path"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        hash["driveway"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
        return hash;
    }();

    if (class_hash.find(value) != class_hash.end())
    {
        return class_hash.find(value)->second;
    }
    else
    {
        util::SimpleLogger().Write(logDEBUG) << "Unknown road class encountered: " << value;
        return FunctionalRoadClass::UNKNOWN;
    }
}

inline bool isRampClass(const FunctionalRoadClass road_class)
{
    // Primary Roads and down are usually too small to announce their links as ramps
    return road_class == FunctionalRoadClass::MOTORWAY_LINK ||
           road_class == FunctionalRoadClass::TRUNK_LINK;
}

// TODO augment this with all data required for guidance generation
struct RoadClassificationData
{
    FunctionalRoadClass road_class = FunctionalRoadClass::UNKNOWN;

    void augment(const osmium::Way &way);
};

inline bool operator==(const RoadClassificationData lhs, const RoadClassificationData rhs)
{
    return lhs.road_class == rhs.road_class;
}

} // namespace guidance
} // namespace extractor
} // namespace osrm

#endif // OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_

{'fraction_non_alphanumeric': 0.0982685297691373, 'fraction_numerical': 0.0006075334143377885, 'mean_word_length': 4.156617071260768, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4326665', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1999, 'n_words': 412}