File size: 826 Bytes
13a8c43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* ๊ฐ„๋‹จํ•œ ์˜์–ด ํ† ํฌ๋‚˜์ด์ € โ€” 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;
}