Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix garbage outputs of Chinese analyzer #1306

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/common/analyzer/chinese_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ ChineseAnalyzer::ChineseAnalyzer(const String &path) : dict_path_(path) {}
ChineseAnalyzer::ChineseAnalyzer(const ChineseAnalyzer &other) {
own_jieba_ = false;
jieba_ = other.jieba_;
stopwords_ = other.stopwords_;
}
ChineseAnalyzer::~ChineseAnalyzer() {
if (own_jieba_ && jieba_)
if (own_jieba_ && jieba_) {
delete jieba_;
}
}

Status ChineseAnalyzer::Load() {
Expand Down Expand Up @@ -98,8 +100,9 @@ Status ChineseAnalyzer::Load() {
void ChineseAnalyzer::LoadStopwordsDict(const String &stopwords_path) {
std::ifstream ifs(stopwords_path);
String line;
stopwords_ = MakeShared<FlatHashSet<String>>();
while (getline(ifs, line)) {
stopwords_.insert(line);
stopwords_->insert(line);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/analyzer/chinese_analyzer.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ protected:

private:
void LoadStopwordsDict(const String &stopwords_path);
bool Accept_token(const String &term) { return !stopwords_.contains(term); }
bool Accept_token(const String &term) { return !stopwords_->contains(term); }

private:
cppjieba::Jieba *jieba_{nullptr};
String dict_path_;
bool own_jieba_{};
Vector<cppjieba::Word> cut_words_;
FlatHashSet<String> stopwords_;
SharedPtr<FlatHashSet<String>> stopwords_{};
};
} // namespace infinity
Loading