Commit ·
ba5b609
1
Parent(s): d085a17
Upload ChatIPC.cpp
Browse files- ChatIPC.cpp +10 -10
ChatIPC.cpp
CHANGED
|
@@ -308,7 +308,7 @@ static std::vector<std::string> tokenize_whitespace(const std::string &s){
|
|
| 308 |
return out;
|
| 309 |
}
|
| 310 |
|
| 311 |
-
static std::vector<std::string>
|
| 312 |
std::vector<std::string> out;
|
| 313 |
std::string cur;
|
| 314 |
|
|
@@ -445,7 +445,7 @@ static void build_def_tokens_cache(){
|
|
| 445 |
|
| 446 |
auto &defs = global_def_tokens_cache[key];
|
| 447 |
for (const auto &def : entry.definitions){
|
| 448 |
-
auto toks =
|
| 449 |
defs.insert(defs.end(), toks.begin(), toks.end());
|
| 450 |
}
|
| 451 |
}
|
|
@@ -771,7 +771,7 @@ static std::string best_candidate_by_similarity(
|
|
| 771 |
auto add_token_and_defs = [&](StrPtr t){
|
| 772 |
if (!t) return;
|
| 773 |
|
| 774 |
-
//
|
| 775 |
TokenId tid = interner.id_of(t);
|
| 776 |
if (tid != TOKEN_ID_INVALID) bitset_set(agg_words.data(), words, tid);
|
| 777 |
|
|
@@ -783,8 +783,8 @@ static std::string best_candidate_by_similarity(
|
|
| 783 |
}
|
| 784 |
}
|
| 785 |
|
| 786 |
-
//
|
| 787 |
-
std::vector<std::string> sub_tokens =
|
| 788 |
for (const std::string& sub_tok : sub_tokens) {
|
| 789 |
|
| 790 |
// Use id_of to check if the sub-token exists without adding a new string to the pool
|
|
@@ -823,11 +823,11 @@ static std::string best_candidate_by_similarity(
|
|
| 823 |
std::uint64_t *row = cand_words.data() + i * words;
|
| 824 |
const StrPtr cand = cands[i];
|
| 825 |
|
| 826 |
-
//
|
| 827 |
TokenId cid = interner.id_of(cand);
|
| 828 |
if (cid != TOKEN_ID_INVALID) bitset_set(row, words, cid);
|
| 829 |
|
| 830 |
-
//
|
| 831 |
auto it = def_index.find(cand);
|
| 832 |
if (it != def_index.end()){
|
| 833 |
for (StrPtr d : it->second){
|
|
@@ -836,8 +836,8 @@ static std::string best_candidate_by_similarity(
|
|
| 836 |
}
|
| 837 |
}
|
| 838 |
|
| 839 |
-
//
|
| 840 |
-
std::vector<std::string> sub_tokens =
|
| 841 |
for (const std::string& sub_tok : sub_tokens) {
|
| 842 |
|
| 843 |
// Check if the sub-token exists in our knowledge base
|
|
@@ -862,7 +862,7 @@ static std::string best_candidate_by_similarity(
|
|
| 862 |
}
|
| 863 |
}
|
| 864 |
|
| 865 |
-
//
|
| 866 |
cand_counts[i] = bitset_count(row, words);
|
| 867 |
}
|
| 868 |
|
|
|
|
| 308 |
return out;
|
| 309 |
}
|
| 310 |
|
| 311 |
+
static std::vector<std::string> tokenize_others(const std::string &s) {
|
| 312 |
std::vector<std::string> out;
|
| 313 |
std::string cur;
|
| 314 |
|
|
|
|
| 445 |
|
| 446 |
auto &defs = global_def_tokens_cache[key];
|
| 447 |
for (const auto &def : entry.definitions){
|
| 448 |
+
auto toks = tokenize_others(def);
|
| 449 |
defs.insert(defs.end(), toks.begin(), toks.end());
|
| 450 |
}
|
| 451 |
}
|
|
|
|
| 771 |
auto add_token_and_defs = [&](StrPtr t){
|
| 772 |
if (!t) return;
|
| 773 |
|
| 774 |
+
// Process the main token and its direct definitions
|
| 775 |
TokenId tid = interner.id_of(t);
|
| 776 |
if (tid != TOKEN_ID_INVALID) bitset_set(agg_words.data(), words, tid);
|
| 777 |
|
|
|
|
| 783 |
}
|
| 784 |
}
|
| 785 |
|
| 786 |
+
// Tokenize the expanded dictionary string to process sub-tokens
|
| 787 |
+
std::vector<std::string> sub_tokens = tokenize_others(*t);
|
| 788 |
for (const std::string& sub_tok : sub_tokens) {
|
| 789 |
|
| 790 |
// Use id_of to check if the sub-token exists without adding a new string to the pool
|
|
|
|
| 823 |
std::uint64_t *row = cand_words.data() + i * words;
|
| 824 |
const StrPtr cand = cands[i];
|
| 825 |
|
| 826 |
+
// Tag the candidate word itself
|
| 827 |
TokenId cid = interner.id_of(cand);
|
| 828 |
if (cid != TOKEN_ID_INVALID) bitset_set(row, words, cid);
|
| 829 |
|
| 830 |
+
// Expand the candidate's direct definition
|
| 831 |
auto it = def_index.find(cand);
|
| 832 |
if (it != def_index.end()){
|
| 833 |
for (StrPtr d : it->second){
|
|
|
|
| 836 |
}
|
| 837 |
}
|
| 838 |
|
| 839 |
+
// Tokenize the candidate to process sub-tokens (e.g., camelCase, hyphens)
|
| 840 |
+
std::vector<std::string> sub_tokens = tokenize_others(*cand);
|
| 841 |
for (const std::string& sub_tok : sub_tokens) {
|
| 842 |
|
| 843 |
// Check if the sub-token exists in our knowledge base
|
|
|
|
| 862 |
}
|
| 863 |
}
|
| 864 |
|
| 865 |
+
// Finally, count the bits for the Jaccard similarity math
|
| 866 |
cand_counts[i] = bitset_count(row, words);
|
| 867 |
}
|
| 868 |
|