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

support the bestEffort flag #84

Merged
merged 1 commit into from
Aug 27, 2024
Merged

support the bestEffort flag #84

merged 1 commit into from
Aug 27, 2024

Conversation

slackhappy
Copy link
Contributor

@slackhappy slackhappy commented Aug 27, 2024

Support CLD2::kCLDFlagBestEffort for shorter text

Helps with issues like #78 for example:

without bestEffort

> console.log((await cld.detect("J'aime me beurrer la biscote")))
Uncaught Error: Failed to identify language
    at Object.detect (/Users/jgallagher/extsrc/slackhappy.gh/node-cld/index.js:76:15)
    at async REPL6:1:46

with bestEffort:

> console.log((await cld.detect("J'aime me beurrer la biscote", {bestEffort:true})))
{
  reliable: true,
  textBytes: 30,
  languages: [ { name: 'FRENCH', code: 'fr', percent: 96, score: 176 } ],
  chunks: []
}

Or #31

> console.log((await cld.detect("beija-flor: laíla defende maior número de parcerias e critica altos gastos")))
Uncaught Error: Failed to identify language
    at Object.detect (/Users/jgallagher/extsrc/slackhappy.gh/node-cld/index.js:76:15)
    at async REPL9:1:46

with bestEffort:

> console.log((await cld.detect("beija-flor: laíla defende maior número de parcerias e critica altos gastos", {bestEffort:true})))
{
  reliable: true,
  textBytes: 77,
  languages: [ { name: 'PORTUGUESE', code: 'pt', percent: 98, score: 215 } ],
  chunks: []
}

#33

> console.log(await cld.detect('Hi there'))
Uncaught Error: Failed to identify language
    at Object.detect (/Users/jgallagher/extsrc/slackhappy.gh/node-cld/index.js:76:15)
    at async REPL3:1:45
> 

with bestEffort:

> console.log(await cld.detect('Hi there', {bestEffort:true}))
{
  reliable: true,
  textBytes: 10,
  languages: [ { name: 'ENGLISH', code: 'en', percent: 90, score: 796 } ],
  chunks: []
}

@dachev
Copy link
Owner

dachev commented Aug 27, 2024

@slackhappy thank you!

@slackhappy
Copy link
Contributor Author

oops sorry - one more update to the typescript defs and the docs

@@ -91,6 +91,11 @@ Pass top level domain as a hint

Pass an HTTP "Content-Encoding" value as a hint

#### bestEffort

Set to true to give best-effort answer, instead of UNKNOWN_LANGUAGE. May be useful for
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description is from

kCLDFlagBestEffort

@slackhappy
Copy link
Contributor Author

@dachev, ready for re-review, I added documentation and updated the ts defs. Thanks so much for considering this PR!

@dachev dachev merged commit 9dec3cd into dachev:master Aug 27, 2024
1 check passed
@dachev
Copy link
Owner

dachev commented Aug 27, 2024

@slackhappy thanks for the contribution. I pushed the changes to npm: https://www.npmjs.com/package/cld?activeTab=versions

@slackhappy slackhappy deleted the bestEffort branch August 27, 2024 23:47
@slackhappy
Copy link
Contributor Author

@dachev, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants