Skip to content

Commit

Permalink
support the bestEffort flag
Browse files Browse the repository at this point in the history
  • Loading branch information
slackhappy committed Aug 27, 2024
1 parent 1a13570 commit 974a52d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ module.exports = {
languageHint : '',
encodingHint : '',
tldHint : '',
httpHint : ''
httpHint : '',
bestEffort : false
};
options = _.defaults({}, options, defaults);

if (!_.isBoolean(options.isHTML)) {
throw new Error('Invalid isHTML value');
}
if (!_.isBoolean(options.bestEffort)) {
throw new Error('Invalid bestEffort value');
}
if (!_.isString(options.languageHint)) {
throw new Error('Invalid languageHint');
}
Expand Down Expand Up @@ -64,7 +68,8 @@ module.exports = {
options.languageHint,
options.encodingHint,
options.tldHint,
options.httpHint
options.httpHint,
options.bestEffort
);

if (result.languages.length < 1) {
Expand Down
8 changes: 7 additions & 1 deletion src/cld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace NodeCld {
httpHint;
int numBytes;
bool isPlainText;
bool bestEffort;
};

struct CLDOutput {
Expand Down Expand Up @@ -52,6 +53,7 @@ namespace NodeCld {
if (info[5].IsString()) {
input->httpHint = info[5].ToString().Utf8Value();
}
input->bestEffort = info[6].ToBoolean();

return input;
}
Expand Down Expand Up @@ -79,13 +81,17 @@ namespace NodeCld {
if (input->httpHint.length() > 0) {
hints.content_language_hint = input->httpHint.c_str();
}
int flags = 0;
if (input->bestEffort) {
flags |= CLD2::kCLDFlagBestEffort;
}

CLD2::ExtDetectLanguageSummary(
input->bytes.c_str(),
input->numBytes,
input->isPlainText,
&hints,
0,
flags,
output->language3,
output->percent3,
output->normalized_score3,
Expand Down

0 comments on commit 974a52d

Please sign in to comment.