From 974a52d97f5690e2b12b8c3c65faeec5e9a65965 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Tue, 27 Aug 2024 15:06:04 -0400 Subject: [PATCH] support the bestEffort flag --- index.js | 9 +++++++-- src/cld.cc | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b59d40b..72109a8 100644 --- a/index.js +++ b/index.js @@ -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'); } @@ -64,7 +68,8 @@ module.exports = { options.languageHint, options.encodingHint, options.tldHint, - options.httpHint + options.httpHint, + options.bestEffort ); if (result.languages.length < 1) { diff --git a/src/cld.cc b/src/cld.cc index 627e07e..fc6d343 100644 --- a/src/cld.cc +++ b/src/cld.cc @@ -19,6 +19,7 @@ namespace NodeCld { httpHint; int numBytes; bool isPlainText; + bool bestEffort; }; struct CLDOutput { @@ -52,6 +53,7 @@ namespace NodeCld { if (info[5].IsString()) { input->httpHint = info[5].ToString().Utf8Value(); } + input->bestEffort = info[6].ToBoolean(); return input; } @@ -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,