Class: Ai::Nlp::Languages
- Inherits:
-
Object
- Object
- Ai::Nlp::Languages
- Defined in:
- lib/ai/nlp/languages.rb
Overview
Class to handle multiple languages
Instance Method Summary collapse
-
#all ⇒ Object
Returns the currently known languages.
-
#create_one(name, input) ⇒ Object
Create a new language.
-
#guess(input) ⇒ Object
Offers among the available languages the closest one to the datasets.
-
#initialize ⇒ Languages
constructor
Initialisation.
Constructor Details
Instance Method Details
#all ⇒ Object
Returns the currently known languages
21 22 23 |
# File 'lib/ai/nlp/languages.rb', line 21 def all @languages = Language.all end |
#create_one(name, input) ⇒ Object
Create a new language.
40 41 42 43 |
# File 'lib/ai/nlp/languages.rb', line 40 def create_one(name, input) language = Language.new(name: name) language.update(map: @n_gram.calculate(input).to_h) end |
#guess(input) ⇒ Object
Offers among the available languages the closest one to the datasets
28 29 30 31 32 33 |
# File 'lib/ai/nlp/languages.rb', line 28 def guess(input) all return [] if @languages.empty? hash = @languages.map { |language| [language, score(input, language)] }.to_h sort(hash) end |