asker-tool 2.1.5 → 2.1.6

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE → LICENSE.txt} +0 -0
  3. data/README.md +2 -3
  4. data/bin/asker +1 -0
  5. data/lib/asker.rb +10 -6
  6. data/lib/asker/ai/ai.rb +4 -0
  7. data/lib/asker/ai/code/base_code_ai.rb +104 -0
  8. data/lib/asker/{code/ai → ai/code}/code_ai_factory.rb +11 -1
  9. data/lib/asker/{code/ai → ai/code}/javascript_code_ai.rb +2 -5
  10. data/lib/asker/ai/code/problem_code_ai.rb +176 -0
  11. data/lib/asker/{code/ai → ai/code}/python_code_ai.rb +2 -5
  12. data/lib/asker/{code/ai → ai/code}/ruby_code_ai.rb +14 -7
  13. data/lib/asker/{code/ai → ai/code}/sql_code_ai.rb +2 -5
  14. data/lib/asker/ai/concept_ai.rb +1 -0
  15. data/lib/asker/ai/stages/stage_t.rb +76 -76
  16. data/lib/asker/application.rb +18 -2
  17. data/lib/asker/checker.rb +112 -30
  18. data/lib/asker/cli.rb +12 -25
  19. data/lib/asker/data/code.rb +73 -0
  20. data/lib/asker/data/column.rb +31 -21
  21. data/lib/asker/data/concept.rb +42 -45
  22. data/lib/asker/data/data_field.rb +14 -0
  23. data/lib/asker/data/row.rb +75 -52
  24. data/lib/asker/data/table.rb +89 -42
  25. data/lib/asker/data/world.rb +57 -33
  26. data/lib/asker/displayer/concept_ai_displayer.rb +56 -37
  27. data/lib/asker/displayer/concept_displayer.rb +7 -5
  28. data/lib/asker/displayer/stats_displayer.rb +4 -3
  29. data/lib/asker/exporter/concept_ai_gift_exporter.rb +5 -3
  30. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +7 -3
  31. data/lib/asker/exporter/output_file_exporter.rb +1 -1
  32. data/lib/asker/files/config.ini +37 -0
  33. data/lib/asker/files/example-concept.haml +0 -1
  34. data/lib/asker/{lang/locales → files/language}/du/templates.yaml +0 -0
  35. data/lib/asker/{lang/locales → files/language}/en/connectors.yaml +0 -0
  36. data/lib/asker/{lang/locales → files/language}/en/mistakes.yaml +0 -0
  37. data/lib/asker/{lang/locales → files/language}/en/templates.yaml +0 -0
  38. data/lib/asker/{lang/locales → files/language}/es/connectors.yaml +0 -0
  39. data/lib/asker/{lang/locales → files/language}/es/mistakes.yaml +0 -0
  40. data/lib/asker/{lang/locales → files/language}/es/templates.yaml +0 -0
  41. data/lib/asker/{lang/locales → files/language}/fr/connectors.yaml +0 -0
  42. data/lib/asker/{lang/locales → files/language}/fr/mistakes.yaml +0 -0
  43. data/lib/asker/{lang/locales → files/language}/fr/templates.yaml +0 -0
  44. data/lib/asker/{lang/locales → files/language}/javascript/connectors.yaml +0 -0
  45. data/lib/asker/{lang/locales → files/language}/javascript/mistakes.yaml +0 -0
  46. data/lib/asker/{lang/locales → files/language}/javascript/templates.yaml +0 -0
  47. data/lib/asker/{lang/locales → files/language}/math/connectors.yaml +0 -0
  48. data/lib/asker/{lang/locales → files/language}/math/mistakes.yaml +0 -0
  49. data/lib/asker/{lang/locales → files/language}/math/templates.yaml +0 -0
  50. data/lib/asker/{lang/locales → files/language}/python/connectors.yaml +0 -0
  51. data/lib/asker/{lang/locales → files/language}/python/mistakes.yaml +0 -0
  52. data/lib/asker/{lang/locales → files/language}/python/templates.yaml +0 -0
  53. data/lib/asker/{lang/locales → files/language}/ruby/connectors.yaml +0 -0
  54. data/lib/asker/{lang/locales → files/language}/ruby/mistakes.yaml +0 -0
  55. data/lib/asker/{lang/locales → files/language}/ruby/templates.yaml +0 -0
  56. data/lib/asker/{lang/locales → files/language}/sql/connectors.yaml +0 -0
  57. data/lib/asker/{lang/locales → files/language}/sql/mistakes.yaml +0 -0
  58. data/lib/asker/{lang/locales → files/language}/sql/templates.yaml +0 -0
  59. data/lib/asker/lang/lang.rb +17 -10
  60. data/lib/asker/lang/lang_factory.rb +26 -5
  61. data/lib/asker/lang/text_actions.rb +87 -69
  62. data/lib/asker/loader/code_loader.rb +3 -3
  63. data/lib/asker/loader/content_loader.rb +9 -5
  64. data/lib/asker/loader/file_loader.rb +2 -11
  65. data/lib/asker/loader/haml_loader.rb +15 -0
  66. data/lib/asker/loader/image_url_loader.rb +5 -8
  67. data/lib/asker/loader/input_loader.rb +8 -9
  68. data/lib/asker/loader/project_loader.rb +10 -8
  69. data/lib/asker/logger.rb +3 -3
  70. data/lib/asker/project.rb +24 -50
  71. data/lib/asker/skeleton.rb +22 -13
  72. metadata +39 -37
  73. data/lib/asker/code/ai/base_code_ai.rb +0 -48
  74. data/lib/asker/code/code.rb +0 -53
@@ -1,93 +1,116 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require_relative 'column'
3
4
 
5
+ ##
6
+ # Row objects
4
7
  class Row
5
8
  attr_reader :table, :index, :id
6
9
  attr_reader :langs, :types, :raws, :columns
7
10
  attr_reader :simple
8
11
 
9
- def initialize( table, index, xml_data )
12
+ ##
13
+ # Initialize Row Object
14
+ # @param table (Table)
15
+ # @param index (Integer)
16
+ # @param xml_data (XML)
17
+ def initialize(table, index, xml_data)
10
18
  @table = table
11
19
  @index = index
12
- @id = @table.id + "." + @index.to_s
20
+ @id = "#{@table.id}.#{@index}"
13
21
  @langs = @table.langs
14
22
  @types = @table.types
15
23
  @raws = []
16
24
  @columns = []
17
- @simple = { :lang => true, :type => true }
25
+ @simple = { lang: true, type: true }
18
26
  read_data_from_xml(xml_data)
19
27
  end
20
28
 
21
29
  def simple_off(option)
22
- @simple[option]=false
30
+ @simple[option] = false
23
31
  @table.simple_off(option)
24
32
  end
25
33
 
26
- private
34
+ private
27
35
 
28
- def read_data_from_xml(pXMLdata)
29
- if pXMLdata.elements.count==0 then
30
- build_row_with_1_column(pXMLdata)
36
+ def read_data_from_xml(xml_data)
37
+ if xml_data.elements.count.zero?
38
+ build_row_with_1_column(xml_data)
31
39
  else
32
- build_row_with_N_columns(pXMLdata)
40
+ build_row_with_n_columns(xml_data)
33
41
  end
34
42
 
35
- raise "[ERROR] Row: #{pXMLdata}" if @columns.size!=@table.fields.size
43
+ raise "[ERROR] Row: #{xml_data}" unless @columns.size == @table.fields.size
36
44
  end
37
45
 
38
- def build_row_with_1_column(pXMLdata)
46
+ def build_row_with_1_column(xml_data)
39
47
  # When row tag only has text, we add this text as one value array
40
48
  # This is usefull for tables with only one columns
41
- @columns = [ Column.new( self, @raws.size, pXMLdata) ]
42
- @raws = [ pXMLdata.text.strip.to_s ]
43
-
44
- #read attributes from XML data
45
- if pXMLdata.attributes['lang'] then
46
- code = pXMLdata.attributes['lang'].strip
47
- if code != @langs[0].code then
48
- @langs = [ LangFactory.instance.get(code) ]
49
- @simple[:lang]= false
50
- @table.simple_off(:lang)
51
- end
52
- end
49
+ @columns = [Column.new(self, @raws.size, xml_data)]
50
+ @raws = [xml_data.text.strip.to_s]
53
51
 
54
- if pXMLdata.attributes['type'] then
55
- type = pXMLdata.attributes['type'].strip
56
- if type != @types[0] then
57
- @types = [ type ]
58
- @simple[:type]= false
59
- @table.simple_off(:type)
60
- end
61
- end
52
+ # read attributes from XML data
53
+ read_lang_from_xml(xml_data)
54
+ read_type_from_xml(xml_data)
62
55
  end
63
56
 
64
- def build_row_with_N_columns(pXMLdata)
65
- pXMLdata.elements.each do |i|
57
+ def read_lang_from_xml(xml_data)
58
+ return unless xml_data.attributes['lang']
59
+
60
+ code = xml_data.attributes['lang'].strip
61
+ return if code == @langs[0].code
62
+
63
+ @langs = [LangFactory.instance.get(code)]
64
+ @simple[:lang] = false
65
+ @table.simple_off(:lang)
66
+ end
67
+
68
+ def read_type_from_xml(xml_data)
69
+ return unless xml_data.attributes['type']
70
+
71
+ type = xml_data.attributes['type'].strip
72
+ return if type == @types[0]
73
+
74
+ @types = [type]
75
+ @simple[:type] = false
76
+ @table.simple_off(:type)
77
+ end
78
+
79
+ # rubocop:disable Metrics/MethodLength
80
+ def build_row_with_n_columns(xml_data)
81
+ xml_data.elements.each do |i|
66
82
  case i.name
67
83
  when 'lang'
68
- j = i.text.split(",")
69
- codes = @langs.map {|i| i.code }
70
-
71
- if j.join(",")!=codes.join(",")
72
- @langs = []
73
- j.each { |k| @langs << LangFactory.instance.get(k.strip.to_s) }
74
- @simple[:lang]=false
75
- @table.simple_off(:lang)
76
- end
84
+ read_langs_from_xml(i)
77
85
  when 'type'
78
- j = i.text.split(",")
79
- if j.join(",")!=@types.join(",") then
80
- @types = []
81
- j.each { |k| @types << k.strip.to_s }
82
- @simple[:type]=false
83
- @table.simple_off(:type)
84
- end
85
- when 'col' # When row tag has several columns, we add every value to the array
86
- #Column Objects
87
- @columns << Column.new( self, @raws.size, i)
86
+ read_types_from_xml(i)
87
+ when 'col'
88
+ # When row has several columns, we add every value to the array
89
+ @columns << Column.new(self, @raws.size, i) # Column Objects
88
90
  @raws << i.text.to_s
89
91
  end
90
92
  end
91
93
  end
94
+ # rubocop:enable Metrics/MethodLength
95
+
96
+ def read_langs_from_xml(xml_data)
97
+ j = xml_data.text.split(',')
98
+ codes = @langs.map(&:code)
99
+ return if j.join(',') == codes.join(',')
100
+
101
+ @langs = []
102
+ j.each { |k| @langs << LangFactory.instance.get(k.strip.to_s) }
103
+ @simple[:lang] = false
104
+ @table.simple_off(:lang)
105
+ end
92
106
 
107
+ def read_types_from_xml(xml_data)
108
+ j = xml_data.text.split(',')
109
+ return if j.join(',') == @types.join(',')
110
+
111
+ @types = []
112
+ j.each { |k| @types << k.strip.to_s }
113
+ @simple[:type] = false
114
+ @table.simple_off(:type)
115
+ end
93
116
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'row'
4
4
  require_relative 'template'
@@ -6,75 +6,96 @@ require_relative 'template'
6
6
  # Contains data table information
7
7
  class Table
8
8
  attr_reader :name, :id
9
- attr_reader :fields, :langs, :types, :sequence
10
- attr_reader :datarows, :rows
9
+ attr_reader :fields, :sequence
10
+ attr_reader :langs
11
+ attr_reader :datarows # DEV: experimental replace for Row objects
12
+ attr_reader :rows # Row objects are Datarows.raws values
13
+ # Table is simple when all their rows and col has the same lang and type value
11
14
  attr_reader :simple
12
15
 
16
+ ##
17
+ # initialize Table object
18
+ # @param concept (Concept)
19
+ # @param xml_data (XML)
13
20
  def initialize(concept, xml_data)
14
21
  @concept = concept
22
+ read_attributes_from_xml(xml_data)
15
23
 
16
- # read attributes from XML data
17
- t = xml_data.attributes['fields'].to_s.strip.split(',')
18
- t.each { |i| i.strip! }
19
- @fields = t || []
24
+ @simple = { lang: true, type: true }
20
25
  @types = ['text'] * @fields.size
21
26
  @langs = [@concept.lang] * @fields.size
22
27
 
23
- @name = ''
24
- @fields.each { |i| @name=@name + '$' + i.to_s.strip.downcase}
25
- @id = @concept.name.to_s + '.' + @name
26
- @simple = { lang: true, type: true }
27
-
28
- @sequence = []
29
- if xml_data.attributes['sequence']
30
- t = xml_data.attributes['sequence'].to_s || ""
31
- @sequence = t.split(",")
32
- # puts "[DEPRECATED] sequence attr on table <#{@name}>"
33
- end
34
-
35
- @datarows = [] #DEV experiment replace row data with row objects
28
+ @datarows = [] # DEV experiment replace row data with row objects
36
29
  read_data_from_xml(xml_data)
37
- @rows = @datarows.map { |r| r.raws }
30
+ @rows = @datarows.map(&:raws)
38
31
  end
39
32
 
33
+ ##
34
+ # Return table name
40
35
  def to_s
41
36
  @name.to_s
42
37
  end
43
38
 
39
+ ##
40
+ # Return true if table has a sequence defined
44
41
  def sequence?
45
- @sequence.size > 0
42
+ @sequence.size.positive?
46
43
  end
47
44
 
45
+ ##
46
+ # Return fields type:
47
+ # * types(:all) => Return an Array with all field types
48
+ # * types(index) => Return type for fields[index]
49
+ # @param index (Integer)
48
50
  def types(index = :all)
49
51
  @types = (['text'] * @fields.size) if @types.nil?
50
52
  return @types if index == :all
53
+
51
54
  @types[index]
52
55
  end
53
56
 
57
+ ##
58
+ # Set table to simple off
59
+ # * simple_off(:lang) => Set table simple lang FALSE
60
+ # * simple_off(:type) => Set table simple type FALSE
61
+ # @param option (Symbol)
54
62
  def simple_off(option)
55
63
  @simple[option] = false
56
64
  end
57
65
 
58
66
  private
59
67
 
68
+ ##
69
+ # Fill:fields, name and id from XML input
70
+ # @param xml_data (XML)
71
+ # rubocop:disable Metrics/AbcSize
72
+ def read_attributes_from_xml(xml_data)
73
+ # read attributes from XML data
74
+ t = xml_data.attributes['fields'].to_s.strip.split(',')
75
+ t.each(&:strip!)
76
+ @fields = t || []
77
+
78
+ @name = ''
79
+ @fields.each { |i| @name = "#{@name}$#{i.to_s.strip.downcase}" }
80
+ @id = "#{@concept.name}.#{@name}"
81
+
82
+ @sequence = []
83
+ return unless xml_data.attributes['sequence']
84
+
85
+ @sequence = xml_data.attributes['sequence'].to_s.split(',')
86
+ end
87
+ # rubocop:enable Metrics/AbcSize
88
+
89
+ ##
90
+ # Build table data from xml input
91
+ # @param xml_data (XML)
92
+ # rubocop:disable Metrics/MethodLength
93
+ # rubocop:disable Metrics/AbcSize
60
94
  def read_data_from_xml(xml_data)
61
95
  xml_data.elements.each do |i|
62
96
  case i.name
63
97
  when 'lang'
64
- j = i.text.split(',')
65
- codes = @langs.map(&:code)
66
-
67
- if j.join(',') != codes.join(',')
68
- simple_off(:lang)
69
- @langs = []
70
- j.each do |k|
71
- if k.strip == '*' || k.strip == ''
72
- @langs << @concept.lang
73
- else
74
- @langs << LangFactory.instance.get(k.strip.to_s)
75
- end
76
- end
77
- end
98
+ read_lang_from_xml(i)
78
99
  when 'row'
79
100
  @datarows << Row.new(self, @datarows.size, i)
80
101
  when 'sequence'
@@ -82,15 +103,41 @@ class Table
82
103
  when 'template'
83
104
  @datarows += Template.new(self, @datarows.size, i).datarows
84
105
  when 'type'
85
- j = i.text.split(',')
86
- if j.join(',') != @types.join(',')
87
- simple_off(:type)
88
- @types = []
89
- j.each { |k| @types << k.strip.to_s }
90
- end
106
+ read_type_from_xml(i)
91
107
  else
92
108
  puts Rainbow("[ERROR] concept/table#xml_data with #{i.name}").red.bright
93
109
  end
94
110
  end
95
111
  end
112
+ # rubocop:enable Metrics/MethodLength
113
+ # rubocop:enable Metrics/AbcSize
114
+
115
+ # rubocop:disable Metrics/MethodLength
116
+ # rubocop:disable Metrics/AbcSize
117
+ def read_lang_from_xml(xml_data)
118
+ j = xml_data.text.split(',')
119
+ codes = @langs.map(&:code)
120
+ return if j.join(',') == codes.join(',')
121
+
122
+ simple_off(:lang)
123
+ @langs = []
124
+ j.each do |k|
125
+ if ['*', ''].include? k.strip
126
+ @langs << @concept.lang
127
+ else
128
+ @langs << LangFactory.instance.get(k.strip.to_s)
129
+ end
130
+ end
131
+ end
132
+ # rubocop:enable Metrics/MethodLength
133
+ # rubocop:enable Metrics/AbcSize
134
+
135
+ def read_type_from_xml(xml_data)
136
+ j = xml_data.text.split(',')
137
+ return if j.join(',') == @types.join(',')
138
+
139
+ simple_off(:type)
140
+ @types = []
141
+ j.each { |k| @types << k.strip.to_s }
142
+ end
96
143
  end
@@ -1,50 +1,31 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require_relative '../loader/image_url_loader'
3
4
  require_relative '../project'
4
5
  require_relative '../logger'
5
6
 
7
+ ##
8
+ # World data
6
9
  class World
7
10
  attr_reader :concepts, :filenames, :contexts, :image_urls
8
11
 
9
- def initialize(concepts, show_progress=true)
12
+ ##
13
+ # Initialize World object
14
+ # @param concepts (Array)
15
+ # @param show_progress (Boolean)
16
+ def initialize(concepts, show_progress = true)
10
17
  find_neighbors_for_every_concept(concepts)
11
-
12
- @concepts = {}
13
- @filenames = []
14
- @contexts = []
15
- @image_urls = {}
16
-
17
- concepts.each do |c|
18
- if c.process
19
- @concepts[c.name] = c
20
- @filenames << c.filename
21
- @contexts << c.context
22
- end
23
- end
24
- @filenames.uniq!
25
- @contexts.uniq!
26
-
27
- Logger.verbose "\n[INFO] Loading data from Internet" if show_progress
28
- threads = []
29
- concepts.each do |c|
30
- print('.') if show_progress
31
- # puts "[DEBUG] #{c.name}\n"
32
- # filter = [ c.name.clone ] + c.context.clone
33
- filter = c.name.clone
34
- threads << Thread.new { @image_urls[c.name] = ImageUrlLoader::load(filter) }
35
- end
36
- @contexts.each do |filter|
37
- print('.') if show_progress
38
- threads << Thread.new { @image_urls[ filter.join('.').to_s ] = ImageUrlLoader::load(filter) }
39
- end
40
- threads.each { |t| t.join } # wait for all threads to finish
41
- print("\n") if show_progress
18
+ @concepts, @filenames, @contexts = get_lists_from(concepts)
19
+ @image_urls = find_url_images_from_internet(show_progress)
42
20
  end
43
21
 
22
+ ##
23
+ # For every concept... find its neighbors
24
+ # @param concepts (Array)
44
25
  def find_neighbors_for_every_concept(concepts)
45
26
  concepts.each do |i|
46
27
  concepts.each do |j|
47
- if (i.id!=j.id) then
28
+ if i.id != j.id
48
29
  i.try_adding_neighbor(j)
49
30
  i.try_adding_references(j)
50
31
  end
@@ -52,4 +33,47 @@ class World
52
33
  end
53
34
  end
54
35
 
36
+ private
37
+
38
+ # rubocop:disable Metrics/MethodLength
39
+ def get_lists_from(input)
40
+ concepts = {}
41
+ filenames = []
42
+ contexts = []
43
+ input.each do |c|
44
+ next unless c.process
45
+
46
+ concepts[c.name] = c
47
+ filenames << c.filename
48
+ contexts << c.context
49
+ end
50
+ filenames.uniq!
51
+ contexts.uniq!
52
+ [concepts, filenames, contexts]
53
+ end
54
+ # rubocop:enable Metrics/MethodLength
55
+
56
+ # rubocop:disable Metrics/MethodLength
57
+ # rubocop:disable Metrics/AbcSize
58
+ def find_url_images_from_internet(show_progress)
59
+ param = Application.instance.config['global']['internet'] || 'yes'
60
+ return {} unless param == 'yes'
61
+
62
+ Logger.verbose "\n[INFO] Loading data from Internet" if show_progress
63
+ threads = []
64
+ searchs = []
65
+ urls = {}
66
+
67
+ @concepts&.each_key { |key| searchs << key }
68
+ @contexts.each { |filter| searchs << filter.join(' ').to_s }
69
+ searchs.each do |search|
70
+ print('.') if show_progress
71
+ threads << Thread.new { urls[search] = ImageUrlLoader.load(search) }
72
+ end
73
+ threads.each(&:join) # wait for all threads to finish
74
+ print("\n") if show_progress
75
+ urls
76
+ end
77
+ # rubocop:enable Metrics/MethodLength
78
+ # rubocop:enable Metrics/AbcSize
55
79
  end