Class: RubyFastText::NN

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_fast_text/nn.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ NN

Returns a new instance of NN.



6
7
8
9
10
11
12
13
14
# File 'lib/ruby_fast_text/nn.rb', line 6

def initialize(params)
  path = params[:path]
  model = params[:model]
  @k = params.fetch(:k, 10)

  @predictor = Dir.chdir(path) do
    IO.popen("fasttext nn #{model} #{k}", 'r+')
  end
end

Instance Attribute Details

#kObject (readonly)

Returns the value of attribute k.



4
5
6
# File 'lib/ruby_fast_text/nn.rb', line 4

def k
  @k
end

#predictorObject

Returns the value of attribute predictor.



3
4
5
# File 'lib/ruby_fast_text/nn.rb', line 3

def predictor
  @predictor
end

Instance Method Details

#neighbours(word) ⇒ Object

TODO: Fix, only getting one line out of the result



17
18
19
20
# File 'lib/ruby_fast_text/nn.rb', line 17

def neighbours(word)
  predictor.puts(word)
  format_result(read_lines)
end