neurographdb / src /tokenize.h
goethe0101's picture
Upload src/tokenize.h with huggingface_hub
13a8c43 verified
Raw
History Blame Contribute Delete
826 Bytes
/* ๊ฐ„๋‹จํ•œ ์˜์–ด ํ† ํฌ๋‚˜์ด์ € โ€” BM25์šฉ.
* ์†Œ๋ฌธ์žํ™” + ๋น„์˜์ˆซ์ž ๋ถ„๋ฆฌ. HotpotQA/MuSiQue ๊ฐ™์€ ์˜์–ด ์œ„ํ‚ค ํ…์ŠคํŠธ๊ฐ€ ๋Œ€์ƒ์ด๋ผ
* ์ด ์ •๋„๋กœ ์ถฉ๋ถ„ํ•˜๋‹ค. ํ˜•ํƒœ์†Œ ๋ถ„์„์€ ๋„ฃ์ง€ ์•Š๋Š”๋‹ค โ€” ๋„ฃ์œผ๋ฉด baseline์ด ์•„๋‹ˆ๋ผ
* ์ด๋ฏธ ํŠœ๋‹๋œ ๊ฒƒ์ด ๋˜์–ด ๋น„๊ต๊ฐ€ ๋ถˆ๊ณต์ •ํ•ด์ง„๋‹ค. */
#pragma once
#include <string>
#include <vector>
#include <cctype>
inline std::vector<std::string> tokenize(const std::string& s) {
std::vector<std::string> out;
std::string cur;
cur.reserve(24);
for (unsigned char c : s) {
if (std::isalnum(c)) {
cur.push_back(static_cast<char>(std::tolower(c)));
} else if (!cur.empty()) {
out.push_back(cur);
cur.clear();
}
}
if (!cur.empty()) out.push_back(cur);
return out;
}