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.
- checksums.yaml +7 -0
- data/README.md +250 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +85 -0
- data/doc/README.gen +210 -0
- data/doc/todo/todo.md +5 -0
- data/lib/dictionaries/ask_english_word.rb +141 -0
- data/lib/dictionaries/ask_italian_word.rb +84 -0
- data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
- data/lib/dictionaries/class/colours.rb +55 -0
- data/lib/dictionaries/class/constants.rb +16 -0
- data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
- data/lib/dictionaries/commandline/parse_commandline.rb +75 -0
- data/lib/dictionaries/constants.rb +133 -0
- data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +457 -0
- data/lib/dictionaries/gui/tk/README.md +2 -0
- data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
- data/lib/dictionaries/helper_module/helper_module.rb +60 -0
- data/lib/dictionaries/project/project.rb +36 -0
- data/lib/dictionaries/require_project/require_project.rb +14 -0
- data/lib/dictionaries/sinatra/app.rb +118 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
- data/lib/dictionaries/statistics/statistics.rb +58 -0
- data/lib/dictionaries/toplevel_methods/e.rb +16 -0
- data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
- data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
- data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
- data/lib/dictionaries/toplevel_methods/misc.rb +185 -0
- data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
- data/lib/dictionaries/toplevel_methods/show_help.rb +31 -0
- data/lib/dictionaries/version/version.rb +19 -0
- data/lib/dictionaries/yaml/chinese.yml +25 -0
- data/lib/dictionaries/yaml/danish.yml +4 -0
- data/lib/dictionaries/yaml/deutsche_fremdw/303/266rter.yml +1 -0
- data/lib/dictionaries/yaml/dutch.yml +3 -0
- data/lib/dictionaries/yaml/english.yml +2661 -0
- data/lib/dictionaries/yaml/farsi.yml +8 -0
- data/lib/dictionaries/yaml/finnish.yml +2 -0
- data/lib/dictionaries/yaml/italian.yml +532 -0
- data/lib/dictionaries/yaml/japanese.yml +15 -0
- data/lib/dictionaries/yaml/norwegian.yml +26 -0
- data/lib/dictionaries/yaml/portugese.yml +41 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +133 -0
- data/lib/dictionaries/yaml/swedish.yml +104 -0
- data/lib/dictionaries.rb +1 -0
- metadata +209 -0
@@ -0,0 +1,693 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# This is the base class for the various dictionaries.
|
6
|
+
#
|
7
|
+
# That way, we can ask specific words from a specific dictionary,
|
8
|
+
# such as english words or italian words and so forth.
|
9
|
+
# =========================================================================== #
|
10
|
+
# require 'dictionaries/class/ask_word_from_dictionary.rb'
|
11
|
+
# =========================================================================== #
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
# =========================================================================== #
|
15
|
+
# Require module-methods of this project next.
|
16
|
+
# =========================================================================== #
|
17
|
+
require 'dictionaries/toplevel_methods/main_file.rb'
|
18
|
+
# =========================================================================== #
|
19
|
+
# Next, load up dictionaries-related ruby code.
|
20
|
+
# =========================================================================== #
|
21
|
+
require 'dictionaries/constants.rb'
|
22
|
+
require 'dictionaries/class/colours.rb'
|
23
|
+
require 'dictionaries/class/set_search_for_this_word.rb'
|
24
|
+
require 'dictionaries/class/constants.rb'
|
25
|
+
|
26
|
+
module Dictionaries
|
27
|
+
|
28
|
+
class AskWordFromDictionary # === Dictionaries::AskWordFromDictionary
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'generate_shell_completion'
|
32
|
+
rescue LoadError; end
|
33
|
+
|
34
|
+
include Colours::E
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'opn'
|
38
|
+
rescue LoadError; end
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'open'
|
42
|
+
rescue LoadError; end
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'xorg_buffer/module'
|
46
|
+
include XorgBuffer
|
47
|
+
rescue LoadError; end
|
48
|
+
|
49
|
+
begin
|
50
|
+
require 'save_file/module'
|
51
|
+
rescue LoadError; end
|
52
|
+
|
53
|
+
# ========================================================================= #
|
54
|
+
# === initialize
|
55
|
+
# ========================================================================= #
|
56
|
+
def initialize(
|
57
|
+
optional_search_for_this_word = nil,
|
58
|
+
use_this_file_for_the_dataset = :default_file,
|
59
|
+
run_already = true
|
60
|
+
)
|
61
|
+
register_sigint
|
62
|
+
reset
|
63
|
+
case optional_search_for_this_word
|
64
|
+
when :do_not_run_yet
|
65
|
+
run_already = :do_not_run_yet
|
66
|
+
optional_search_for_this_word = nil
|
67
|
+
end
|
68
|
+
# ======================================================================= #
|
69
|
+
# === Next, set the main file to use
|
70
|
+
# ======================================================================= #
|
71
|
+
if use_this_file_for_the_dataset
|
72
|
+
set_use_this_file(use_this_file_for_the_dataset)
|
73
|
+
load_main_dataset
|
74
|
+
end
|
75
|
+
set_search_for_this_word(optional_search_for_this_word)
|
76
|
+
if run_already.is_a? Hash
|
77
|
+
if run_already.has_key? :delay
|
78
|
+
set_delay(run_already.delete(:delay))
|
79
|
+
end
|
80
|
+
run_already = true
|
81
|
+
end
|
82
|
+
case run_already
|
83
|
+
when :dont_run_yet, :do_not_run_yet
|
84
|
+
run_already = false
|
85
|
+
end
|
86
|
+
run if run_already
|
87
|
+
end
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === reset
|
91
|
+
# ========================================================================= #
|
92
|
+
def reset
|
93
|
+
# ======================================================================= #
|
94
|
+
# === @original_words
|
95
|
+
# ======================================================================= #
|
96
|
+
@original_words = {} # A Hash.
|
97
|
+
# ======================================================================= #
|
98
|
+
# === @words
|
99
|
+
# ======================================================================= #
|
100
|
+
@words = nil
|
101
|
+
# ======================================================================= #
|
102
|
+
# === @be_verbose
|
103
|
+
# ======================================================================= #
|
104
|
+
@be_verbose = true
|
105
|
+
# ======================================================================= #
|
106
|
+
# === @store_line_number_where
|
107
|
+
# ======================================================================= #
|
108
|
+
@store_line_number_where = STORE_LINE_NUMBER_HERE
|
109
|
+
# ======================================================================= #
|
110
|
+
# === @ask_the_question
|
111
|
+
# ======================================================================= #
|
112
|
+
@ask_the_question = true # Whether to ask the question or not.
|
113
|
+
set_use_this_file # Set to nil initially.
|
114
|
+
set_delay
|
115
|
+
end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === set_delay (delay tag)
|
119
|
+
# ========================================================================= #
|
120
|
+
def set_delay(i = DEFAULT_DELAY)
|
121
|
+
@delay = i
|
122
|
+
end
|
123
|
+
|
124
|
+
# ========================================================================= #
|
125
|
+
# === find_all_matches_for
|
126
|
+
# ========================================================================= #
|
127
|
+
def find_all_matches_for(i) # Must return an Array.
|
128
|
+
selection = @words.select {|key,value| key.start_with? i }.keys
|
129
|
+
return selection
|
130
|
+
end
|
131
|
+
|
132
|
+
# ========================================================================= #
|
133
|
+
# === available_keys?
|
134
|
+
# ========================================================================= #
|
135
|
+
def available_keys?
|
136
|
+
@words.keys if @words
|
137
|
+
end; alias array available_keys? # === array
|
138
|
+
|
139
|
+
# ========================================================================= #
|
140
|
+
# === find_this_word_in_yaml_file
|
141
|
+
#
|
142
|
+
# This method will give us the correct line number.
|
143
|
+
# ========================================================================= #
|
144
|
+
def find_this_word_in_yaml_file(this_word)
|
145
|
+
_ = File.readlines(
|
146
|
+
@use_this_file, :encoding => USE_THIS_ENCODING
|
147
|
+
)
|
148
|
+
_ = _.index() {|x| x =~ /^#{this_word}/ }
|
149
|
+
line_number = _.to_i + 1
|
150
|
+
save_line_number(line_number)
|
151
|
+
save_last_question_asked(this_word)
|
152
|
+
end
|
153
|
+
|
154
|
+
# ========================================================================= #
|
155
|
+
# === show_every_word
|
156
|
+
#
|
157
|
+
# This will simply show every word.
|
158
|
+
# ========================================================================= #
|
159
|
+
def show_every_word
|
160
|
+
@original_words.each_pair {|key, value|
|
161
|
+
e "#{key.to_s.ljust(20)} -> #{value}"
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
# ========================================================================= #
|
166
|
+
# === return_random_word
|
167
|
+
# ========================================================================= #
|
168
|
+
def return_random_word
|
169
|
+
available_keys?.sample
|
170
|
+
end
|
171
|
+
|
172
|
+
# ========================================================================= #
|
173
|
+
# === generate_tab_completion (tab tag)
|
174
|
+
#
|
175
|
+
# The first argument should be the name of the dictionary in question,
|
176
|
+
# such as 'english' or 'italian'.
|
177
|
+
#
|
178
|
+
# To generate the tab completion, do this:
|
179
|
+
#
|
180
|
+
# askeng TAB
|
181
|
+
#
|
182
|
+
# ========================================================================= #
|
183
|
+
def generate_tab_completion(
|
184
|
+
this_language = 'english'
|
185
|
+
)
|
186
|
+
require 'generate_shell_completion'
|
187
|
+
dataset = @original_words.keys # cat $SCI/YAML/DICTIONARIES/english.yml
|
188
|
+
# Next, determine where to store the completion stuff.
|
189
|
+
generate_where =
|
190
|
+
ENV['MY_OS'].to_s+'/LINUX/SHELL/SCRIPTS/'+this_language+'_completion.sh'
|
191
|
+
_ = GenerateShellCompletion::GenerateShellCompletion.new(:do_not_run_yet)
|
192
|
+
_.add_data(dataset)
|
193
|
+
_.set_file(generate_where)
|
194
|
+
_.set_name_of_function(this_language.to_sym)
|
195
|
+
_.add_aliases %w( askeng ask_eng )
|
196
|
+
_.generate
|
197
|
+
end
|
198
|
+
|
199
|
+
# ========================================================================= #
|
200
|
+
# === reveal_the_answer
|
201
|
+
#
|
202
|
+
# Show the answer here.
|
203
|
+
# ========================================================================= #
|
204
|
+
def reveal_the_answer
|
205
|
+
@result = @original_words[@search_for_this_word].to_s
|
206
|
+
_ = @result
|
207
|
+
begin
|
208
|
+
_[0,1] = _[0,1].upcase
|
209
|
+
rescue Exception => error
|
210
|
+
opnn; e 'An exception happened at line '+simp(__LINE__.to_s)+' when '\
|
211
|
+
'we tried to use .upcase.'
|
212
|
+
opnn; e 'The file was '+sfile(__FILE__)
|
213
|
+
opnn; e 'The difficult word in question was `'+simp(_)+'`.'
|
214
|
+
opnn; e 'The encoding in use was '+simp(_.encoding.to_s)+'.'
|
215
|
+
pp error
|
216
|
+
begin
|
217
|
+
_ = _.encode(USE_THIS_ENCODING)
|
218
|
+
_[0,1] = _[0,1].upcase
|
219
|
+
rescue Exception => error
|
220
|
+
pp error
|
221
|
+
end
|
222
|
+
end
|
223
|
+
_ = sanitize_answer(_)
|
224
|
+
if _.include? '[]' # Chop off [] token, if it is part of the String.
|
225
|
+
_ = _.force_encoding(USE_THIS_ENCODING) if _.encoding.to_s.include? 'UTF'
|
226
|
+
_ = _.delete('[').delete(']').strip
|
227
|
+
end
|
228
|
+
e N+simportant(_)+'.'+N+N
|
229
|
+
end; alias reveal_answer reveal_the_answer # === reveal_answer
|
230
|
+
|
231
|
+
# ========================================================================= #
|
232
|
+
# === register_sigint
|
233
|
+
# ========================================================================= #
|
234
|
+
def register_sigint
|
235
|
+
Signal.trap('SIGINT') { exit }
|
236
|
+
end
|
237
|
+
|
238
|
+
# ========================================================================= #
|
239
|
+
# === is_included?
|
240
|
+
# ========================================================================= #
|
241
|
+
def is_included?(i)
|
242
|
+
@original_words.has_key?(i)
|
243
|
+
end
|
244
|
+
|
245
|
+
# ========================================================================= #
|
246
|
+
# === feedback_help_options
|
247
|
+
#
|
248
|
+
# If you wish to trigger this, do:
|
249
|
+
#
|
250
|
+
# askeng --help
|
251
|
+
#
|
252
|
+
# ========================================================================= #
|
253
|
+
def feedback_help_options # help tag
|
254
|
+
e
|
255
|
+
e LPAD+sfancy('TOTAL')+' # Feedback how many keys are registered, '+
|
256
|
+
'also aliased to '+sfancy('STATS')+'.'
|
257
|
+
e LPAD+sfancy('OPEN')+' # Open '+sfile(File.basename(main_file?))+
|
258
|
+
' and '+sfile('ask_english_word.rb')+' in the main editor.'
|
259
|
+
e LPAD+sfancy('SOLVED')+' # Set the last word as solved.'
|
260
|
+
e LPAD+sfancy('URL')+' # Show the URL for the dictionary.'
|
261
|
+
e LPAD+sfancy('REPEAT')+' # Repeat the last question asked.'
|
262
|
+
e LPAD+sfancy('DELAY?')+' # Feedback the delay we use.'
|
263
|
+
e LPAD+sfancy('STATS')+' # To show some statistics, especially '\
|
264
|
+
'the amount of registered words.'
|
265
|
+
e LPAD+sfancy('FILE?')+' # Show the main .yml file in question.'
|
266
|
+
e
|
267
|
+
exit
|
268
|
+
end
|
269
|
+
|
270
|
+
# ========================================================================= #
|
271
|
+
# === search_for?
|
272
|
+
# ========================================================================= #
|
273
|
+
def search_for?
|
274
|
+
@search_for_this_word
|
275
|
+
end
|
276
|
+
|
277
|
+
# ========================================================================= #
|
278
|
+
# === words?
|
279
|
+
# ========================================================================= #
|
280
|
+
def words?
|
281
|
+
@words
|
282
|
+
end; alias dataset? words? # === dataset?
|
283
|
+
|
284
|
+
# ========================================================================= #
|
285
|
+
# === be_verbose?
|
286
|
+
# ========================================================================= #
|
287
|
+
def be_verbose?
|
288
|
+
@be_verbose
|
289
|
+
end
|
290
|
+
|
291
|
+
# ========================================================================= #
|
292
|
+
# === result?
|
293
|
+
# ========================================================================= #
|
294
|
+
def result?
|
295
|
+
@result
|
296
|
+
end; alias result result? # === result
|
297
|
+
|
298
|
+
# ========================================================================= #
|
299
|
+
# === words?
|
300
|
+
# ========================================================================= #
|
301
|
+
def words?
|
302
|
+
@words
|
303
|
+
end
|
304
|
+
|
305
|
+
# ========================================================================= #
|
306
|
+
# === sanitize_dataset
|
307
|
+
# ========================================================================= #
|
308
|
+
def sanitize_dataset # We have to ignore all entries that contain []. We do this only for @words.
|
309
|
+
words?.reject! {|key, value|
|
310
|
+
value.include? '[]'
|
311
|
+
}
|
312
|
+
end
|
313
|
+
|
314
|
+
# ========================================================================= #
|
315
|
+
# === on_roebe?
|
316
|
+
# ========================================================================= #
|
317
|
+
def on_roebe?
|
318
|
+
ENV['IS_ROEBE'].to_s == '1'
|
319
|
+
end
|
320
|
+
|
321
|
+
# ========================================================================= #
|
322
|
+
# === do_ask_the_question
|
323
|
+
# ========================================================================= #
|
324
|
+
def do_ask_the_question # This method will ask the english question.
|
325
|
+
if search_for?.empty?
|
326
|
+
set_search_for_this_word 'RANDOM'
|
327
|
+
end
|
328
|
+
_ = search_for?
|
329
|
+
if _ == 'rand'
|
330
|
+
_ = (@search_for_this_word = return_random_word)
|
331
|
+
end
|
332
|
+
unless is_included? _
|
333
|
+
set_xorg_buffer _
|
334
|
+
opnn; e 'Sorry, the word `'+sfancy(_)+'` is not included.'
|
335
|
+
opnn; e 'We will thus try to open our english dictionary in our editor'
|
336
|
+
opnn; e 'and lookup the word in our browser.'
|
337
|
+
open_main_yaml_file_in_main_editor # Added ~ 22.02.2013
|
338
|
+
consider_opening_browser_page(_)
|
339
|
+
else # Ok, we now know that it is included. Thus, continue.
|
340
|
+
if be_verbose?
|
341
|
+
e "#{rev}What does the word `#{sfancy(_)}` mean? #{show_delay_string}"
|
342
|
+
find_this_word_in_yaml_file(_)
|
343
|
+
new_buffer = build_url_www_string(_)
|
344
|
+
set_xorg_buffer(new_buffer)
|
345
|
+
sleep delay?
|
346
|
+
reveal_the_answer
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# ========================================================================= #
|
352
|
+
# === rev
|
353
|
+
# ========================================================================= #
|
354
|
+
def rev
|
355
|
+
Colours.rev
|
356
|
+
end
|
357
|
+
|
358
|
+
# ========================================================================= #
|
359
|
+
# === set_xorg_buffer
|
360
|
+
# ========================================================================= #
|
361
|
+
def set_xorg_buffer(i)
|
362
|
+
XorgBuffer[i] if Object.const_defined? :XorgBuffer
|
363
|
+
end
|
364
|
+
|
365
|
+
# ========================================================================= #
|
366
|
+
# === store_last_question_asked_where?
|
367
|
+
#
|
368
|
+
# This method will try to automatically find out where we will store
|
369
|
+
# the last question asked.
|
370
|
+
# ========================================================================= #
|
371
|
+
def store_last_question_asked_where?
|
372
|
+
name = Dictionaries.return_name_from_compound(main_file?)
|
373
|
+
path = DEPOT_INFORMATION_DIR+'last_'+name+'_question_asked'
|
374
|
+
return path
|
375
|
+
end
|
376
|
+
|
377
|
+
# ========================================================================= #
|
378
|
+
# === consider_opening_browser_page
|
379
|
+
# ========================================================================= #
|
380
|
+
def consider_opening_browser_page(i = '')
|
381
|
+
url = build_url_www_string(i)
|
382
|
+
opnn; e 'Consider visiting '+brown(url)+' if you need a translation.'
|
383
|
+
open_in_browser url
|
384
|
+
end
|
385
|
+
|
386
|
+
# ========================================================================= #
|
387
|
+
# === build_url_www_string
|
388
|
+
# ========================================================================= #
|
389
|
+
def build_url_www_string(i)
|
390
|
+
_ = ''.dup
|
391
|
+
# ======================================================================= #
|
392
|
+
# We need to differ between the english dictionary and the italian
|
393
|
+
# dictionary.
|
394
|
+
# ======================================================================= #
|
395
|
+
language = Dictionaries.return_name_from_compound(main_file?)
|
396
|
+
if language == 'english'
|
397
|
+
_ << '"' unless _.end_with? '"'
|
398
|
+
end
|
399
|
+
case language # case tag
|
400
|
+
when 'italian'
|
401
|
+
_ << URL_FOR_ITALIAN_DICTIONARY
|
402
|
+
when 'english' # This is the default.
|
403
|
+
_ << URL_FOR_DICT_LEO+'ende/?lp=ende&lang=de&searchLoc=0&cmpType=relaxed§Hdr=on&spellToler=&search='
|
404
|
+
end
|
405
|
+
_ << i.to_s
|
406
|
+
if language == 'english'
|
407
|
+
_ << '"' unless _.end_with? '"' # Append '"' here.
|
408
|
+
end
|
409
|
+
_
|
410
|
+
end
|
411
|
+
|
412
|
+
# ========================================================================= #
|
413
|
+
# === show_help
|
414
|
+
#
|
415
|
+
# Show the help options.
|
416
|
+
# ========================================================================= #
|
417
|
+
def show_help
|
418
|
+
end
|
419
|
+
|
420
|
+
# ========================================================================= #
|
421
|
+
# === load_dataset
|
422
|
+
#
|
423
|
+
# Here we will define the important instance variable @original_words.
|
424
|
+
# ========================================================================= #
|
425
|
+
def load_dataset(
|
426
|
+
of_this_file = @use_this_file
|
427
|
+
) # called via reset()
|
428
|
+
of_this_file = of_this_file.to_s # We must work with a String.
|
429
|
+
if File.exist? of_this_file
|
430
|
+
dataset = YAML.load_file(of_this_file)
|
431
|
+
@original_words = dataset
|
432
|
+
# ^^^ This is the file english.yml
|
433
|
+
else
|
434
|
+
e 'Did not find a file at '+of_this_file+'.'
|
435
|
+
e 'Thus, the @original_words will be empty.'
|
436
|
+
e 'If you wish to change this, modify the constant ENGLISH_WORDS'
|
437
|
+
e 'to point at a yaml-dataset (we require a hash, thus key: value pairs)'
|
438
|
+
@original_words = {}
|
439
|
+
end
|
440
|
+
@words = @original_words.dup
|
441
|
+
sanitize_dataset # Get rid of lines that have [] as entry.
|
442
|
+
end; alias load_main_dataset load_dataset # === load_main_dataset
|
443
|
+
|
444
|
+
# ========================================================================= #
|
445
|
+
# === set_use_this_file
|
446
|
+
#
|
447
|
+
# This sets the main dictionary-file to use, the file path to it.
|
448
|
+
# ========================================================================= #
|
449
|
+
def set_use_this_file(i = :default)
|
450
|
+
case i
|
451
|
+
when :english
|
452
|
+
i = ENGLISH_WORDS
|
453
|
+
when :default_file, :default
|
454
|
+
i = main_file?
|
455
|
+
end
|
456
|
+
@use_this_file = i
|
457
|
+
end
|
458
|
+
|
459
|
+
# ========================================================================= #
|
460
|
+
# === load_the_english_file
|
461
|
+
# ========================================================================= #
|
462
|
+
def load_the_english_file
|
463
|
+
set_use_this_file(:english)
|
464
|
+
load_main_dataset
|
465
|
+
end
|
466
|
+
|
467
|
+
# ========================================================================= #
|
468
|
+
# === use_this_file?
|
469
|
+
# ========================================================================= #
|
470
|
+
def use_this_file?
|
471
|
+
@use_this_file
|
472
|
+
end
|
473
|
+
|
474
|
+
# ========================================================================= #
|
475
|
+
# === opnn
|
476
|
+
# ========================================================================= #
|
477
|
+
def opnn
|
478
|
+
Opn.opn(namespace: NAMESPACE)
|
479
|
+
end
|
480
|
+
|
481
|
+
# ========================================================================= #
|
482
|
+
# === feedback_statistics
|
483
|
+
#
|
484
|
+
# Feedback the amount of questions registered. In the future, perhaps
|
485
|
+
# we may want to have more statistic-options, so this may be expanded
|
486
|
+
# at a later time.
|
487
|
+
#
|
488
|
+
# To trigger this, do:
|
489
|
+
# askeng --stats?
|
490
|
+
# ========================================================================= #
|
491
|
+
def feedback_statistics
|
492
|
+
feedback_total_amount_of_keys(:do_not_exit)
|
493
|
+
end
|
494
|
+
|
495
|
+
# ========================================================================= #
|
496
|
+
# === feedback_url
|
497
|
+
# ========================================================================= #
|
498
|
+
def feedback_url
|
499
|
+
opnn; e " -> #{URL_FOR_DICT_LEO}"
|
500
|
+
exit
|
501
|
+
end
|
502
|
+
|
503
|
+
# ========================================================================= #
|
504
|
+
# === open_yaml_file_in_main_editor
|
505
|
+
# ========================================================================= #
|
506
|
+
def open_yaml_file_in_main_editor(
|
507
|
+
this_file = main_file?
|
508
|
+
)
|
509
|
+
if on_roebe? # Rewrite for my own system at home.
|
510
|
+
this_file = File.basename(this_file)
|
511
|
+
this_file = MY_DICTIONARIES+this_file
|
512
|
+
end
|
513
|
+
_= this_file
|
514
|
+
notify_the_user_that_we_will_next_open_this_file(_)
|
515
|
+
system "bluefish #{_}"
|
516
|
+
end; alias open_main_yaml_file_in_main_editor open_yaml_file_in_main_editor # === open_main_yaml_file_in_main_editor
|
517
|
+
|
518
|
+
# ========================================================================= #
|
519
|
+
# === notify_the_user_that_we_will_next_open_this_file
|
520
|
+
# ========================================================================= #
|
521
|
+
def notify_the_user_that_we_will_next_open_this_file(this_file)
|
522
|
+
opnn; e 'Opening file `'+sfile(this_file)+'` next.'
|
523
|
+
end
|
524
|
+
|
525
|
+
# ========================================================================= #
|
526
|
+
# === feedback_total_amount_of_keys
|
527
|
+
# ========================================================================= #
|
528
|
+
def feedback_total_amount_of_keys(shall_we_exit = true) # KEYS
|
529
|
+
case shall_we_exit
|
530
|
+
when :do_not_exit
|
531
|
+
shall_we_exit = false
|
532
|
+
end
|
533
|
+
_ = @original_words.size - @words.size
|
534
|
+
opnn; e swarn(@original_words.size.to_s)+' english words in total.'
|
535
|
+
rounded = sprintf('%0.2f', 100.0 - (@words.size * 100.0 / @original_words.size) )
|
536
|
+
opnn; e swarn(@words.size.to_s)+' unanswered english words, '\
|
537
|
+
'thus '+sfancy(_.to_s)+' are already answered. ('+
|
538
|
+
simp(rounded.to_s+'%')+')'
|
539
|
+
opnn; e 'The yaml file that we we will use is:'
|
540
|
+
opnn; e ' '+sfile(main_file?)
|
541
|
+
exit if shall_we_exit
|
542
|
+
end
|
543
|
+
|
544
|
+
# ========================================================================= #
|
545
|
+
# === open_this_file_here
|
546
|
+
# ========================================================================= #
|
547
|
+
def open_this_file_here(be_verbose = false)
|
548
|
+
_= Dictionaries.main_file?
|
549
|
+
if be_verbose
|
550
|
+
opnn; notify_the_user_that_we_will_next_open_this_file(_)
|
551
|
+
end
|
552
|
+
system "bluefish #{_}"
|
553
|
+
end
|
554
|
+
|
555
|
+
# ========================================================================= #
|
556
|
+
# === sanitize_answer
|
557
|
+
#
|
558
|
+
# This may also re-encode the given String object.
|
559
|
+
# ========================================================================= #
|
560
|
+
def sanitize_answer(i)
|
561
|
+
begin
|
562
|
+
unless i.encoding.to_s.include? USE_THIS_ENCODING
|
563
|
+
i = i.force_encoding(USE_THIS_ENCODING)
|
564
|
+
end
|
565
|
+
i.gsub!(/ \[\]/,'') if i.include? '[]'
|
566
|
+
rescue Exception => error
|
567
|
+
opnn; pp error # Propagate the error here to the user.
|
568
|
+
end
|
569
|
+
return i
|
570
|
+
end
|
571
|
+
|
572
|
+
# ========================================================================= #
|
573
|
+
# === save_line_number
|
574
|
+
# ========================================================================= #
|
575
|
+
def save_line_number(what) # save tag
|
576
|
+
begin
|
577
|
+
save_file(what, @store_line_number_where)
|
578
|
+
rescue => error
|
579
|
+
pp error
|
580
|
+
pp error.class
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
# ========================================================================= #
|
585
|
+
# === set_last_word_solved
|
586
|
+
# ========================================================================= #
|
587
|
+
def set_last_word_solved # Call this only when you want to solve an english word.
|
588
|
+
begin
|
589
|
+
require 'roebe/classes/append_to_line.rb'
|
590
|
+
_ = Roebe::AppendToLine.new(:english, false) # bl $RUBY_TOOLS/append_to_line.rb
|
591
|
+
_.set_line File.read(STORE_LINE_NUMBER_HERE)
|
592
|
+
_.run
|
593
|
+
rescue LoadError; end
|
594
|
+
exit
|
595
|
+
end
|
596
|
+
|
597
|
+
# ========================================================================= #
|
598
|
+
# === save_last_question_asked
|
599
|
+
# ========================================================================= #
|
600
|
+
def save_last_question_asked(what) # Save the last question asked.
|
601
|
+
into = store_last_question_asked_where?
|
602
|
+
begin
|
603
|
+
save_file(what, into)
|
604
|
+
rescue Errno::ENOENT
|
605
|
+
opnn; e "Can not store into `#{sfile(into)}`."
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
# ========================================================================= #
|
610
|
+
# === save_file
|
611
|
+
# ========================================================================= #
|
612
|
+
def save_file(what, into)
|
613
|
+
SaveFile.write_what_into(what, into)
|
614
|
+
end
|
615
|
+
|
616
|
+
# ========================================================================= #
|
617
|
+
# === delay?
|
618
|
+
# ========================================================================= #
|
619
|
+
def delay?
|
620
|
+
@delay
|
621
|
+
end
|
622
|
+
|
623
|
+
# ========================================================================= #
|
624
|
+
# === feedback_delay
|
625
|
+
# ========================================================================= #
|
626
|
+
def feedback_delay
|
627
|
+
opnn; e "The delay we use is set to: #{sfancy(@delay.to_s)}"
|
628
|
+
exit
|
629
|
+
end
|
630
|
+
|
631
|
+
# ========================================================================= #
|
632
|
+
# === translate
|
633
|
+
# ========================================================================= #
|
634
|
+
def translate(i)
|
635
|
+
return @original_words[i].to_s
|
636
|
+
end
|
637
|
+
|
638
|
+
# ========================================================================= #
|
639
|
+
# === show_delay_string
|
640
|
+
# ========================================================================= #
|
641
|
+
def show_delay_string
|
642
|
+
result = '(Delay is at '+simp(@delay.to_s)+' seconds)'
|
643
|
+
result = '' if @delay.to_i == 0
|
644
|
+
return result
|
645
|
+
end
|
646
|
+
|
647
|
+
# ========================================================================= #
|
648
|
+
# === feedback_yaml_file
|
649
|
+
# ========================================================================= #
|
650
|
+
def feedback_yaml_file
|
651
|
+
efile main_file?
|
652
|
+
end
|
653
|
+
|
654
|
+
# ========================================================================= #
|
655
|
+
# === main_file?
|
656
|
+
# ========================================================================= #
|
657
|
+
def main_file?
|
658
|
+
Dictionaries.main_file?
|
659
|
+
end; alias currently_selected_file? main_file? # === currently_selected_file?
|
660
|
+
|
661
|
+
# ========================================================================= #
|
662
|
+
# === run (run tag)
|
663
|
+
# ========================================================================= #
|
664
|
+
def run
|
665
|
+
load_dataset
|
666
|
+
do_ask_the_question if @ask_the_question
|
667
|
+
end
|
668
|
+
|
669
|
+
end
|
670
|
+
|
671
|
+
# =========================================================================== #
|
672
|
+
# === Dictionaries.translate
|
673
|
+
# =========================================================================== #
|
674
|
+
def self.translate(this_word = nil)
|
675
|
+
_ = Dictionaries::AskWordFromDictionary.new(this_word, :default_file, :dont_run_yet)
|
676
|
+
_.translate(this_word)
|
677
|
+
end
|
678
|
+
|
679
|
+
# =========================================================================== #
|
680
|
+
# === Dictionaries.new
|
681
|
+
# =========================================================================== #
|
682
|
+
def self.new(i = nil)
|
683
|
+
Dictionaries::AskWordFromDictionary.new(i)
|
684
|
+
end
|
685
|
+
|
686
|
+
end
|
687
|
+
|
688
|
+
if __FILE__ == $PROGRAM_NAME
|
689
|
+
pp Dictionaries::AskWordFromDictionary.new
|
690
|
+
pp Dictionaries::AskWordFromDictionary.class
|
691
|
+
pp Dictionaries::DICTIONARIES_DIR
|
692
|
+
pp Dictionaries::ENGLISH_WORDS
|
693
|
+
end
|