parent
e9657e819d
commit
006471b2e2
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Highlighter {
|
||||||
|
public:
|
||||||
|
struct HighlightSpan {
|
||||||
|
size_t start;
|
||||||
|
size_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::string highlight_text(
|
||||||
|
const std::string& text,
|
||||||
|
const std::vector<std::string>& keywords,
|
||||||
|
const std::string& pre_tag = "<em>",
|
||||||
|
const std::string& post_tag = "</em>"
|
||||||
|
);
|
||||||
|
|
||||||
|
static std::vector<HighlightSpan> find_keyword_positions(
|
||||||
|
const std::string& text,
|
||||||
|
const std::vector<std::string>& keywords
|
||||||
|
);
|
||||||
|
|
||||||
|
static std::string extract_snippet(
|
||||||
|
const std::string& text,
|
||||||
|
const std::vector<HighlightSpan>& spans,
|
||||||
|
size_t context_size = 50
|
||||||
|
);
|
||||||
|
};
|
Loading…
Reference in new issue