mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-12 06:35:44 +08:00
Go: fix register user (#16058)
### What problem does this PR solve? Fix register user ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -164,7 +164,7 @@ add_executable(rag_analyzer_c_test
|
||||
rag_analyzer_c_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(rag_analyzer_c_test rag_tokenizer_c_api stdc++ libm.a ${PCRE2_LIB})
|
||||
target_link_libraries(rag_analyzer_c_test rag_tokenizer_c_api stdc++ m ${PCRE2_LIB})
|
||||
target_include_directories(rag_analyzer_c_test PUBLIC "${CMAKE_SOURCE_DIR}")
|
||||
set_target_properties(rag_analyzer_c_test PROPERTIES
|
||||
CXX_STANDARD 20
|
||||
|
||||
@@ -684,35 +684,38 @@ RAGAnalyzer::~RAGAnalyzer() {
|
||||
|
||||
int32_t RAGAnalyzer::Load() {
|
||||
fs::path root(dict_path_);
|
||||
fs::path dict_path(root / DICT_PATH);
|
||||
|
||||
fs::path dict_path(root / DICT_PATH);
|
||||
printf("Validate dict file: %s\n", dict_path.string().c_str());
|
||||
if (!fs::exists(dict_path)) {
|
||||
printf("Invalid analyzer file: %s", dict_path.string().c_str());
|
||||
// return Status::InvalidAnalyzerFile(dict_path);
|
||||
printf("Invalid dict file: %s\n", dict_path.string().c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path pos_def_path(root / POS_DEF_PATH);
|
||||
printf("Validate pos file: %s\n", pos_def_path.string().c_str());
|
||||
if (!fs::exists(pos_def_path)) {
|
||||
printf("Invalid post file: %s", pos_def_path.string().c_str());
|
||||
// return Status::InvalidAnalyzerFile(pos_def_path);
|
||||
return -1;
|
||||
printf("Invalid pos file: %s\n", pos_def_path.string().c_str());
|
||||
return -2;
|
||||
}
|
||||
own_dict_ = true;
|
||||
trie_ = new DartsTrie();
|
||||
pos_table_ = new POSTable(pos_def_path.string());
|
||||
printf("Load pos file: %s\n", pos_def_path.string().c_str());
|
||||
if (pos_table_->Load() != 0) {
|
||||
printf("Fail to load post table: %s", pos_def_path.string().c_str());
|
||||
return -1;
|
||||
// return Status::InvalidAnalyzerFile("Failed to load RAGAnalyzer POS definition");
|
||||
printf("Fail to load pos file: %s\n", pos_def_path.string().c_str());
|
||||
return -3;
|
||||
}
|
||||
|
||||
fs::path trie_path(root / TRIE_PATH);
|
||||
printf("Validate trie file: %s\n", trie_path.string().c_str());
|
||||
if (fs::exists(trie_path)) {
|
||||
printf("Load trie file: %s\n", trie_path.string().c_str());
|
||||
trie_->Load(trie_path.string());
|
||||
} else {
|
||||
// Build trie
|
||||
try {
|
||||
printf("Build trie file: %s\n", dict_path.string().c_str());
|
||||
std::ifstream from(dict_path.string());
|
||||
std::string line;
|
||||
re2::RE2 re_pattern(R"([\r\n]+)");
|
||||
@@ -737,36 +740,35 @@ int32_t RAGAnalyzer::Load() {
|
||||
}
|
||||
trie_->Build();
|
||||
} catch (const std::exception &e) {
|
||||
return -1;
|
||||
// return Status::InvalidAnalyzerFile("Failed to load RAGAnalyzer analyzer");
|
||||
printf("Fail to build trie: %s\n", e.what());
|
||||
return -4;
|
||||
}
|
||||
printf("Save trie file: %s\n", trie_path.string().c_str());
|
||||
trie_->Save(trie_path.string());
|
||||
}
|
||||
|
||||
fs::path lemma_path(root / WORDNET_PATH);
|
||||
if (!fs::exists(lemma_path)) {
|
||||
printf("Fail to load wordnet: %s", lemma_path.string().c_str());
|
||||
return -1;
|
||||
// return Status::InvalidAnalyzerFile(lemma_path);
|
||||
printf("Fail to load wordnet: %s\n", lemma_path.string().c_str());
|
||||
return -5;
|
||||
}
|
||||
|
||||
wordnet_lemma_ = new WordNetLemmatizer(lemma_path.string());
|
||||
|
||||
fs::path opencc_path(root / OPENCC_PATH);
|
||||
|
||||
printf("Validate opencc file: %s\n", opencc_path.string().c_str());
|
||||
if (!fs::exists(opencc_path)) {
|
||||
printf("Fail to load opencc_path: %s", opencc_path.string().c_str());
|
||||
return -1;
|
||||
// return Status::InvalidAnalyzerFile(opencc_path);
|
||||
printf("opencc_path not exists: %s\n", opencc_path.string().c_str());
|
||||
return -6;
|
||||
}
|
||||
try {
|
||||
printf("Load opencc file: %s\n", opencc_path.string().c_str());
|
||||
opencc_ = new ::OpenCC(opencc_path.string());
|
||||
} catch (const std::exception &e) {
|
||||
return -1;
|
||||
// return Status::InvalidAnalyzerFile("Failed to load OpenCC");
|
||||
printf("Fail to open opencc: %s\n", opencc_path.string().c_str());
|
||||
return -7;
|
||||
}
|
||||
|
||||
// return Status::OK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ void test_single_thread() {
|
||||
std::cout << "Test 1: Single thread, 1000 iterations..." << std::endl;
|
||||
|
||||
// Create analyzer instance
|
||||
RAGAnalyzerHandle handle = RAGAnalyzer_Create(".");
|
||||
RAGAnalyzerHandle handle = RAGAnalyzer_Create("./resource");
|
||||
assert(handle != nullptr && "Failed to create RAGAnalyzer");
|
||||
|
||||
// Load the analyzer
|
||||
@@ -110,8 +110,9 @@ void test_multi_thread() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Please make sure the './resource' directory exists and is accessible." << std::endl;
|
||||
std::cout << "=== RAGAnalyzer C API Test ===" << std::endl;
|
||||
|
||||
|
||||
test_single_thread();
|
||||
// test_multi_thread();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user