Code Monkey home page Code Monkey logo

Comments (1)

joshrotenberg avatar joshrotenberg commented on June 12, 2024

Trying to detect with only one language results in:

iex(1)> Lingua.detect("państwowych", builder_option: :with_languages, languages: [:english])
thread '<unnamed>' panicked at 'LanguageDetector needs at least 2 languages to choose from', /Users/joshrotenberg/.cargo/registry/src/github.com-1ecc6299db9ec823/lingua-1.2.0/src/builder.rs:86:13
                                                                               ** (ArgumentError) argument error
    (lingua 0.2.0) Lingua.Nif.detect_language_of("państwowych", :with_languages, [:english], 0.0, false)
iex(1)> 

Trying to detect with an out of range minimum relative distance:

iex(4)> Lingua.detect("państwowych", builder_option: :with_languages, languages: [:english, :russian], minimum_relative_distance: 1.0)
thread '<unnamed>' panicked at 'minimum relative distance must lie in between 0.0 and 0.99', /Users/joshrotenberg/.cargo/registry/src/github.com-1ecc6299db9ec823/lingua-1.2.0/src/builder.rs:143:13
                                                                                ** (ArgumentError) argument error
    (lingua 0.2.0) Lingua.Nif.detect_language_of("państwowych", :with_languages, [:english, :russian], 1.0, false)
iex(4)> 

Ideally, these would return {:error, :too_few_languages} and {:error, :minimum_relative_distance_out_of_range} or similar.

These should be handled explicitly with std::panic::catch_unwind. This probably means breaking up build_detector and handling each in isolation. It might also be helpful to handle the common parts of detect_language_of and compute_language_confidence_values to handle the errors first, and then branch for the two different calls, or just make them one function that if/elses.

from lingua_ex.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.