asker-tool 2.2.0 → 2.2.4
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.
- checksums.yaml +4 -4
 - data/README.md +14 -15
 - data/lib/asker/ai/concept_ai.rb +1 -1
 - data/lib/asker/ai/stages/stage_b.rb +1 -10
 - data/lib/asker/ai/stages/stage_d.rb +4 -10
 - data/lib/asker/ai/stages/stage_f.rb +1 -20
 - data/lib/asker/application.rb +6 -16
 - data/lib/asker/check_input/check_haml_data.rb +264 -0
 - data/lib/asker/check_input/check_table.rb +104 -0
 - data/lib/asker/check_input.rb +51 -0
 - data/lib/asker/cli.rb +32 -47
 - data/lib/asker/data/code.rb +1 -15
 - data/lib/asker/data/concept.rb +8 -7
 - data/lib/asker/{project.rb → data/project_data.rb} +5 -23
 - data/lib/asker/data/world.rb +4 -15
 - data/lib/asker/displayer/concept_ai_displayer.rb +1 -0
 - data/lib/asker/exporter/concept_ai_moodle_exporter.rb +3 -2
 - data/lib/asker/exporter/concept_doc_exporter.rb +3 -6
 - data/lib/asker/exporter/data_gift_exporter.rb +4 -2
 - data/lib/asker/files/language/en/templates.yaml +1 -1
 - data/lib/asker/files/language/es/templates.yaml +1 -1
 - data/lib/asker/formatter/concept_doc_formatter.rb +0 -4
 - data/lib/asker/loader/content_loader.rb +8 -10
 - data/lib/asker/loader/directory_loader.rb +1 -8
 - data/lib/asker/loader/file_loader.rb +1 -6
 - data/lib/asker/loader/haml_loader.rb +9 -5
 - data/lib/asker/loader/image_url_loader.rb +4 -6
 - data/lib/asker/loader/input_loader.rb +5 -6
 - data/lib/asker/loader/project_loader.rb +7 -8
 - data/lib/asker/logger.rb +17 -15
 - data/lib/asker/skeleton.rb +3 -3
 - data/lib/asker/version.rb +9 -0
 - data/lib/asker.rb +39 -38
 - metadata +52 -7
 - data/lib/asker/checker.rb +0 -453
 
    
        data/lib/asker/cli.rb
    CHANGED
    
    | 
         @@ -2,24 +2,49 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'rainbow'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'thor'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative ' 
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative 'version'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require_relative '../asker'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            ##
         
     | 
| 
       9 
9 
     | 
    
         
             
            # Command Line User Interface
         
     | 
| 
       10 
10 
     | 
    
         
             
            class CLI < Thor
         
     | 
| 
       11 
     | 
    
         
            -
              map [' 
     | 
| 
      
 11 
     | 
    
         
            +
              map ['--help'] => 'help'
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              map [' 
     | 
| 
      
 13 
     | 
    
         
            +
              map ['--version'] => 'version'
         
     | 
| 
       14 
14 
     | 
    
         
             
              desc 'version', 'Show the program version'
         
     | 
| 
       15 
     | 
    
         
            -
              ##
         
     | 
| 
       16 
     | 
    
         
            -
              # Show current version
         
     | 
| 
       17 
15 
     | 
    
         
             
              def version
         
     | 
| 
       18 
     | 
    
         
            -
                puts "#{ 
     | 
| 
      
 16 
     | 
    
         
            +
                puts "#{Version::NAME} version #{Version::VERSION}"
         
     | 
| 
      
 17 
     | 
    
         
            +
                exit 0
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              map ['--init'] => 'init'
         
     | 
| 
      
 21 
     | 
    
         
            +
              desc 'init', 'Create default INI config file'
         
     | 
| 
      
 22 
     | 
    
         
            +
              def init
         
     | 
| 
      
 23 
     | 
    
         
            +
                Asker.init
         
     | 
| 
      
 24 
     | 
    
         
            +
                exit 0
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              map ['new','--new'] => 'new_input'
         
     | 
| 
      
 28 
     | 
    
         
            +
              desc 'new DIRPATH', 'Create Asker demo input files'
         
     | 
| 
      
 29 
     | 
    
         
            +
              ##
         
     | 
| 
      
 30 
     | 
    
         
            +
              # Create Asker demo input files
         
     | 
| 
      
 31 
     | 
    
         
            +
              # @param dirname (String) Path to folder
         
     | 
| 
      
 32 
     | 
    
         
            +
              def new_input(dirname)
         
     | 
| 
      
 33 
     | 
    
         
            +
                Asker.new_input(dirname)
         
     | 
| 
      
 34 
     | 
    
         
            +
                exit 0
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              map ['--check'] => 'check'
         
     | 
| 
      
 38 
     | 
    
         
            +
              desc 'check FILEPATH', 'Check input HAML file syntax'
         
     | 
| 
      
 39 
     | 
    
         
            +
              def check(filename)
         
     | 
| 
      
 40 
     | 
    
         
            +
                # Enable/disable color output
         
     | 
| 
      
 41 
     | 
    
         
            +
                Rainbow.enabled = false if options['color'] == false
         
     | 
| 
      
 42 
     | 
    
         
            +
                # Asker start processing input file
         
     | 
| 
      
 43 
     | 
    
         
            +
                Asker.check(filename)
         
     | 
| 
       19 
44 
     | 
    
         
             
              end
         
     | 
| 
       20 
45 
     | 
    
         | 
| 
       21 
46 
     | 
    
         
             
              map ['f', '-f', '--file'] => 'file'
         
     | 
| 
       22 
     | 
    
         
            -
              desc 'file  
     | 
| 
      
 47 
     | 
    
         
            +
              desc '[file] FILEPATH', 'Build output files, from HAML/XML input file.'
         
     | 
| 
       23 
48 
     | 
    
         
             
              long_desc <<-LONGDESC
         
     | 
| 
       24 
49 
     | 
    
         | 
| 
       25 
50 
     | 
    
         
             
              Build questions about contents defined into input file specified.
         
     | 
| 
         @@ -35,51 +60,11 @@ class CLI < Thor 
     | 
|
| 
       35 
60 
     | 
    
         
             
              (3) #{Rainbow('asker projects/foo/foo.yaml').aqua}, Build questions from YAML project file.
         
     | 
| 
       36 
61 
     | 
    
         | 
| 
       37 
62 
     | 
    
         
             
              LONGDESC
         
     | 
| 
       38 
     | 
    
         
            -
              ##
         
     | 
| 
       39 
     | 
    
         
            -
              # Create questions from input file
         
     | 
| 
       40 
     | 
    
         
            -
              # @param filename (String) Path to input file
         
     | 
| 
       41 
63 
     | 
    
         
             
              def file(filename)
         
     | 
| 
       42 
64 
     | 
    
         
             
                # Asker start processing input file
         
     | 
| 
       43 
65 
     | 
    
         
             
                Asker.start(filename)
         
     | 
| 
       44 
66 
     | 
    
         
             
              end
         
     | 
| 
       45 
67 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
              map ['c', '-c', '--check'] => 'check'
         
     | 
| 
       47 
     | 
    
         
            -
              desc 'check', 'Check input HAML file syntax'
         
     | 
| 
       48 
     | 
    
         
            -
              ##
         
     | 
| 
       49 
     | 
    
         
            -
              # Check input file syntax
         
     | 
| 
       50 
     | 
    
         
            -
              # @param filename (String) Path to input file
         
     | 
| 
       51 
     | 
    
         
            -
              def check(filename)
         
     | 
| 
       52 
     | 
    
         
            -
                # Enable/disable color output
         
     | 
| 
       53 
     | 
    
         
            -
                Rainbow.enabled = false if options['color'] == false
         
     | 
| 
       54 
     | 
    
         
            -
                # Asker start processing input file
         
     | 
| 
       55 
     | 
    
         
            -
                Asker.check(filename)
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
              map ['h', '-h', '--homepage', 'homepage'] => 'show_homepage'
         
     | 
| 
       59 
     | 
    
         
            -
              desc 'homepage', 'Documentation homepage'
         
     | 
| 
       60 
     | 
    
         
            -
              ##
         
     | 
| 
       61 
     | 
    
         
            -
              # Show documentation homepage
         
     | 
| 
       62 
     | 
    
         
            -
              def show_homepage()
         
     | 
| 
       63 
     | 
    
         
            -
                puts Application::HOMEPAGE
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
              map ['i', '-i', '--init'] => 'init'
         
     | 
| 
       67 
     | 
    
         
            -
              desc 'init', 'Create default INI config file'
         
     | 
| 
       68 
     | 
    
         
            -
              ##
         
     | 
| 
       69 
     | 
    
         
            -
              # Create default INI config file
         
     | 
| 
       70 
     | 
    
         
            -
              def init
         
     | 
| 
       71 
     | 
    
         
            -
                Asker.create_configuration
         
     | 
| 
       72 
     | 
    
         
            -
              end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
              map ['n', '-n', '--new', 'new'] => 'create_input'
         
     | 
| 
       75 
     | 
    
         
            -
              desc 'new [FOLDER]', 'Create Asker demo input files'
         
     | 
| 
       76 
     | 
    
         
            -
              ##
         
     | 
| 
       77 
     | 
    
         
            -
              # Create Asker demo input files
         
     | 
| 
       78 
     | 
    
         
            -
              # @param dirname (String) Path to folder
         
     | 
| 
       79 
     | 
    
         
            -
              def create_input(dirname)
         
     | 
| 
       80 
     | 
    
         
            -
                Asker.create_input(dirname)
         
     | 
| 
       81 
     | 
    
         
            -
              end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
68 
     | 
    
         
             
              ##
         
     | 
| 
       84 
69 
     | 
    
         
             
              # This actions are equals:
         
     | 
| 
       85 
70 
     | 
    
         
             
              # * asker demo/foo.haml
         
     | 
    
        data/lib/asker/data/code.rb
    CHANGED
    
    | 
         @@ -1,22 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative '../ai/code/code_ai_factory'
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative '../project'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       6 
     | 
    
         
            -
            require_relative '../formatter/code_string_formatter'
         
     | 
| 
       7 
4 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            ##
         
     | 
| 
       9 
     | 
    
         
            -
            # Code data object
         
     | 
| 
       10 
5 
     | 
    
         
             
            class Code
         
     | 
| 
       11 
6 
     | 
    
         
             
              attr_reader :dirname, :filename, :type
         
     | 
| 
       12 
7 
     | 
    
         
             
              attr_accessor :process, :features
         
     | 
| 
       13 
8 
     | 
    
         
             
              attr_reader :lines, :questions
         
     | 
| 
       14 
9 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              ##
         
     | 
| 
       16 
     | 
    
         
            -
              # Initialize Code object
         
     | 
| 
       17 
     | 
    
         
            -
              # @param dirname (String)
         
     | 
| 
       18 
     | 
    
         
            -
              # @param filename (String)
         
     | 
| 
       19 
     | 
    
         
            -
              # @param type (String)
         
     | 
| 
       20 
10 
     | 
    
         
             
              def initialize(dirname, filename, type)
         
     | 
| 
       21 
11 
     | 
    
         
             
                @dirname = dirname
         
     | 
| 
       22 
12 
     | 
    
         
             
                @filename = filename
         
     | 
| 
         @@ -40,17 +30,13 @@ class Code 
     | 
|
| 
       40 
30 
     | 
    
         
             
                out
         
     | 
| 
       41 
31 
     | 
    
         
             
              end
         
     | 
| 
       42 
32 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
              def debug
         
     | 
| 
       44 
     | 
    
         
            -
                Logger.verbose CodeStringFormatter.to_s(self)
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
33 
     | 
    
         
             
              private
         
     | 
| 
       48 
34 
     | 
    
         | 
| 
       49 
35 
     | 
    
         
             
              def load(filepath)
         
     | 
| 
       50 
36 
     | 
    
         
             
                return if filepath.nil?
         
     | 
| 
       51 
37 
     | 
    
         | 
| 
       52 
38 
     | 
    
         
             
                unless File.exist? filepath
         
     | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
      
 39 
     | 
    
         
            +
                  puts Rainbow("[ERROR] Unkown file #{filepath}").red.bright
         
     | 
| 
       54 
40 
     | 
    
         
             
                  return
         
     | 
| 
       55 
41 
     | 
    
         
             
                end
         
     | 
| 
       56 
42 
     | 
    
         
             
                content = File.read(filepath)
         
     | 
    
        data/lib/asker/data/concept.rb
    CHANGED
    
    | 
         @@ -3,8 +3,6 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'rainbow'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'rexml/document'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            require_relative '../application'
         
     | 
| 
       7 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       8 
6 
     | 
    
         
             
            require_relative '../lang/lang_factory'
         
     | 
| 
       9 
7 
     | 
    
         
             
            require_relative '../loader/embedded_file'
         
     | 
| 
       10 
8 
     | 
    
         
             
            require_relative 'table'
         
     | 
| 
         @@ -24,7 +22,7 @@ class Concept 
     | 
|
| 
       24 
22 
     | 
    
         
             
              attr_reader :data      # Data about this concept
         
     | 
| 
       25 
23 
     | 
    
         
             
              attr_accessor :process # (Boolean) if it is necesary generate questions
         
     | 
| 
       26 
24 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              @@id = 0 # Global Concept counter
         
     | 
| 
      
 25 
     | 
    
         
            +
              @@id = 0 # Global Concept counter (concept identifier)
         
     | 
| 
       28 
26 
     | 
    
         | 
| 
       29 
27 
     | 
    
         
             
              ##
         
     | 
| 
       30 
28 
     | 
    
         
             
              # Initilize Concept
         
     | 
| 
         @@ -93,7 +91,8 @@ class Concept 
     | 
|
| 
       93 
91 
     | 
    
         
             
              # rubocop:disable Metrics/AbcSize
         
     | 
| 
       94 
92 
     | 
    
         
             
              # rubocop:disable Metrics/CyclomaticComplexity
         
     | 
| 
       95 
93 
     | 
    
         
             
              def calculate_nearness_to_concept(other)
         
     | 
| 
       96 
     | 
    
         
            -
                a =  
     | 
| 
      
 94 
     | 
    
         
            +
                a = ProjectData.instance.get(:weights)
         
     | 
| 
      
 95 
     | 
    
         
            +
                #Application.instance.config['ai']['formula_weights']
         
     | 
| 
       97 
96 
     | 
    
         
             
                weights = a.split(',').map(&:to_f)
         
     | 
| 
       98 
97 
     | 
    
         | 
| 
       99 
98 
     | 
    
         
             
                max1 = @context.count
         
     | 
| 
         @@ -180,7 +179,7 @@ class Concept 
     | 
|
| 
       180 
179 
     | 
    
         
             
                    @data[:tables] << Table.new(self, i)
         
     | 
| 
       181 
180 
     | 
    
         
             
                  else
         
     | 
| 
       182 
181 
     | 
    
         
             
                    text = "   [ERROR] Concept #{name} with unkown attribute: #{i.name}"
         
     | 
| 
       183 
     | 
    
         
            -
                     
     | 
| 
      
 182 
     | 
    
         
            +
                    puts Rainbow(text).color(:red)
         
     | 
| 
       184 
183 
     | 
    
         
             
                  end
         
     | 
| 
       185 
184 
     | 
    
         
             
                end
         
     | 
| 
       186 
185 
     | 
    
         
             
              end
         
     | 
| 
         @@ -195,7 +194,7 @@ class Concept 
     | 
|
| 
       195 
194 
     | 
    
         | 
| 
       196 
195 
     | 
    
         
             
              def process_tags(value)
         
     | 
| 
       197 
196 
     | 
    
         
             
                if value.text.nil? || value.text.size.zero?
         
     | 
| 
       198 
     | 
    
         
            -
                   
     | 
| 
      
 197 
     | 
    
         
            +
                  puts Rainbow("[ERROR] Concept #{name} has tags empty!").red.briht
         
     | 
| 
       199 
198 
     | 
    
         
             
                  exit 1
         
     | 
| 
       200 
199 
     | 
    
         
             
                end
         
     | 
| 
       201 
200 
     | 
    
         | 
| 
         @@ -208,14 +207,16 @@ class Concept 
     | 
|
| 
       208 
207 
     | 
    
         
             
              def process_def(value)
         
     | 
| 
       209 
208 
     | 
    
         
             
                case value.attributes['type']
         
     | 
| 
       210 
209 
     | 
    
         
             
                when 'image_url'
         
     | 
| 
      
 210 
     | 
    
         
            +
                  # Link with remote image
         
     | 
| 
       211 
211 
     | 
    
         
             
                  @data[:images] << EmbeddedFile.load(value.text.strip, File.dirname(@filename))
         
     | 
| 
       212 
212 
     | 
    
         
             
                when 'file'
         
     | 
| 
      
 213 
     | 
    
         
            +
                  # Load local images and text files
         
     | 
| 
       213 
214 
     | 
    
         
             
                  @data[:images] << EmbeddedFile.load(value.text.strip, File.dirname(@filename))
         
     | 
| 
       214 
215 
     | 
    
         
             
                when nil
         
     | 
| 
       215 
216 
     | 
    
         
             
                  @data[:texts] << value.text.strip
         
     | 
| 
       216 
217 
     | 
    
         
             
                else
         
     | 
| 
       217 
218 
     | 
    
         
             
                  msg = "[ERROR] Unknown type: #{value.attributes['type']}"
         
     | 
| 
       218 
     | 
    
         
            -
                   
     | 
| 
      
 219 
     | 
    
         
            +
                  puts Rainbow(msg).red.bright
         
     | 
| 
       219 
220 
     | 
    
         
             
                  exit 1
         
     | 
| 
       220 
221 
     | 
    
         
             
                end
         
     | 
| 
       221 
222 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,43 +1,30 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'singleton'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'rainbow'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative 'application'
         
     | 
| 
       6 
     | 
    
         
            -
            require_relative 'logger'
         
     | 
| 
       7 
4 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            class Project
         
     | 
| 
      
 5 
     | 
    
         
            +
            class ProjectData
         
     | 
| 
       10 
6 
     | 
    
         
             
              include Singleton
         
     | 
| 
       11 
7 
     | 
    
         
             
              attr_reader :default, :param
         
     | 
| 
       12 
8 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              ##
         
     | 
| 
       14 
     | 
    
         
            -
              # Initialize
         
     | 
| 
       15 
9 
     | 
    
         
             
              def initialize
         
     | 
| 
       16 
10 
     | 
    
         
             
                reset
         
     | 
| 
       17 
11 
     | 
    
         
             
              end
         
     | 
| 
       18 
12 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              ##
         
     | 
| 
       20 
     | 
    
         
            -
              # Reset project params
         
     | 
| 
       21 
13 
     | 
    
         
             
              def reset
         
     | 
| 
       22 
14 
     | 
    
         
             
                @default = { inputbasedir: FileUtils.pwd,
         
     | 
| 
       23 
15 
     | 
    
         
             
                             stages: { d: true, b: true, f: true, i: true, s: true, t: true },
         
     | 
| 
       24 
     | 
    
         
            -
                             threshold: 0.5 
     | 
| 
      
 16 
     | 
    
         
            +
                             threshold: 0.5,
         
     | 
| 
      
 17 
     | 
    
         
            +
                             outputdir: 'output',
         
     | 
| 
      
 18 
     | 
    
         
            +
                             weights: '1, 1, 1' }
         
     | 
| 
       25 
19 
     | 
    
         
             
                @param = {}
         
     | 
| 
       26 
20 
     | 
    
         
             
              end
         
     | 
| 
       27 
21 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
              ##
         
     | 
| 
       29 
     | 
    
         
            -
              # Get value param
         
     | 
| 
       30 
     | 
    
         
            -
              # @param key (Symbol) key
         
     | 
| 
       31 
22 
     | 
    
         
             
              def get(key)
         
     | 
| 
       32 
23 
     | 
    
         
             
                return @param[key] unless @param[key].nil?
         
     | 
| 
       33 
24 
     | 
    
         | 
| 
       34 
25 
     | 
    
         
             
                @default[key]
         
     | 
| 
       35 
26 
     | 
    
         
             
              end
         
     | 
| 
       36 
27 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
              ##
         
     | 
| 
       38 
     | 
    
         
            -
              # Set value param
         
     | 
| 
       39 
     | 
    
         
            -
              # @param key (Symbol) key
         
     | 
| 
       40 
     | 
    
         
            -
              # @param value (String) value
         
     | 
| 
       41 
28 
     | 
    
         
             
              def set(key, value)
         
     | 
| 
       42 
29 
     | 
    
         
             
                @param[key] = value
         
     | 
| 
       43 
30 
     | 
    
         
             
              end
         
     | 
| 
         @@ -52,7 +39,6 @@ class Project 
     | 
|
| 
       52 
39 
     | 
    
         
             
              # rubocop:disable Metrics/MethodLength
         
     | 
| 
       53 
40 
     | 
    
         
             
              # rubocop:disable Metrics/AbcSize
         
     | 
| 
       54 
41 
     | 
    
         
             
              def open
         
     | 
| 
       55 
     | 
    
         
            -
                config = Application.instance.config
         
     | 
| 
       56 
42 
     | 
    
         
             
                ext = File.extname(@param[:process_file]) || '.haml'
         
     | 
| 
       57 
43 
     | 
    
         
             
                @param[:projectname] = @param[:projectname] ||
         
     | 
| 
       58 
44 
     | 
    
         
             
                                       File.basename(@param[:process_file], ext)
         
     | 
| 
         @@ -63,7 +49,7 @@ class Project 
     | 
|
| 
       63 
49 
     | 
    
         
             
                @param[:yamlname] = "#{@param[:projectname]}.yaml"
         
     | 
| 
       64 
50 
     | 
    
         
             
                @param[:moodlename] = "#{@param[:projectname]}-moodle.xml"
         
     | 
| 
       65 
51 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                outputdir =  
     | 
| 
      
 52 
     | 
    
         
            +
                outputdir = get(:outputdir)
         
     | 
| 
       67 
53 
     | 
    
         
             
                @param[:logpath] = File.join(outputdir, get(:logname))
         
     | 
| 
       68 
54 
     | 
    
         
             
                @param[:outputpath] = File.join(outputdir, get(:outputname))
         
     | 
| 
       69 
55 
     | 
    
         
             
                @param[:lessonpath] = File.join(outputdir, get(:lessonname))
         
     | 
| 
         @@ -71,10 +57,6 @@ class Project 
     | 
|
| 
       71 
57 
     | 
    
         
             
                @param[:moodlepath] = File.join(outputdir, get(:moodlename))
         
     | 
| 
       72 
58 
     | 
    
         | 
| 
       73 
59 
     | 
    
         
             
                Dir.mkdir(outputdir) unless Dir.exist?(outputdir)
         
     | 
| 
       74 
     | 
    
         
            -
                Logger.create(self) # Create log file where to save log messages
         
     | 
| 
       75 
     | 
    
         
            -
                Logger.verboseln '[INFO] Project open'
         
     | 
| 
       76 
     | 
    
         
            -
                Logger.verboseln '   ├── inputdirs    = ' + Rainbow(get(:inputdirs)).bright
         
     | 
| 
       77 
     | 
    
         
            -
                Logger.verboseln '   └── process_file = ' + Rainbow(get(:process_file)).bright
         
     | 
| 
       78 
60 
     | 
    
         
             
              end
         
     | 
| 
       79 
61 
     | 
    
         
             
              # rubocop:enable Metrics/MethodLength
         
     | 
| 
       80 
62 
     | 
    
         
             
              # rubocop:enable Metrics/AbcSize
         
     | 
    
        data/lib/asker/data/world.rb
    CHANGED
    
    | 
         @@ -1,22 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative '../loader/image_url_loader'
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative '../project'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       6 
4 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            ##
         
     | 
| 
       8 
     | 
    
         
            -
            # World data
         
     | 
| 
       9 
5 
     | 
    
         
             
            class World
         
     | 
| 
       10 
6 
     | 
    
         
             
              attr_reader :concepts, :filenames, :contexts, :image_urls
         
     | 
| 
       11 
7 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
               
     | 
| 
       13 
     | 
    
         
            -
              # Initialize World object
         
     | 
| 
       14 
     | 
    
         
            -
              # @param concepts (Array)
         
     | 
| 
       15 
     | 
    
         
            -
              # @param show_progress (Boolean)
         
     | 
| 
       16 
     | 
    
         
            -
              def initialize(concepts, show_progress = true)
         
     | 
| 
      
 8 
     | 
    
         
            +
              def initialize(concepts, internet = true)
         
     | 
| 
       17 
9 
     | 
    
         
             
                find_neighbors_for_every_concept(concepts)
         
     | 
| 
       18 
10 
     | 
    
         
             
                @concepts, @filenames, @contexts = get_lists_from(concepts)
         
     | 
| 
       19 
     | 
    
         
            -
                @image_urls = find_url_images_from_internet( 
     | 
| 
      
 11 
     | 
    
         
            +
                @image_urls = find_url_images_from_internet(internet)
         
     | 
| 
       20 
12 
     | 
    
         
             
              end
         
     | 
| 
       21 
13 
     | 
    
         | 
| 
       22 
14 
     | 
    
         
             
              ##
         
     | 
| 
         @@ -57,10 +49,9 @@ class World 
     | 
|
| 
       57 
49 
     | 
    
         
             
              # rubocop:disable Metrics/AbcSize
         
     | 
| 
       58 
50 
     | 
    
         
             
              # rubocop:disable Metrics/CyclomaticComplexity
         
     | 
| 
       59 
51 
     | 
    
         
             
              # rubocop:disable Metrics/PerceivedComplexity
         
     | 
| 
       60 
     | 
    
         
            -
              def find_url_images_from_internet( 
     | 
| 
       61 
     | 
    
         
            -
                return {} unless  
     | 
| 
      
 52 
     | 
    
         
            +
              def find_url_images_from_internet(internet)
         
     | 
| 
      
 53 
     | 
    
         
            +
                return {} unless internet
         
     | 
| 
       62 
54 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                Logger.verbose "\n[INFO] Loading data from Internet" if show_progress
         
     | 
| 
       64 
55 
     | 
    
         
             
                threads = []
         
     | 
| 
       65 
56 
     | 
    
         
             
                searchs = []
         
     | 
| 
       66 
57 
     | 
    
         
             
                urls = {}
         
     | 
| 
         @@ -68,11 +59,9 @@ class World 
     | 
|
| 
       68 
59 
     | 
    
         
             
                @concepts&.each_key { |key| searchs << key }
         
     | 
| 
       69 
60 
     | 
    
         
             
                @contexts.each { |filter| searchs << filter.join(' ').to_s }
         
     | 
| 
       70 
61 
     | 
    
         
             
                searchs.each do |search|
         
     | 
| 
       71 
     | 
    
         
            -
                  Logger.verbose('.') if show_progress
         
     | 
| 
       72 
62 
     | 
    
         
             
                  threads << Thread.new { urls[search] = ImageUrlLoader.load(search) }
         
     | 
| 
       73 
63 
     | 
    
         
             
                end
         
     | 
| 
       74 
64 
     | 
    
         
             
                threads.each(&:join) # wait for all threads to finish
         
     | 
| 
       75 
     | 
    
         
            -
                Logger.verbose("\n") if show_progress
         
     | 
| 
       76 
65 
     | 
    
         
             
                urls
         
     | 
| 
       77 
66 
     | 
    
         
             
              end
         
     | 
| 
       78 
67 
     | 
    
         
             
              # rubocop:enable Metrics/MethodLength
         
     | 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative '../formatter/question_moodle_formatter'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../version'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            # Export ConceptIA data to gift to moodlefile
         
     | 
| 
       6 
7 
     | 
    
         
             
            module ConceptAIMoodleExporter
         
     | 
| 
         @@ -13,8 +14,8 @@ module ConceptAIMoodleExporter 
     | 
|
| 
       13 
14 
     | 
    
         
             
                file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
         
     | 
| 
       14 
15 
     | 
    
         
             
                file.write("<quiz>\n")
         
     | 
| 
       15 
16 
     | 
    
         
             
                file.write("<!--\n#{('=' * 50)}\n")
         
     | 
| 
       16 
     | 
    
         
            -
                file.write(" Created by : #{ 
     | 
| 
       17 
     | 
    
         
            -
                file.write(" (version #{ 
     | 
| 
      
 17 
     | 
    
         
            +
                file.write(" Created by : #{Version::NAME}")
         
     | 
| 
      
 18 
     | 
    
         
            +
                file.write(" (version #{Version::VERSION})\n")
         
     | 
| 
       18 
19 
     | 
    
         
             
                file.write(" File       : #{project.get(:moodlename)}\n")
         
     | 
| 
       19 
20 
     | 
    
         
             
                file.write(" Time       : #{Time.new}\n")
         
     | 
| 
       20 
21 
     | 
    
         
             
                file.write(" Author     : David Vargas Ruiz\n")
         
     | 
| 
         @@ -1,18 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative '../formatter/concept_doc_formatter'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../version'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            ##
         
     | 
| 
       6 
7 
     | 
    
         
             
            # Export Concept to Doc file
         
     | 
| 
       7 
8 
     | 
    
         
             
            module ConceptDocExporter
         
     | 
| 
       8 
9 
     | 
    
         
             
              ##
         
     | 
| 
       9 
     | 
    
         
            -
              # Export  
     | 
| 
       10 
     | 
    
         
            -
              # rubocop:disable Metrics/AbcSize
         
     | 
| 
       11 
     | 
    
         
            -
              # rubocop:disable Metrics/MethodLength
         
     | 
| 
      
 10 
     | 
    
         
            +
              # Export array of concepts to doc
         
     | 
| 
       12 
11 
     | 
    
         
             
              def self.export_all(concepts, project)
         
     | 
| 
       13 
12 
     | 
    
         
             
                file = File.new(project.get(:lessonpath), 'w')
         
     | 
| 
       14 
13 
     | 
    
         
             
                file.write('=' * 50 + "\n")
         
     | 
| 
       15 
     | 
    
         
            -
                file.write("Created by : #{ 
     | 
| 
      
 14 
     | 
    
         
            +
                file.write("Created by : #{Version::NAME} (version #{Version::VERSION})\n")
         
     | 
| 
       16 
15 
     | 
    
         
             
                file.write("File       : #{project.get(:lessonname)}\n")
         
     | 
| 
       17 
16 
     | 
    
         
             
                file.write("Time       : #{Time.new}\n")
         
     | 
| 
       18 
17 
     | 
    
         
             
                file.write("Author     : David Vargas Ruiz\n")
         
     | 
| 
         @@ -23,6 +22,4 @@ module ConceptDocExporter 
     | 
|
| 
       23 
22 
     | 
    
         
             
                end
         
     | 
| 
       24 
23 
     | 
    
         
             
                file.close
         
     | 
| 
       25 
24 
     | 
    
         
             
              end
         
     | 
| 
       26 
     | 
    
         
            -
              # rubocop:enable Metrics/AbcSize
         
     | 
| 
       27 
     | 
    
         
            -
              # rubocop:enable Metrics/MethodLength
         
     | 
| 
       28 
25 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,6 +2,8 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'concept_ai_gift_exporter'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require_relative 'code_gift_exporter'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative '../version'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative '../application'
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
8 
     | 
    
         
             
            # Export Data (ConceptIA and Code) to gift to outputfile
         
     | 
| 
       7 
9 
     | 
    
         
             
            module DataGiftExporter
         
     | 
| 
         @@ -12,8 +14,8 @@ module DataGiftExporter 
     | 
|
| 
       12 
14 
     | 
    
         
             
              def self.export_all(data, project)
         
     | 
| 
       13 
15 
     | 
    
         
             
                file = File.open(project.get(:outputpath), 'w')
         
     | 
| 
       14 
16 
     | 
    
         
             
                file.write('// ' + ('=' * 50) + "\n")
         
     | 
| 
       15 
     | 
    
         
            -
                file.write("// Created by : #{ 
     | 
| 
       16 
     | 
    
         
            -
                file.write(" (version #{ 
     | 
| 
      
 17 
     | 
    
         
            +
                file.write("// Created by : #{Version::NAME}")
         
     | 
| 
      
 18 
     | 
    
         
            +
                file.write(" (version #{Version::VERSION})\n")
         
     | 
| 
       17 
19 
     | 
    
         
             
                file.write("// File       : #{project.get(:outputname)}\n")
         
     | 
| 
       18 
20 
     | 
    
         
             
                file.write("// Time       : #{Time.new}\n")
         
     | 
| 
       19 
21 
     | 
    
         
             
                file.write("// Author     : David Vargas Ruiz\n")
         
     | 
| 
         @@ -13,7 +13,7 @@ 
     | 
|
| 
       13 
13 
     | 
    
         
             
            :f2: 'The next items are "<%=text2%>".<br/>Choose the option that not belongs concept <b><%=text1%></b>.'
         
     | 
| 
       14 
14 
     | 
    
         
             
            :f3: 'The next items are "<%=text2%>" from <b><%=text1%></b> concept:<br><p><%=text3%></p>(Put every word into the right position)'
         
     | 
| 
       15 
15 
     | 
    
         
             
            :i1: '<%=text1%><br/>Choose the best association for the previous image.<br/>'
         
     | 
| 
       16 
     | 
    
         
            -
            :i2: '<%=text1%><br/>The previous image corresponds to <b><%=text2%></b>.'
         
     | 
| 
      
 16 
     | 
    
         
            +
            :i2: '<%=text1%><br/>The previous image/text corresponds to <b><%=text2%></b>.'
         
     | 
| 
       17 
17 
     | 
    
         
             
            :i3: '<%=text1%><br/>Write the best answer <%=text2%>, for the previous image.<br/>'
         
     | 
| 
       18 
18 
     | 
    
         
             
            :i4: '<%=text1%><br/>Definition:<br/> <i><%=text2%></i><br/><br/>(Put every word in the right text position)'
         
     | 
| 
       19 
19 
     | 
    
         
             
            :s1: "About <b><%=text1%></b> concept, sort every \"<%=text2%>\", so It is true that \"<%=text3%>\".<br/>"
         
     | 
| 
         @@ -13,7 +13,7 @@ 
     | 
|
| 
       13 
13 
     | 
    
         
             
            :f2: 'Los siguientes elementos son "<%=text2%>".<br/>Selecciona la opción que no pertenezca al concepto <b><%=text1%></b>.'
         
     | 
| 
       14 
14 
     | 
    
         
             
            :f3: 'Los siguientes elementos son "<%=text2%>" del concepto <b><%=text1%></b>:<br><p><%=text3%></p>(Coloca cada palabra en su posición correcta dentro del texto)'
         
     | 
| 
       15 
15 
     | 
    
         
             
            :i1: '<%=text1%><br/>Elige la opción que mejor se corresponda con la imagen anterior.<br/>'
         
     | 
| 
       16 
     | 
    
         
            -
            :i2: '<%=text1%><br/>La imagen anterior corresponde a <b><%=text2%></b>.'
         
     | 
| 
      
 16 
     | 
    
         
            +
            :i2: '<%=text1%><br/>La imagen/texto anterior corresponde a <b><%=text2%></b>.'
         
     | 
| 
       17 
17 
     | 
    
         
             
            :i3: '<%=text1%><br/>Escribe la opción <%=text2%>, que mejor corresponda con la imagen anterior.<br/>'
         
     | 
| 
       18 
18 
     | 
    
         
             
            :i4: '<%=text1%><br/>Definición: <i><%=text2%></i><br/><br/>(Coloca cada palabra en su posición correcta dentro del texto)'
         
     | 
| 
       19 
19 
     | 
    
         
             
            :s1: 'En relación al concepto <b><%=text1%></b>, ordena cada/las/los "<%=text2%>" de modo que se cumpla el criterio "<%=text3%>".<br/>'
         
     | 
| 
         @@ -4,8 +4,7 @@ require 'rainbow' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'rexml/document'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require_relative '../data/concept'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require_relative 'code_loader'
         
     | 
| 
       7 
     | 
    
         
            -
            require_relative '../ 
     | 
| 
       8 
     | 
    
         
            -
            require_relative '../project'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative '../data/project_data'
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
9 
     | 
    
         
             
            # Define methods that load data from XML contents
         
     | 
| 
       11 
10 
     | 
    
         
             
            module ContentLoader
         
     | 
| 
         @@ -13,8 +12,6 @@ module ContentLoader 
     | 
|
| 
       13 
12 
     | 
    
         
             
              # Load XML content into Asker data objects
         
     | 
| 
       14 
13 
     | 
    
         
             
              # @param filepath (String) File path
         
     | 
| 
       15 
14 
     | 
    
         
             
              # @param content (String) XML plane text content
         
     | 
| 
       16 
     | 
    
         
            -
              # rubocop:disable Metrics/MethodLength
         
     | 
| 
       17 
     | 
    
         
            -
              # rubocop:disable Metrics/AbcSize
         
     | 
| 
       18 
15 
     | 
    
         
             
              def self.load(filepath, content)
         
     | 
| 
       19 
16 
     | 
    
         
             
                concepts = []
         
     | 
| 
       20 
17 
     | 
    
         
             
                codes = []
         
     | 
| 
         @@ -33,7 +30,7 @@ module ContentLoader 
     | 
|
| 
       33 
30 
     | 
    
         
             
                  when 'code'
         
     | 
| 
       34 
31 
     | 
    
         
             
                    codes << read_code(xmldata, filepath)
         
     | 
| 
       35 
32 
     | 
    
         
             
                  else
         
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
      
 33 
     | 
    
         
            +
                    puts Rainbow("[ERROR] Unkown tag <#{xmldata.name}>").red
         
     | 
| 
       37 
34 
     | 
    
         
             
                  end
         
     | 
| 
       38 
35 
     | 
    
         
             
                end
         
     | 
| 
       39 
36 
     | 
    
         | 
| 
         @@ -49,7 +46,7 @@ module ContentLoader 
     | 
|
| 
       49 
46 
     | 
    
         
             
                begin
         
     | 
| 
       50 
47 
     | 
    
         
             
                  lang = xmldata.root.attributes['lang']
         
     | 
| 
       51 
48 
     | 
    
         
             
                rescue StandardError
         
     | 
| 
       52 
     | 
    
         
            -
                  lang =  
     | 
| 
      
 49 
     | 
    
         
            +
                  lang = ProjectData.instance.lang
         
     | 
| 
       53 
50 
     | 
    
         
             
                end
         
     | 
| 
       54 
51 
     | 
    
         
             
                lang
         
     | 
| 
       55 
52 
     | 
    
         
             
              end
         
     | 
| 
         @@ -73,7 +70,7 @@ module ContentLoader 
     | 
|
| 
       73 
70 
     | 
    
         
             
              # @param lang
         
     | 
| 
       74 
71 
     | 
    
         
             
              # @param context
         
     | 
| 
       75 
72 
     | 
    
         
             
              private_class_method def self.read_concept(xmldata, filepath, lang, context)
         
     | 
| 
       76 
     | 
    
         
            -
                project =  
     | 
| 
      
 73 
     | 
    
         
            +
                project = ProjectData.instance
         
     | 
| 
       77 
74 
     | 
    
         
             
                c = Concept.new(xmldata, filepath, lang, context)
         
     | 
| 
       78 
75 
     | 
    
         
             
                c.process = true if [File.basename(filepath), :default].include? project.get(:process_file)
         
     | 
| 
       79 
76 
     | 
    
         
             
                c
         
     | 
| 
         @@ -84,7 +81,7 @@ module ContentLoader 
     | 
|
| 
       84 
81 
     | 
    
         
             
              # @param xmldata (XML Object)
         
     | 
| 
       85 
82 
     | 
    
         
             
              # @param filepath (String)
         
     | 
| 
       86 
83 
     | 
    
         
             
              private_class_method def self.read_code(xmldata, filepath)
         
     | 
| 
       87 
     | 
    
         
            -
                project =  
     | 
| 
      
 84 
     | 
    
         
            +
                project = ProjectData.instance
         
     | 
| 
       88 
85 
     | 
    
         
             
                c = CodeLoader.load(xmldata, filepath)
         
     | 
| 
       89 
86 
     | 
    
         
             
                c.process = true if [File.basename(filepath), :default].include? project.get(:process_file)
         
     | 
| 
       90 
87 
     | 
    
         
             
                c
         
     | 
| 
         @@ -95,8 +92,9 @@ module ContentLoader 
     | 
|
| 
       95 
92 
     | 
    
         
             
              # @param filepath (String)
         
     | 
| 
       96 
93 
     | 
    
         
             
              # @param content (String)
         
     | 
| 
       97 
94 
     | 
    
         
             
              private_class_method def self.raise_error_with(filepath, content)
         
     | 
| 
       98 
     | 
    
         
            -
                msg = 
     | 
| 
       99 
     | 
    
         
            -
                 
     | 
| 
      
 95 
     | 
    
         
            +
                msg =  "[ERROR] ContentLoader: Format error in #{filepath}\n"
         
     | 
| 
      
 96 
     | 
    
         
            +
                msg += "        Take a look at ouput/error.xml"
         
     | 
| 
      
 97 
     | 
    
         
            +
                puts Rainbow(msg).red.bright
         
     | 
| 
       100 
98 
     | 
    
         
             
                f = File.open('output/error.xml', 'w')
         
     | 
| 
       101 
99 
     | 
    
         
             
                f.write(content)
         
     | 
| 
       102 
100 
     | 
    
         
             
                f.close
         
     | 
| 
         @@ -1,7 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'file_loader'
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
5 
     | 
    
         
             
            # Load input data from one directory
         
     | 
| 
       7 
6 
     | 
    
         
             
            module DirectoryLoader
         
     | 
| 
         @@ -13,7 +12,6 @@ module DirectoryLoader 
     | 
|
| 
       13 
12 
     | 
    
         
             
                files = (Dir.new(dirname).entries - ['.', '..']).sort
         
     | 
| 
       14 
13 
     | 
    
         
             
                # Accept only HAML or XML files
         
     | 
| 
       15 
14 
     | 
    
         
             
                accepted = files.select { |f| %w[.xml .haml].include? File.extname(f) }
         
     | 
| 
       16 
     | 
    
         
            -
                Logger.verboseln " * Input directory  = #{Rainbow(dirname).bright}"
         
     | 
| 
       17 
15 
     | 
    
         
             
                DirectoryLoader.load_files(accepted, dirname)
         
     | 
| 
       18 
16 
     | 
    
         
             
              end
         
     | 
| 
       19 
17 
     | 
    
         | 
| 
         @@ -24,7 +22,7 @@ module DirectoryLoader 
     | 
|
| 
       24 
22 
     | 
    
         
             
                return if Dir.exist? dirname
         
     | 
| 
       25 
23 
     | 
    
         | 
| 
       26 
24 
     | 
    
         
             
                msg = Rainbow("[ERROR] #{dirname} directory dosn't exist!").color(:red)
         
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
      
 25 
     | 
    
         
            +
                puts msg
         
     | 
| 
       28 
26 
     | 
    
         
             
                raise msg
         
     | 
| 
       29 
27 
     | 
    
         
             
              end
         
     | 
| 
       30 
28 
     | 
    
         | 
| 
         @@ -48,11 +46,6 @@ module DirectoryLoader 
     | 
|
| 
       48 
46 
     | 
    
         
             
              # @param filepath (String) Path to input file
         
     | 
| 
       49 
47 
     | 
    
         
             
              # @param last (Boolean) True if it is the last filename
         
     | 
| 
       50 
48 
     | 
    
         
             
              def self.load_file(filepath, last = false)
         
     | 
| 
       51 
     | 
    
         
            -
                if last
         
     | 
| 
       52 
     | 
    
         
            -
                  Logger.verboseln "   └── Input file   = #{Rainbow(filepath).bright}"
         
     | 
| 
       53 
     | 
    
         
            -
                else
         
     | 
| 
       54 
     | 
    
         
            -
                  Logger.verboseln "   ├── Input file   = #{Rainbow(filepath).bright}"
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
49 
     | 
    
         
             
                FileLoader.load(filepath)
         
     | 
| 
       57 
50 
     | 
    
         
             
              end
         
     | 
| 
       58 
51 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,21 +2,16 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'content_loader'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require_relative 'haml_loader'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       6 
5 
     | 
    
         | 
| 
       7 
6 
     | 
    
         
             
            # Methods that load a filename and return list of concepts
         
     | 
| 
       8 
7 
     | 
    
         
             
            module FileLoader
         
     | 
| 
       9 
     | 
    
         
            -
              ##
         
     | 
| 
       10 
     | 
    
         
            -
              # Load asker data from file
         
     | 
| 
       11 
     | 
    
         
            -
              # @param filename (String) File name to be load
         
     | 
| 
       12 
8 
     | 
    
         
             
              def self.load(filename)
         
     | 
| 
       13 
9 
     | 
    
         
             
                if File.extname(filename).casecmp('.haml').zero?
         
     | 
| 
       14 
10 
     | 
    
         
             
                  file_content = HamlLoader.load filename
         
     | 
| 
       15 
11 
     | 
    
         
             
                elsif File.extname(filename).casecmp('.xml').zero?
         
     | 
| 
       16 
12 
     | 
    
         
             
                  file_content = File.read(filename)
         
     | 
| 
       17 
13 
     | 
    
         
             
                else
         
     | 
| 
       18 
     | 
    
         
            -
                   
     | 
| 
       19 
     | 
    
         
            -
                  Logger.verboseln msg
         
     | 
| 
      
 14 
     | 
    
         
            +
                  puts "[ERROR] FileLoader: Format error #{filename}"
         
     | 
| 
       20 
15 
     | 
    
         
             
                  raise msg
         
     | 
| 
       21 
16 
     | 
    
         
             
                end
         
     | 
| 
       22 
17 
     | 
    
         
             
                ContentLoader.load(filename, file_content)
         
     | 
| 
         @@ -4,12 +4,16 @@ require 'haml' 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            # HAML file loader
         
     | 
| 
       6 
6 
     | 
    
         
             
            module HamlLoader
         
     | 
| 
       7 
     | 
    
         
            -
              ##
         
     | 
| 
       8 
     | 
    
         
            -
              # Load HAML file name
         
     | 
| 
       9 
     | 
    
         
            -
              # @param filename (String) HAML file name
         
     | 
| 
       10 
7 
     | 
    
         
             
              def self.load(filename)
         
     | 
| 
       11 
8 
     | 
    
         
             
                template = File.read(filename)
         
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
                begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                  haml_engine = Haml::Engine.new(template)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  return haml_engine.render
         
     | 
| 
      
 12 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 13 
     | 
    
         
            +
                  puts "[ERROR] HamlLoader: Can't load <#{filename}> file!"
         
     | 
| 
      
 14 
     | 
    
         
            +
                  puts "  => #{e}"
         
     | 
| 
      
 15 
     | 
    
         
            +
                  exit 0
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
       14 
17 
     | 
    
         
             
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       15 
19 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,8 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         | 
| 
       2 
2 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'uri'
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative '../application'
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       6 
4 
     | 
    
         | 
| 
       7 
5 
     | 
    
         
             
            # Search URL images on Internet
         
     | 
| 
       8 
6 
     | 
    
         
             
            # Methods:
         
     | 
| 
         @@ -36,10 +34,10 @@ module ImageUrlLoader 
     | 
|
| 
       36 
34 
     | 
    
         
             
                    end
         
     | 
| 
       37 
35 
     | 
    
         
             
                  end
         
     | 
| 
       38 
36 
     | 
    
         
             
                rescue
         
     | 
| 
       39 
     | 
    
         
            -
                   
     | 
| 
       40 
     | 
    
         
            -
                   
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
      
 37 
     | 
    
         
            +
                  puts '[ERROR] ImageUrlLoader'
         
     | 
| 
      
 38 
     | 
    
         
            +
                  puts " => #{search_url}"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  puts ' => Check Internet connections'
         
     | 
| 
      
 40 
     | 
    
         
            +
                  puts ' => Ensure URL is well formed'
         
     | 
| 
       43 
41 
     | 
    
         
             
                end
         
     | 
| 
       44 
42 
     | 
    
         
             
                image_urls
         
     | 
| 
       45 
43 
     | 
    
         
             
              end
         
     | 
| 
         @@ -3,30 +3,29 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require_relative 'directory_loader'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require_relative '../ai/concept_ai'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require_relative '../data/world'
         
     | 
| 
       6 
     | 
    
         
            -
            require_relative '../logger'
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
7 
     | 
    
         
             
            # Load DATA defined into our Project
         
     | 
| 
       9 
8 
     | 
    
         
             
            module InputLoader
         
     | 
| 
       10 
9 
     | 
    
         
             
              ##
         
     | 
| 
       11 
10 
     | 
    
         
             
              # Load input data from every input directory
         
     | 
| 
       12 
11 
     | 
    
         
             
              # @param inputdirs (Array)
         
     | 
| 
       13 
     | 
    
         
            -
              def self.load(inputdirs)
         
     | 
| 
      
 12 
     | 
    
         
            +
              def self.load(inputdirs, internet = true)
         
     | 
| 
       14 
13 
     | 
    
         
             
                data = { concepts: [], codes: [], world: nil,
         
     | 
| 
       15 
14 
     | 
    
         
             
                         concepts_ai: [], codes_ai: [] }
         
     | 
| 
       16 
     | 
    
         
            -
                Logger.verboseln "\n[INFO] Loading input data"
         
     | 
| 
      
 15 
     | 
    
         
            +
                #Logger.verboseln "\n[INFO] Loading input data"
         
     | 
| 
       17 
16 
     | 
    
         
             
                inputdirs.each do |dirname|
         
     | 
| 
       18 
17 
     | 
    
         
             
                  temp = DirectoryLoader.load(dirname)
         
     | 
| 
       19 
18 
     | 
    
         
             
                  data[:concepts] += temp[:concepts]
         
     | 
| 
       20 
19 
     | 
    
         
             
                  data[:codes] += temp[:codes]
         
     | 
| 
       21 
20 
     | 
    
         
             
                end
         
     | 
| 
       22 
     | 
    
         
            -
                create_questions(data)
         
     | 
| 
      
 21 
     | 
    
         
            +
                create_questions(data, internet)
         
     | 
| 
       23 
22 
     | 
    
         
             
              end
         
     | 
| 
       24 
23 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              private_class_method def self.create_questions(data)
         
     | 
| 
      
 24 
     | 
    
         
            +
              private_class_method def self.create_questions(data, internet)
         
     | 
| 
       26 
25 
     | 
    
         
             
                # Create World data
         
     | 
| 
       27 
26 
     | 
    
         
             
                # * Calculate concept neighbours
         
     | 
| 
       28 
27 
     | 
    
         
             
                # * TO-DO: Calculate code neighbours
         
     | 
| 
       29 
     | 
    
         
            -
                data[:world] = World.new(data[:concepts])
         
     | 
| 
      
 28 
     | 
    
         
            +
                data[:world] = World.new(data[:concepts], internet)
         
     | 
| 
       30 
29 
     | 
    
         
             
                # Create ConceptAI data (ConceptAI = concept + questions)
         
     | 
| 
       31 
30 
     | 
    
         
             
                data[:concepts].each do |concept|
         
     | 
| 
       32 
31 
     | 
    
         
             
                  data[:concepts_ai] << ConceptAI.new(concept, data[:world])
         
     |