Module: Chakin::Downloader
- Included in:
- Vectors
- Defined in:
- lib/chakin-rb/chakin.rb
Instance Method Summary collapse
-
#download(number: nil, name: '', save_dir: './') ⇒ Object
Download pre-trained word vector.
- #load_datasets(path = File.join(__dir__, 'datasets.csv')) ⇒ Object
- #search(lang = '') ⇒ Object
Instance Method Details
#download(number: nil, name: '', save_dir: './') ⇒ Object
Download pre-trained word vector
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chakin-rb/chakin.rb', line 16 def download(number: nil, name: '', save_dir: './') df = load_datasets row = if !number.nil? df.row[number] elsif name df.df.where(df['Name'].eq(name)) end url = row['URL'] raise 'The word vector you specified was not found. Please specify correct name.' if url.nil? = ProgressBar.create file_name = url.split('/')[-1] File.mkdir(save_dir) unless File.exist?(save_dir) save_path = File.join(save_dir, file_name) f = File.open(save_path, 'wb') begin my_uri = URI.parse(url) Net::HTTP.start(my_uri.host) do |http| http.request_get(my_uri.path) do |resp| total_size = resp.content_length .total = total_size resp.read_body do |segment| .progress += segment.size f.write(segment) end end end ensure f.close end save_path end |
#load_datasets(path = File.join(__dir__, 'datasets.csv')) ⇒ Object
10 11 12 |
# File 'lib/chakin-rb/chakin.rb', line 10 def load_datasets(path = File.join(__dir__, 'datasets.csv')) Daru::DataFrame.from_csv(path) end |
#search(lang = '') ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/chakin-rb/chakin.rb', line 57 def search(lang = '') df = load_datasets if lang == '' puts df.inspect else rows = df.where(df['Language'].eq(lang)) puts rows['Name', 'Dimension', 'Corpus', 'VocabularySize', 'Method', 'Language', 'Author'].inspect end end |