genebrand 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,15 +13,23 @@ module Genebrand
13
13
  process(args, options)
14
14
  end
15
15
  end
16
+
17
+ p.default_command(:new)
16
18
  end
17
19
 
18
20
  def process(_args, _options)
19
21
  puts "Hello! Let's generate some brands!".cyan
20
22
  puts
21
23
 
24
+ choose do |menu|
25
+ menu.prompt = 'Which word DB should i use?'.yellow
26
+
27
+ menu.choice('Full (lots of words, but not high quality)') { @gen = Genebrand::Generator.new('posinfo.json') }
28
+ menu.choice('100k (based on top 100k English words, better quality)') { @gen = Genebrand::Generator.new('pos100k.json') }
29
+ menu.choice('10k (based on top 10k English words, best quality)') { @gen = Genebrand::Generator.new('pos10k.json') }
30
+ end
31
+
22
32
  brand = []
23
- stopit = false
24
- @gen = Genebrand::Generator.new
25
33
 
26
34
  catch :parts_done do
27
35
  loop do
@@ -4,8 +4,8 @@ module Genebrand
4
4
 
5
5
  attr_reader :words
6
6
 
7
- def initialize
8
- @words = JSON.parse(File.read(File.join(Gem::Specification.find_by_name('genebrand').gem_dir, 'lib/data/posinfo.json')))
7
+ def initialize(filename)
8
+ @words = JSON.parse(File.read(File.join(Gem::Specification.find_by_name('genebrand').gem_dir, "lib/data/#{filename}")))
9
9
  end
10
10
 
11
11
  def prettyoutput(domain)
@@ -4,6 +4,10 @@ module Genebrand
4
4
  require 'fileutils'
5
5
 
6
6
  def initialize
7
+ init
8
+ end
9
+
10
+ def init
7
11
  @parsed = {}
8
12
  @table = {}
9
13
  # Сущ
@@ -19,27 +23,99 @@ module Genebrand
19
23
  end
20
24
 
21
25
  def parse(filename)
26
+ init
27
+
22
28
  unless File.exist?(filename)
23
29
  fail "File not found: #{filename}"
24
30
  return
25
31
  end
26
32
 
33
+ puts "Seeding"
27
34
  File.open(filename, 'r').each_line do |line|
28
35
  data = line.split("\t")
29
36
 
30
- if !is_numeric?(data[0]) && (!/\A[a-zA-Z0-9]{2,10}\z/.match(data[0]).nil?)
37
+ data[1].split('').each do |partofsp|
38
+ @table[partofsp].push(data[0].downcase) if @table.key?(partofsp)
39
+ end
40
+ end
41
+
42
+ @parsed
43
+ end
44
+
45
+ def parse_top(filename, top)
46
+ init
47
+
48
+ unless File.exist?(filename)
49
+ fail "File not found: #{filename}"
50
+ return
51
+ end
52
+
53
+ puts "Load top"
54
+ toparr = []
55
+ File.open(top, 'r').each_line do |line|
56
+ toparr << line.strip.downcase
57
+ end
58
+ puts toparr.count
59
+
60
+ puts "Seeding"
61
+ it = 0
62
+ File.open(filename, 'r').each_line do |line|
63
+ data = line.split("\t")
64
+
65
+ if toparr.include?(data[0])
31
66
  data[1].split('').each do |partofsp|
32
- @table[partofsp].push(data[0]) if @table.key?(partofsp)
67
+ @table[partofsp].push(data[0].downcase) if @table.key?(partofsp)
33
68
  end
34
69
  end
70
+ it+=1
71
+ if it % 10000 == 0
72
+ puts it
73
+ end
35
74
  end
36
75
 
37
76
  @parsed
38
77
  end
39
78
 
40
- def parseandsave(filename)
79
+ def preseed(filename)
80
+ init
81
+
82
+ prsdata = []
83
+
84
+ unless File.exist?(filename)
85
+ fail "File not found: #{filename}"
86
+ return
87
+ end
88
+
89
+ puts "Preseed"
90
+ File.open(filename, 'r').each_line do |line|
91
+ data = line.split("\t")
92
+
93
+ if !is_numeric?(data[0]) && (!/\A[a-zA-Z0-9]{2,10}\z/.match(data[0]).nil?)
94
+ prsdata << line
95
+ end
96
+ end
97
+
98
+ prsdata
99
+ end
100
+
101
+ def parseandsave(filename, to)
102
+ FileUtils.mkdir_p 'lib/data'
103
+ File.open(to, 'w+') { |f| f.write(parse(filename).to_json) }
104
+ end
105
+
106
+ def parseandsave_preseed(filename, to)
107
+ FileUtils.mkdir_p 'lib/data'
108
+ File.open(to, 'w+') do |f|
109
+ write = preseed(filename)
110
+ write.each do |line|
111
+ f.write(line)
112
+ end
113
+ end
114
+ end
115
+
116
+ def parseandsave_top(filename, top, to)
41
117
  FileUtils.mkdir_p 'lib/data'
42
- File.open('lib/data/posinfo.json', 'w+') { |f| f.write(parse(filename).to_json) }
118
+ File.open(to, 'w+') { |f| f.write(parse_top(filename, top).to_json) }
43
119
  end
44
120
 
45
121
  def is_numeric?(obj)
@@ -1,3 +1,3 @@
1
1
  module Genebrand
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genebrand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Viktorov
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.2'
97
83
  description: CLI brand names generator
98
84
  email:
99
85
  - andv@outlook.com
@@ -113,6 +99,8 @@ files:
113
99
  - bin/setup
114
100
  - exe/genebrand
115
101
  - genebrand.gemspec
102
+ - lib/data/pos100k.json
103
+ - lib/data/pos10k.json
116
104
  - lib/data/posinfo.json
117
105
  - lib/genebrand.rb
118
106
  - lib/genebrand/command.rb
@@ -134,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
122
  requirements:
135
123
  - - ">="
136
124
  - !ruby/object:Gem::Version
137
- version: '0'
125
+ version: 1.9.3
138
126
  required_rubygems_version: !ruby/object:Gem::Requirement
139
127
  requirements:
140
128
  - - ">="