Skip to content

Commit

Permalink
Fix cpp style
Browse files Browse the repository at this point in the history
  • Loading branch information
pkufool committed Jan 11, 2024
1 parent d63cc88 commit 29bd76f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
29 changes: 19 additions & 10 deletions sherpa-onnx/csrc/keyword-spotter-transducer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
}

std::unique_ptr<OnlineStream> CreateStream(
const std::string& keywords) const override {
const std::string &keywords) const override {
auto kws = std::regex_replace(keywords, std::regex("/"), "\n");
std::istringstream is(kws);

Expand All @@ -123,7 +123,8 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
int32_t num_kws = current_ids.size();
int32_t num_default_kws = keywords_id_.size();

current_ids.insert(current_ids.end(), keywords_id_.begin(), keywords_id_.end());
current_ids.insert(current_ids.end(), keywords_id_.begin(),
keywords_id_.end());

if (!current_kws.empty() && !keywords_.empty()) {
current_kws.insert(current_kws.end(), keywords_.begin(), keywords_.end());
Expand All @@ -137,23 +138,31 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
}

if (!current_scores.empty() && !boost_scores_.empty()) {
current_scores.insert(current_scores.end(), boost_scores_.begin(), boost_scores_.end());
current_scores.insert(current_scores.end(), boost_scores_.begin(),
boost_scores_.end());
} else if (!current_scores.empty() && boost_scores_.empty()) {
current_scores.insert(current_scores.end(), num_default_kws, config_.keywords_score);
current_scores.insert(current_scores.end(), num_default_kws,
config_.keywords_score);
} else if (current_scores.empty() && !boost_scores_.empty()) {
current_scores.insert(current_scores.end(), num_kws, config_.keywords_score);
current_scores.insert(current_scores.end(), boost_scores_.begin(), boost_scores_.end());
current_scores.insert(current_scores.end(), num_kws,
config_.keywords_score);
current_scores.insert(current_scores.end(), boost_scores_.begin(),
boost_scores_.end());
} else {
// Do nothing.
}

if (!current_thresholds.empty() && !thresholds_.empty()) {
current_thresholds.insert(current_thresholds.end(), thresholds_.begin(), thresholds_.end());
current_thresholds.insert(current_thresholds.end(), thresholds_.begin(),
thresholds_.end());
} else if (!current_thresholds.empty() && thresholds_.empty()) {
current_thresholds.insert(current_thresholds.end(), num_default_kws, config_.keywords_threshold);
current_thresholds.insert(current_thresholds.end(), num_default_kws,
config_.keywords_threshold);
} else if (current_thresholds.empty() && !thresholds_.empty()) {
current_thresholds.insert(current_thresholds.end(), num_kws, config_.keywords_threshold);
current_thresholds.insert(current_thresholds.end(), thresholds_.begin(), thresholds_.end());
current_thresholds.insert(current_thresholds.end(), num_kws,
config_.keywords_threshold);
current_thresholds.insert(current_thresholds.end(), thresholds_.begin(),
thresholds_.end());
} else {
// Do nothing.
}
Expand Down
7 changes: 4 additions & 3 deletions sherpa-onnx/jni/jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class SherpaOnnxKws {
stream_->InputFinished();
}

bool SetKeywords(const std::string& keywords) {
bool SetKeywords(const std::string &keywords) {
auto stream = keyword_spotter_.CreateStream(keywords);
if (stream == nullptr) {
return false;
Expand Down Expand Up @@ -1264,12 +1264,13 @@ JNIEXPORT jstring JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnxKws_getKeyword(
SHERPA_ONNX_EXTERN_C
JNIEXPORT bool JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnxKws_setKeywords(
JNIEnv *env, jobject /*obj*/, jlong ptr, jstring keywords) {

const char *p_keywords = env->GetStringUTFChars(keywords, nullptr);

std::string keywords_str = p_keywords;

bool status = reinterpret_cast<sherpa_onnx::SherpaOnnxKws *>(ptr)->SetKeywords(keywords_str);
bool status =
reinterpret_cast<sherpa_onnx::SherpaOnnxKws *>(ptr)->SetKeywords(
keywords_str);
env->ReleaseStringUTFChars(keywords, p_keywords);
return status;
}
Expand Down

0 comments on commit 29bd76f

Please sign in to comment.