mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Formatted includes/services/enrichment
This commit is contained in:
@@ -14,16 +14,16 @@
|
|||||||
* @brief Interface for services that can enrich a location with context.
|
* @brief Interface for services that can enrich a location with context.
|
||||||
*/
|
*/
|
||||||
class IEnrichmentService {
|
class IEnrichmentService {
|
||||||
public:
|
public:
|
||||||
virtual ~IEnrichmentService() = default;
|
virtual ~IEnrichmentService() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resolves contextual enrichment for a location.
|
* @brief Resolves contextual enrichment for a location.
|
||||||
*
|
*
|
||||||
* @param loc City to enrich.
|
* @param loc City to enrich.
|
||||||
* @return Context text, or an empty string if unavailable.
|
* @return Context text, or an empty string if unavailable.
|
||||||
*/
|
*/
|
||||||
virtual std::string GetLocationContext(const City& loc) = 0;
|
virtual std::string GetLocationContext(const City& loc) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_ENRICHMENT_SERVICE_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_ENRICHMENT_SERVICE_H_
|
||||||
|
|||||||
@@ -14,9 +14,7 @@
|
|||||||
* @brief Enrichment service that returns no context for any location.
|
* @brief Enrichment service that returns no context for any location.
|
||||||
*/
|
*/
|
||||||
class MockEnrichmentService final : public IEnrichmentService {
|
class MockEnrichmentService final : public IEnrichmentService {
|
||||||
public:
|
public:
|
||||||
std::string GetLocationContext(const City& /*loc*/) override {
|
std::string GetLocationContext(const City& /*loc*/) override { return {}; }
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_MOCK_ENRICHMENT_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_MOCK_ENRICHMENT_H_
|
||||||
|
|||||||
@@ -19,30 +19,30 @@
|
|||||||
* @brief Provides Wikipedia summary lookups backed by cached raw extracts.
|
* @brief Provides Wikipedia summary lookups backed by cached raw extracts.
|
||||||
*/
|
*/
|
||||||
class WikipediaEnrichmentService final : public IEnrichmentService {
|
class WikipediaEnrichmentService final : public IEnrichmentService {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new Wikipedia service with the provided web client.
|
* @brief Creates a new Wikipedia service with the provided web client.
|
||||||
*/
|
*/
|
||||||
explicit WikipediaEnrichmentService(std::unique_ptr<WebClient> client,
|
explicit WikipediaEnrichmentService(std::unique_ptr<WebClient> client,
|
||||||
std::shared_ptr<ILogger> logger);
|
std::shared_ptr<ILogger> logger);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the Wikipedia-derived context for a location.
|
* @brief Returns the Wikipedia-derived context for a location.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string GetLocationContext(const City& loc) override;
|
[[nodiscard]] std::string GetLocationContext(const City& loc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string FetchExtract(std::string_view query);
|
std::string FetchExtract(std::string_view query);
|
||||||
std::unique_ptr<WebClient> client_;
|
std::unique_ptr<WebClient> client_;
|
||||||
std::shared_ptr<ILogger> logger_;
|
std::shared_ptr<ILogger> logger_;
|
||||||
/**
|
/**
|
||||||
* @brief Cache for raw Wikipedia query extracts, keyed by query string.
|
* @brief Cache for raw Wikipedia query extracts, keyed by query string.
|
||||||
*
|
*
|
||||||
* GetLocationContext() always queries "brewing" and reuses "beer in
|
* GetLocationContext() always queries "brewing" and reuses "beer in
|
||||||
* {country}" for every city in that country, so caching avoids refetching
|
* {country}" for every city in that country, so caching avoids refetching
|
||||||
* the same extract across locations in a run.
|
* the same extract across locations in a run.
|
||||||
*/
|
*/
|
||||||
std::unordered_map<std::string, std::string> extract_cache_;
|
std::unordered_map<std::string, std::string> extract_cache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_WIKIPEDIA_SERVICE_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_WIKIPEDIA_SERVICE_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user