dictionaries 0.3.24

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dictionaries might be problematic. Click here for more details.

Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +250 -0
  3. data/bin/dictionaries +7 -0
  4. data/bin/unique_words_in_this_file +7 -0
  5. data/dictionaries.gemspec +85 -0
  6. data/doc/README.gen +210 -0
  7. data/doc/todo/todo.md +5 -0
  8. data/lib/dictionaries/ask_english_word.rb +141 -0
  9. data/lib/dictionaries/ask_italian_word.rb +84 -0
  10. data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
  11. data/lib/dictionaries/class/colours.rb +55 -0
  12. data/lib/dictionaries/class/constants.rb +16 -0
  13. data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
  14. data/lib/dictionaries/commandline/parse_commandline.rb +75 -0
  15. data/lib/dictionaries/constants.rb +133 -0
  16. data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +457 -0
  17. data/lib/dictionaries/gui/tk/README.md +2 -0
  18. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  19. data/lib/dictionaries/helper_module/helper_module.rb +60 -0
  20. data/lib/dictionaries/project/project.rb +36 -0
  21. data/lib/dictionaries/require_project/require_project.rb +14 -0
  22. data/lib/dictionaries/sinatra/app.rb +118 -0
  23. data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
  24. data/lib/dictionaries/statistics/statistics.rb +58 -0
  25. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  26. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  27. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  28. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  29. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  30. data/lib/dictionaries/toplevel_methods/misc.rb +185 -0
  31. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  32. data/lib/dictionaries/toplevel_methods/show_help.rb +31 -0
  33. data/lib/dictionaries/version/version.rb +19 -0
  34. data/lib/dictionaries/yaml/chinese.yml +25 -0
  35. data/lib/dictionaries/yaml/danish.yml +4 -0
  36. data/lib/dictionaries/yaml/deutsche_fremdw/303/266rter.yml +1 -0
  37. data/lib/dictionaries/yaml/dutch.yml +3 -0
  38. data/lib/dictionaries/yaml/english.yml +2661 -0
  39. data/lib/dictionaries/yaml/farsi.yml +8 -0
  40. data/lib/dictionaries/yaml/finnish.yml +2 -0
  41. data/lib/dictionaries/yaml/italian.yml +532 -0
  42. data/lib/dictionaries/yaml/japanese.yml +15 -0
  43. data/lib/dictionaries/yaml/norwegian.yml +26 -0
  44. data/lib/dictionaries/yaml/portugese.yml +41 -0
  45. data/lib/dictionaries/yaml/russian.yml +10 -0
  46. data/lib/dictionaries/yaml/spanish.yml +133 -0
  47. data/lib/dictionaries/yaml/swedish.yml +104 -0
  48. data/lib/dictionaries.rb +1 -0
  49. metadata +209 -0
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::Sinatra
6
+ # =========================================================================== #
7
+ # require 'dictionaries/sinatra/app.rb'
8
+ # =========================================================================== #
9
+ require 'sinatra/base.rb'
10
+
11
+ module Dictionaries
12
+
13
+ class Sinatra < ::Sinatra::Base
14
+
15
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
16
+ require 'dictionaries/toplevel_methods/is_on_roebe.rb'
17
+ require 'dictionaries/sinatra/english_to_german.rb'
18
+
19
+ include ::Colours
20
+ include ::Colours::E
21
+ begin
22
+ require 'html_tags'
23
+ include HtmlTags::BaseModule
24
+ rescue LoadError; end
25
+
26
+ # ========================================================================= #
27
+ # === USE_THIS_PORT
28
+ # ========================================================================= #
29
+ USE_THIS_PORT = '5252'
30
+
31
+ set :port, USE_THIS_PORT
32
+
33
+ # ========================================================================= #
34
+ # === initialize
35
+ # ========================================================================= #
36
+ def initialize(
37
+ i = ARGV
38
+ )
39
+ super()
40
+ reset
41
+ consider_opening_the_page_in_the_browser(i)
42
+ end
43
+
44
+ # ========================================================================= #
45
+ # === reset (reset tag)
46
+ # ========================================================================= #
47
+ def reset
48
+ end
49
+
50
+ # ========================================================================= #
51
+ # === consider_opening_the_page_in_the_browser
52
+ # ========================================================================= #
53
+ def consider_opening_the_page_in_the_browser(
54
+ shall_we_open_the_page_in_the_browser = ::Dictionaries.is_on_roebe?
55
+ )
56
+ case shall_we_open_the_page_in_the_browser
57
+ # ======================================================================= #
58
+ # === :do_not_open_in_the_browser
59
+ # ======================================================================= #
60
+ when :do_not_open_in_the_browser,
61
+ :dont_connect,
62
+ :dont
63
+ shall_we_open_the_page_in_the_browser = false
64
+ end
65
+ if shall_we_open_the_page_in_the_browser
66
+ begin
67
+ require 'open'
68
+ rescue LoadError; end
69
+ # ===================================================================== #
70
+ # Tell us which port will be used:
71
+ # ===================================================================== #
72
+ target = "http://localhost:#{USE_THIS_PORT}/"
73
+ e sfancy(target)
74
+ Thread.new {
75
+ sleep 0.8
76
+ Open.in_browser(target)
77
+ }
78
+ end
79
+ end
80
+
81
+ # ========================================================================= #
82
+ # === / Entry point
83
+ #
84
+ # This is the root of our web-application.
85
+ # ========================================================================= #
86
+ get('/'){
87
+ html_header_default_title_and_start_of_the_body_tag+
88
+ p('The following translation-tables are available:')+
89
+ HtmlTags.a('/english_to_german', css_style: 'margin-left: 2em')+
90
+ br+
91
+ HtmlTags.a('/german_to_english', css_style: 'margin-left: 2em')+
92
+ br
93
+ }
94
+
95
+ # ========================================================================= #
96
+ # === not_found
97
+ # ========================================================================= #
98
+ not_found {
99
+ p('This particular <b>API</b> was not found.')
100
+ }
101
+
102
+ end
103
+
104
+ # =========================================================================== #
105
+ # === Dictionaries.start_sinatra_interface
106
+ #
107
+ # This method can be used to start the sinatra interface.
108
+ # =========================================================================== #
109
+ def self.start_sinatra_interface
110
+ e 'Trying to start the sinatra-interface of the Dictionaries project.'
111
+ ::Dictionaries::Sinatra.run!
112
+ end
113
+
114
+ end
115
+
116
+ if __FILE__ == $PROGRAM_NAME
117
+ Dictionaries.start_sinatra_interface
118
+ end # dictionaries --sinatra
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # 'dictionaries/english_to_german.rb'
6
+ # =========================================================================== #
7
+ require 'sinatra/base.rb'
8
+
9
+ module Dictionaries
10
+
11
+ class Sinatra < ::Sinatra::Base
12
+
13
+ require 'dictionaries/toplevel_methods/english_to_german.rb'
14
+ require 'dictionaries/helper_module/helper_module.rb'
15
+
16
+ # ========================================================================= #
17
+ # === /english_to_german
18
+ #
19
+ # This is the root of our web-application.
20
+ # ========================================================================= #
21
+ get('/english_to_german'){
22
+ return_english_to_german_form
23
+ }
24
+
25
+ # ========================================================================= #
26
+ # === return_english_to_german_form
27
+ # ========================================================================= #
28
+ def return_english_to_german_form
29
+ route_to_this_action = '/english_to_german/'
30
+ html_header_default_title_and_start_of_the_body_tag+
31
+ h5('Input an english word to see the translation.')+
32
+ div(css_style: 'padding: 0.1em') {
33
+ p(
34
+ '<b>Enter the word here:</b>',
35
+ css_style: 'padding: 0.15em'
36
+ )+
37
+ form(action: route_to_this_action,
38
+ id: 'english_to_german',
39
+ css_style: 'margin-left:1em; margin-top:2px') {
40
+ '<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
41
+ return_search_button
42
+ }
43
+ }
44
+ end
45
+
46
+ # ========================================================================= #
47
+ # === html_header_default_title_and_start_of_the_body_tag
48
+ # ========================================================================= #
49
+ def html_header_default_title_and_start_of_the_body_tag
50
+ return Dictionaries::HelperModule.html_header_default_title_and_start_of_the_body_tag
51
+ end
52
+
53
+ # ========================================================================= #
54
+ # === return_search_button
55
+ # ========================================================================= #
56
+ def return_search_button
57
+ return Dictionaries::HelperModule.return_search_button
58
+ end
59
+
60
+ # ========================================================================= #
61
+ # === /english_to_german
62
+ #
63
+ # This is the root of our web-application.
64
+ # ========================================================================= #
65
+ get('/english_to_german/*'){
66
+ _ = params[:splat]
67
+ _ = params.fetch('user_input') if params.has_key?('user_input')
68
+ _ = _.join if _.is_a? Array
69
+ # ======================================================================= #
70
+ # Obtain the translated word next:
71
+ # ======================================================================= #
72
+ translated_word = Dictionaries.english_to_german(_)
73
+ if translated_word
74
+ html_header_default_title_and_start_of_the_body_tag+
75
+ p('The word <b>'+_.to_s+'</b> translates to: '\
76
+ '<b style="font-size: larger; color: darkblue">'+translated_word+'</b>')+
77
+ return_english_to_german_form
78
+ else
79
+ html_header_default_title_and_start_of_the_body_tag+
80
+ p('The key '+_.to_s+' is not registered in the Dictionaries word file.')
81
+ end
82
+ }
83
+
84
+ end; end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::Statistics
6
+ # =========================================================================== #
7
+ # require 'dictionaries/statistics/statistics.rb'
8
+ # =========================================================================== #
9
+ module Dictionaries
10
+
11
+ module Statistics # === Dictionaries::Statistics
12
+
13
+ require 'dictionaries/constants.rb'
14
+ require 'dictionaries/toplevel_methods/misc.rb'
15
+ require 'dictionaries/project/project.rb'
16
+
17
+ # ========================================================================= #
18
+ # === Dictionaries::Statistics.e
19
+ # ========================================================================= #
20
+ def self.e(i = '')
21
+ puts i
22
+ end
23
+
24
+ # ========================================================================= #
25
+ # === Dictionaries::Statistics.report
26
+ # ========================================================================= #
27
+ def self.report
28
+ require 'yaml'
29
+ begin
30
+ require 'colours'
31
+ rescue LoadError; end
32
+ all_files = Dir[
33
+ Dictionaries.project_yaml_dir?+'*'
34
+ ].reject {|entry| entry.include?('deutsche_fremdwörter.yml') }
35
+ e 'The statistics for each .yml file available in this project are'
36
+ e 'as follows:'
37
+ e
38
+ all_files.each {|this_file|
39
+ begin
40
+ dataset = YAML.load_file(this_file)
41
+ if dataset
42
+ e " #{File.basename(this_file).delete_suffix('.yml').ljust(15)} "+
43
+ "#{::Colours.steelblue(dataset.keys.size.to_s.rjust(4))} words."
44
+ else
45
+ e 'No data is available for '+this_file+'.'
46
+ end
47
+ rescue => error
48
+ pp error
49
+ end
50
+ }
51
+ e
52
+ end
53
+
54
+ end; end
55
+
56
+ if __FILE__ == $PROGRAM_NAME
57
+ Dictionaries::Statistics.report
58
+ end # statistics.rb
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/e.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries.e
11
+ # ========================================================================= #
12
+ def self.e(i = '')
13
+ puts i
14
+ end
15
+
16
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/english_to_german.rb'
6
+ # =========================================================================== #
7
+ require 'dictionaries/toplevel_methods/has_key.rb'
8
+ require 'dictionaries/toplevel_methods/misc.rb'
9
+
10
+ module Dictionaries
11
+
12
+ # ========================================================================= #
13
+ # === Dictionaries.english_to_german
14
+ #
15
+ # This method will return nil if the key has not been found in the
16
+ # Dictionaries dataset.
17
+ # ========================================================================= #
18
+ def self.english_to_german(i)
19
+ i = i.join.strip if i.is_a? Array
20
+ converted_word = nil
21
+ if Dictionaries.has_key? i
22
+ converted_word = Dictionaries[i]
23
+ end
24
+ converted_word
25
+ end; self.instance_eval { alias translate_this_from_english_to_german english_to_german } # === Dictionaries.translate_this_from_english_to_german
26
+
27
+ end
28
+
29
+ if __FILE__ == $PROGRAM_NAME
30
+ pp Dictionaries.english_to_german(ARGV)
31
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/has_key.rb'
6
+ # Dictionaries.has_key?
7
+ # =========================================================================== #
8
+ module Dictionaries
9
+
10
+ require 'dictionaries/ask_english_word.rb'
11
+
12
+ # ========================================================================= #
13
+ # === Dictionaries.has_key?
14
+ #
15
+ # Query whether the main file of the Dictionaries namespace, has the
16
+ # given input key at hand.
17
+ #
18
+ # Returns:
19
+ # true if the key is included
20
+ # false otherwise
21
+ #
22
+ # Invocation examples:
23
+ #
24
+ # Dictionaries.has_key? 'apprehensions' # => true
25
+ # Dictionaries.has_key? 'apprehensio'
26
+ #
27
+ # ========================================================================= #
28
+ def self.has_key?(this_key)
29
+ Dictionaries::AskEnglishWord.dataset?.has_key?(this_key)
30
+ end
31
+
32
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/is_on_roebe.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries.is_on_roebe?
11
+ # ========================================================================= #
12
+ def self.is_on_roebe?
13
+ (ENV['IS_ROEBE'].to_s == '1')
14
+ end
15
+
16
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/main_file.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === @main_file
11
+ #
12
+ # This module-level instance variable keeps track of the main file in
13
+ # use.
14
+ # ========================================================================= #
15
+ @main_file = nil
16
+
17
+ # ========================================================================= #
18
+ # === DICTIONARIES_FILE
19
+ #
20
+ # Add support for the environment variable DICTIONARIES_FILE here.
21
+ # ========================================================================= #
22
+ if ENV['DICTIONARIES_FILE'] and
23
+ File.exist?(ENV['DICTIONARIES_FILE'])
24
+ @main_file = ENV['DICTIONARIES_FILE'].to_s
25
+ end
26
+
27
+ # ========================================================================= #
28
+ # === Dictionaries.return_name_from_compound
29
+ #
30
+ # This method will return 'italian' if the input is 'ask_italian_word'.
31
+ # ========================================================================= #
32
+ def self.return_name_from_compound(
33
+ i = Dictionaries.main_file?
34
+ )
35
+ i = i.to_s
36
+ i = File.basename(i).gsub(/.rb/, '').gsub(/.yml/, '')
37
+ if i.include? '_'
38
+ i = i.split('_')[1] # Grab the middle part here.
39
+ end
40
+ i
41
+ end
42
+
43
+ # ========================================================================= #
44
+ # === Dictionaries.set_main_file
45
+ #
46
+ # Use this method to designate the main yaml file which should contain
47
+ # the language-specific translations.
48
+ #
49
+ # If the input includes a '/' token and also ends with '.rb' then we
50
+ # assume that it may be in the form of this:
51
+ #
52
+ # /home/x/programming/ruby/src/dictionaries/lib/dictionaries/ask_italian_word.rb
53
+ #
54
+ # So we will instead use the second part of the last part.
55
+ #
56
+ # Usage example:
57
+ #
58
+ # Dictionaries.set_main_file(THIS_FILE)
59
+ #
60
+ # ========================================================================= #
61
+ def self.set_main_file(i = :default_file)
62
+ case i
63
+ when :default_file,
64
+ :default
65
+ i = FILE_ENGLISH_WORDS
66
+ end
67
+ if i.include? '/'
68
+ if i.end_with? '.rb'
69
+ i = File.basename(i).sub(/.rb^/,'')
70
+ if i.include? '_'
71
+ i = Dictionaries.return_name_from_compound(i) # Grab the middle part here.
72
+ i = DICTIONARIES_DIR+i+'.yml'
73
+ end
74
+ end
75
+ end
76
+ @main_file = i
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === Dictionaries.main_file?
81
+ #
82
+ # Query method over the @main_file module-level instance variable.
83
+ # ========================================================================= #
84
+ def self.main_file?
85
+ @main_file
86
+ end; self.instance_eval { alias main_file main_file? } # === Dictionaries.main_file
87
+
88
+ end
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/misc.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ require 'yaml'
10
+ require 'dictionaries/constants.rb'
11
+ require 'dictionaries/toplevel_methods/main_file.rb'
12
+ require 'dictionaries/toplevel_methods/has_key.rb'
13
+
14
+ # ========================================================================= #
15
+ # === Dictionaries.generate_pdf_file
16
+ #
17
+ # This method can be used to generate a .pdf file.
18
+ # ========================================================================= #
19
+ def self.generate_pdf_file(
20
+ use_this_font = 'Courier', # Helvetica-Bold' # #'Times-Roman'
21
+ use_this_font_size = 12
22
+ )
23
+ require 'prawn'
24
+ ::Prawn::Fonts::AFM.hide_m17n_warning = true
25
+ right_arrow = ' -> '.dup.encode(
26
+ 'Windows-1252', invalid: :replace, undef: :replace, replace: ''
27
+ )
28
+ dataset = YAML.load_file(Dictionaries.file_english)
29
+ into = File.absolute_path('english_to_german_dictionary.pdf')
30
+ Prawn::Document.generate(into) {
31
+ font use_this_font
32
+ font_size use_this_font_size
33
+ text(
34
+ "English to German dictionary: "\
35
+ "#{dataset.keys.size.to_s} translated words\n\n"
36
+ )
37
+ # ===================================================================== #
38
+ # Iterate over our exam dataset next.
39
+ # ===================================================================== #
40
+ dataset.each_pair {|key, value|
41
+ indent(8) {
42
+ key = key.dup if key.frozen?
43
+ value = value.dup if value.frozen?
44
+ result = key.encode(
45
+ 'Windows-1252', invalid: :replace, undef: :replace, replace: ''
46
+ )+
47
+ right_arrow+
48
+ value.encode(
49
+ 'Windows-1252', invalid: :replace, undef: :replace, replace: ''
50
+ )
51
+ text(result, {size: 10})
52
+ }
53
+ }
54
+ }
55
+ e 'Stored into `'+into+'`.'
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === Dictionaries[]
60
+ #
61
+ # Currently this method will always reload the main file. In the future
62
+ # we may change this approach, but for now this has to suffice (May 2019).
63
+ #
64
+ # The method will return either the translated string - or nil. Nil
65
+ # indicates that the main Hash does not include that key; in other words,
66
+ # that the word is not registered.
67
+ # ========================================================================= #
68
+ def self.[](i = ARGV)
69
+ i = i.join.strip if i.is_a? Array
70
+ this_file = Dictionaries.main_file?
71
+ if this_file.nil?
72
+ Dictionaries.set_main_file(:default) # Must initialize it in this case.
73
+ this_file = Dictionaries.main_file?
74
+ end
75
+ if this_file
76
+ dataset = YAML.load_file(this_file)
77
+ dataset[i] # Return the result here.
78
+ else
79
+ nil
80
+ end
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === Dictionaries.return_array_of_translated_words_from_online_leo
85
+ #
86
+ # This method can be used to query the online dictionary from leo.
87
+ #
88
+ # It will then return an Array of translations.
89
+ #
90
+ # Note that this currently only works for the translation from english
91
+ # to german, not the other way around, even though that is not too
92
+ # hard to implement either.
93
+ # ========================================================================= #
94
+ def self.return_array_of_translated_words_from_online_leo(this_word)
95
+ if this_word.is_a? Array
96
+ this_word = this_word.join(' ').strip
97
+ end
98
+ require 'open-uri'
99
+ remote_url = "https://dict.leo.org/german-english/#{this_word}"
100
+ remote_dataset = URI.open(remote_url).read
101
+ # ======================================================================= #
102
+ # See: https://rubular.com/r/OOXwAc6PVqjU5Q
103
+ # ======================================================================= #
104
+ use_this_regex =
105
+ /<words><word>([a-zA-Z\s]+)\<\/word><\/words>/
106
+ scanned_results = remote_dataset.scan(use_this_regex).flatten
107
+ # ======================================================================= #
108
+ # This result may look like so:
109
+ # [["cat"], ["die Katze"]
110
+ # We have to sanitize it still.
111
+ # ======================================================================= #
112
+ scanned_results.reject! {|entry| entry.start_with?(this_word) }
113
+ return scanned_results # Note that the full Array is returned.
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === Dictionaries.return_unique_words_from_this_file
118
+ #
119
+ # This method will read in the words from an existing local file.
120
+ #
121
+ # Some files may be huge, though, and then this method becomes
122
+ # quite useless, so we really should discard a lot of data after a
123
+ # certain threshold, to keep memory usage low.
124
+ # ========================================================================= #
125
+ def self.return_unique_words_from_this_file(
126
+ this_file,
127
+ optional_arguments = :english,
128
+ remove_html_tags = false
129
+ )
130
+ case remove_html_tags
131
+ # ======================================================================= #
132
+ # === :remove_HTML_tags
133
+ # ======================================================================= #
134
+ when :remove_HTML_tags
135
+ remove_html_tags = true
136
+ end
137
+ dataset = nil
138
+ if this_file.is_a? Array
139
+ this_file = this_file.join(' ').strip
140
+ end
141
+ if this_file and File.file?(this_file)
142
+ dataset = File.read(this_file)
143
+ if remove_html_tags
144
+ require 'cyberweb/toplevel_methods/remove_html.rb'
145
+ dataset = ::Cyberweb.remove_html(dataset)
146
+ end
147
+ end
148
+ result = [] # ← This variable will store the unique words found in the file.
149
+ case optional_arguments
150
+ # ======================================================================= #
151
+ # === :english
152
+ # ======================================================================= #
153
+ when :english,
154
+ :default
155
+ # ===================================================================== #
156
+ # Query unknown words in english. We will compare the words to the
157
+ # available variants.
158
+ # ===================================================================== #
159
+ result = dataset.scan(/\w+/).map {|entry| entry.downcase } # ← Obtain all words here.
160
+ # ===================================================================== #
161
+ # Next, reject those that are registered:
162
+ # ===================================================================== #
163
+ result.reject! {|this_word|
164
+ ::Dictionaries.has_key?(this_word)
165
+ }
166
+ end if dataset
167
+ return result.uniq.sort
168
+ end
169
+
170
+ end
171
+
172
+ if __FILE__ == $PROGRAM_NAME
173
+ alias e puts
174
+ #puts Dictionaries[ARGV]
175
+ e 'Possible words for cat:'
176
+ pp Dictionaries.return_array_of_translated_words_from_online_leo('cat')
177
+ # ========================================================================= #
178
+ # The next chunk of code is to test reading unique words from a given
179
+ # local file.
180
+ # ========================================================================= #
181
+ puts '-'*80
182
+ _ = Dictionaries.return_unique_words_from_this_file('/Depot/j/foobar.md')
183
+ pp _
184
+ pp _.size
185
+ end # rb misc.rb cat
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Just bundle together some requires through this file here.
6
+ # =========================================================================== #
7
+ require 'dictionaries/commandline/parse_commandline.rb'
8
+ require 'dictionaries/toplevel_methods/e.rb'
9
+ require 'dictionaries/toplevel_methods/show_help.rb'
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/show_help.rb'
6
+ # =========================================================================== #
7
+ require 'dictionaries/toplevel_methods/e.rb'
8
+
9
+ module Dictionaries
10
+
11
+ # ========================================================================= #
12
+ # === Dictionaries.show_help
13
+ #
14
+ # To invoke this, try:
15
+ #
16
+ # dictionaries --help
17
+ #
18
+ # ========================================================================= #
19
+ def self.show_help
20
+ help_string = <<EOF
21
+ These options are currently available:
22
+
23
+ --n_words? # Show how many words are available
24
+ --gui # Start the GTK GUI; aliases exist to this, such as --gtk
25
+ --read=www.nytimes.com.html # Read from a specific file, to find unique words
26
+
27
+ EOF
28
+ e help_string
29
+ end
30
+
31
+ end