dictionaries 0.3.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +354 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +84 -0
- data/doc/README.gen +292 -0
- data/doc/todo/todo.md +8 -0
- data/lib/dictionaries/ask_english_word.rb +141 -0
- data/lib/dictionaries/ask_italian_word.rb +84 -0
- data/lib/dictionaries/base/base.rb +78 -0
- data/lib/dictionaries/class/class.rb +903 -0
- data/lib/dictionaries/commandline/parse_commandline.rb +85 -0
- data/lib/dictionaries/constants/constants.rb +134 -0
- data/lib/dictionaries/gui/tk/README.md +2 -0
- data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
- data/lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb +516 -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 +123 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
- data/lib/dictionaries/spell_checker/README.md +5 -0
- data/lib/dictionaries/spell_checker/spell_checker.rb +133 -0
- data/lib/dictionaries/statistics/statistics.rb +59 -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 +231 -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 +3263 -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/polish.yml +2 -0
- data/lib/dictionaries/yaml/portugese.yml +41 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +147 -0
- data/lib/dictionaries/yaml/swedish.yml +104 -0
- data/lib/dictionaries.rb +1 -0
- data/test/translation_example.html +2758 -0
- metadata +211 -0
data/doc/README.gen
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
DEFAULT_HEADER
|
2
|
+
|
3
|
+
## Environment variable to use a specific yaml file
|
4
|
+
|
5
|
+
You can use an <b>environment variable</b> to denote the default
|
6
|
+
yaml file in use. This allows you to use your own yaml file
|
7
|
+
format, rather than the yaml files that are distributed with
|
8
|
+
this gem.
|
9
|
+
|
10
|
+
The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
|
11
|
+
It shall point to your yaml file that holds the key-value pairs.
|
12
|
+
|
13
|
+
For example, if your file is at /opt/czech.yml, then
|
14
|
+
DICTIONARIES_FILE should point at that location.
|
15
|
+
|
16
|
+
In bash, this may be equivalent to:
|
17
|
+
|
18
|
+
export DICTIONARIES_FILE=/opt/czech.yml
|
19
|
+
|
20
|
+
Note that in the long run, the dictionaries gem could be extended
|
21
|
+
with these yaml files - or allow means to download these files
|
22
|
+
over the www. But before we can do so, let's aim for at the least
|
23
|
+
100 words in such a file before we would consider distributing
|
24
|
+
it or offering means to distribute said file.
|
25
|
+
|
26
|
+
## Difficult english sentences
|
27
|
+
|
28
|
+
English is not the most difficult language in the world, but when it
|
29
|
+
comes to proper pronounciation of words, english can be surprisingly
|
30
|
+
difficult.
|
31
|
+
|
32
|
+
This subsection may keep a listing of sentences that, for one reason
|
33
|
+
or the other, can be somewhat difficult to **read out aloud** without
|
34
|
+
mistake, on a first try. It is just a fun-subsection, not meant to be
|
35
|
+
taken too seriously; and it is quite subjective.
|
36
|
+
|
37
|
+
Without any further ado, here comes a listing of sentences that may
|
38
|
+
be difficult to pronounce properly so:
|
39
|
+
|
40
|
+
I would like to distribute something.
|
41
|
+
|
42
|
+
## Obtaining all translations into german for a given english word
|
43
|
+
|
44
|
+
Since as of **November 2020** the following API exists:
|
45
|
+
|
46
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('cat')
|
47
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('dog')
|
48
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('human')
|
49
|
+
|
50
|
+
This will return an Array of german names. It does not work 100% perfectly
|
51
|
+
as it is based on a regex; and using a regex to parse HTML is never a
|
52
|
+
trivial way. But if you just want to get the first entry, just call
|
53
|
+
.first on it, and in most cases this is the best, most likely
|
54
|
+
translation available.
|
55
|
+
|
56
|
+
The regex has to find matches to entries such as the following one:
|
57
|
+
|
58
|
+
</repr><words><word>der Jazzfan</word></words>
|
59
|
+
|
60
|
+
Anyone to come up with a more accurate regex is welcome to share it. :)
|
61
|
+
|
62
|
+
This functionality was specifically necessary because I needed to
|
63
|
+
use this in the ruby-gtk bindings for this project.
|
64
|
+
|
65
|
+
## Dictionaries.return_unique_words_from_this_file
|
66
|
+
|
67
|
+
This method will return all words that are presently not registered
|
68
|
+
in the english dictionary.
|
69
|
+
|
70
|
+
The idea here is for me to slowly add more english words into the
|
71
|
+
yaml file. I won't add every english word that exists, but I will
|
72
|
+
try to aim for a seizable number in the long run, such as
|
73
|
+
5000 english words - already halfway there. \o/
|
74
|
+
|
75
|
+
## GUI component
|
76
|
+
|
77
|
+
The **GUI component** of the dictionaries gem defaults to
|
78
|
+
**GTK3** finally. It is not a very advanced GUI, though.
|
79
|
+
|
80
|
+
First, install the gtk3 gem:
|
81
|
+
|
82
|
+
gem install gtk3
|
83
|
+
|
84
|
+
Then install the gtk_paradise project:
|
85
|
+
|
86
|
+
gem install gtk_paradise
|
87
|
+
|
88
|
+
Now you should be able to start the GUI component if the above
|
89
|
+
has worked:
|
90
|
+
|
91
|
+
dictionaries --gui
|
92
|
+
|
93
|
+
See also the help options.
|
94
|
+
|
95
|
+
dictionaries --help
|
96
|
+
|
97
|
+
You may need to install some .h files if you use a specific
|
98
|
+
Linux distribution; look at the relevant -dev packages for
|
99
|
+
this. Or just compile from source. :)
|
100
|
+
|
101
|
+
The current version of ruby-gtk3 in October 2021 looks like
|
102
|
+
this:
|
103
|
+
|
104
|
+
<img src="https://i.imgur.com/K430Kae.png" style="margin-left: 2em">
|
105
|
+
|
106
|
+
Yes, this isn't very pretty; I just wanted to focus a bit on
|
107
|
+
the functionality. Tons of things are missing, such as
|
108
|
+
switching to other .yml files from within the GUI itself.
|
109
|
+
I just wanted to showcase a demo - the convert from
|
110
|
+
english-to-german functionality is working, though, so
|
111
|
+
the GUI is functional, even if not super-pretty.
|
112
|
+
|
113
|
+
In **February 2022** this was improved a little bit. It's still
|
114
|
+
not extremely pretty, but you can see a few small improvements.
|
115
|
+
In the long run I will add functionality to switch between
|
116
|
+
different .yml files (thus, different dictionaries, such as
|
117
|
+
english, italian and so forth) - but it is a hobby project.
|
118
|
+
I won't have enough time to add all dictionaries into this
|
119
|
+
project as-is. I will, however had, add the possibility to
|
120
|
+
load custom .yml files and other formats in the long run,
|
121
|
+
so others can adapt the project to suit their needs.
|
122
|
+
|
123
|
+
<img src="https://i.imgur.com/ChFJmfo.png" style="margin-left: 2em">
|
124
|
+
|
125
|
+
## sinatra
|
126
|
+
|
127
|
+
To start the sinatra interface of the dictionaries gem, do:
|
128
|
+
|
129
|
+
dictionaries --sinatra
|
130
|
+
|
131
|
+
You can then visit it on the localhost and it may look like
|
132
|
+
this:
|
133
|
+
|
134
|
+
<img src="https://i.imgur.com/uhzbXZ1.png" style="margin: 0.5em; margin-left: 2em">
|
135
|
+
|
136
|
+
You can then input an english word into the form, or the
|
137
|
+
URL area in your browser. If this word is registered in
|
138
|
+
the .yml file then the following result can be seen:
|
139
|
+
|
140
|
+
<img src="https://i.imgur.com/i1RqRmr.png" style="margin: 0.5em; margin-left: 2em">
|
141
|
+
|
142
|
+
This is really just very basic - I wanted to show the
|
143
|
+
functionality. You may have to adapt the code if you
|
144
|
+
have a more realistic use case, so consider the images
|
145
|
+
above just as examples of how this <b>could</b> be
|
146
|
+
used in a website.
|
147
|
+
|
148
|
+
## Generating a .pdf file containing the translations
|
149
|
+
|
150
|
+
Since as of <b>July 2022</b> you can generate a .pdf file
|
151
|
+
with all the translated words. This functionality depends
|
152
|
+
on the <b>prawn</b> gem right now, so make sure that
|
153
|
+
this gem is installed before invoking the ruby code
|
154
|
+
that generates the .pdf file.
|
155
|
+
|
156
|
+
The toplevel API for creating the .pdf file is as follows:
|
157
|
+
|
158
|
+
Dictionaries.generate_pdf_file
|
159
|
+
|
160
|
+
## Statistical information
|
161
|
+
|
162
|
+
On the <b>24.01.2023</b>, the Statistics submodule was
|
163
|
+
added towards module Dictionaries. The purpose of that
|
164
|
+
submodule is to simply display some information about
|
165
|
+
the project - in particular how many words are kept in
|
166
|
+
each individual .yml file (the yaml file that contains
|
167
|
+
all words in a given language).
|
168
|
+
|
169
|
+
For instance, on that day, the dictionaries gem contains
|
170
|
+
these word-translations in total:
|
171
|
+
|
172
|
+
chinese 15 words.
|
173
|
+
danish 1 words.
|
174
|
+
dutch 1 words.
|
175
|
+
english 2489 words.
|
176
|
+
farsi 4 words.
|
177
|
+
finnish 2 words.
|
178
|
+
italian 191 words.
|
179
|
+
japanese 2 words.
|
180
|
+
norwegian 5 words.
|
181
|
+
russian 3 words.
|
182
|
+
spanish 23 words.
|
183
|
+
swedish 1 words.
|
184
|
+
|
185
|
+
Expect more to be added over the coming months and years. As
|
186
|
+
can be seen english is the primary focus for this project,
|
187
|
+
in particular english-to-german and german-to-english.
|
188
|
+
|
189
|
+
Right now I am adding new entries manually for the most part,
|
190
|
+
but at a later point in time I may simply parse an existing
|
191
|
+
dictionary and then begin to add the missing entries more
|
192
|
+
systematically. Stay tuned for more information in this
|
193
|
+
regard in the future.
|
194
|
+
|
195
|
+
Since as of <b>May 2023</b> it is now possible to show how
|
196
|
+
many words are available per language file.
|
197
|
+
|
198
|
+
Use the following commandline invocation for this:
|
199
|
+
|
200
|
+
dictionaries --stats
|
201
|
+
dictionaries --statistics # both variants work
|
202
|
+
|
203
|
+
In <b>May 2023</b> the statistics were as follows:
|
204
|
+
|
205
|
+
chinese 15 words.
|
206
|
+
danish 1 words.
|
207
|
+
dutch 1 words.
|
208
|
+
english 2607 words.
|
209
|
+
farsi 4 words.
|
210
|
+
finnish 2 words.
|
211
|
+
italian 206 words.
|
212
|
+
japanese 2 words.
|
213
|
+
norwegian 5 words.
|
214
|
+
polish 1 words.
|
215
|
+
russian 3 words.
|
216
|
+
spanish 31 words.
|
217
|
+
swedish 1 words.
|
218
|
+
|
219
|
+
I may add to the above listing every some year or so, to
|
220
|
+
show how the project grows - and, also, in the event
|
221
|
+
that someone else may want to take over eventually.
|
222
|
+
|
223
|
+
## Standalone .html example
|
224
|
+
|
225
|
+
Since as of August 2023 there is a small example file under
|
226
|
+
test/, to show how the dictionary could be used on a webpage:
|
227
|
+
|
228
|
+
<img src="https://i.imgur.com/XgN6CTD.png">
|
229
|
+
|
230
|
+
Note that the word-list, in JavaScript, is auto-generated from ruby,
|
231
|
+
but not updated regularly. So this is more a proof of concept
|
232
|
+
as-is. In the long run functionality will be added to the
|
233
|
+
dictionaries gem to allow users to embed the javascript-hash
|
234
|
+
into a webpage. Dictionaries for everyone! \o/
|
235
|
+
|
236
|
+
## Why are there so few words registered in the dictionaries gem?
|
237
|
+
|
238
|
+
In August 2023, almost 3000 german-to-english words are registered
|
239
|
+
in the dictionaries gem. This is not a whole lot of words.
|
240
|
+
|
241
|
+
The main reason for this is that I manually add new entries, so
|
242
|
+
that takes time. I thus focus on my own use case.
|
243
|
+
|
244
|
+
However had, as I also want to make the dictionaries gem more
|
245
|
+
useful to other folks, I may begin to programmatically convert
|
246
|
+
entries, such as in the ding-dictionary, and integrate it into
|
247
|
+
the dictionaries gem. But for now this has to come at a later
|
248
|
+
time. This subsection was written in the event that people
|
249
|
+
are confused why there are so few words registered in this
|
250
|
+
project.
|
251
|
+
|
252
|
+
## SpellChecker
|
253
|
+
|
254
|
+
A new class was added in November 2023. This class can be used
|
255
|
+
to "spell check" against the distributed .yml file for english
|
256
|
+
words (to german).
|
257
|
+
|
258
|
+
This class can be found here:
|
259
|
+
|
260
|
+
require 'dictionaries/spell_checker/spell_checker.rb'
|
261
|
+
Dictionaries::SpellChecker.new(ARGV)
|
262
|
+
|
263
|
+
It is currently unfinished. In the long run I plan to have
|
264
|
+
this class support all entries in the distributed .yml file,
|
265
|
+
but this will probably take a few years, considering how
|
266
|
+
slow I am in regards to this project here. Nonetheless, others
|
267
|
+
can then expand on this functionality, such as by subclassing
|
268
|
+
class Dictionaries::SpellChecker eventually.
|
269
|
+
|
270
|
+
You can also add words that have to be ignored, into a file
|
271
|
+
called <b>IGNORE_THESE_WORDS.md</b> - which is treated as a
|
272
|
+
YAML file by class Dictionaries::SpellChecker. It has to
|
273
|
+
exist in the current working directory. If it does exist,
|
274
|
+
then it will be loaded and each entry there will become
|
275
|
+
a word that will be ignored by class Dictionaries::Spellchecker.
|
276
|
+
|
277
|
+
## Licence
|
278
|
+
|
279
|
+
Until the 17th of October 2019, this project was using the **GPLv2
|
280
|
+
licence** (no later clause).
|
281
|
+
|
282
|
+
However had, I believe that the GPLv2 licence is not great for
|
283
|
+
a project that focuses on existing words in **real languages**,
|
284
|
+
aka dictionaries. Thus, I have decided to change the licence into
|
285
|
+
the **MIT licence** on that day (**17.11.2019**, in dd.mm.yyyy notation).
|
286
|
+
|
287
|
+
So the gem is now MIT licenced. There may be dragons! \o/
|
288
|
+
|
289
|
+
For a description of that licence, see
|
290
|
+
https://opensource.org/licenses/MIT.
|
291
|
+
|
292
|
+
ADD_CONTACT_INFORMATION
|
data/doc/todo/todo.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
- Add italian, and GUI support for that.
|
2
|
+
|
3
|
+
- AND add stats to the main README, via macro or so,
|
4
|
+
aka "contains 5000 english words, 3000 italian
|
5
|
+
words" or so. Split by <br> I think.
|
6
|
+
|
7
|
+
- add an autoformatter, for the .yml files, so I no
|
8
|
+
longer have to do so manually.
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Dictionaries::AskEnglishWord
|
6
|
+
#
|
7
|
+
# Use this class to ask a random english word.
|
8
|
+
#
|
9
|
+
# There are two ways to use this class:
|
10
|
+
#
|
11
|
+
# - Pass in an optional argument to it, which we will use to query this
|
12
|
+
# word from the database.
|
13
|
+
#
|
14
|
+
# - Pass nothing to it, in which case we load a random entry.
|
15
|
+
#
|
16
|
+
# Specific usage examples:
|
17
|
+
#
|
18
|
+
# require 'dictionaries'
|
19
|
+
# Dictionaries::AskEnglishWord.new
|
20
|
+
# Dictionaries.ask_english_word
|
21
|
+
#
|
22
|
+
# =========================================================================== #
|
23
|
+
# require 'dictionaries/ask_english_word.rb'
|
24
|
+
# Dictionaries.path_to_the_english_file?
|
25
|
+
# =========================================================================== #
|
26
|
+
require 'dictionaries/class/class.rb'
|
27
|
+
|
28
|
+
module Dictionaries
|
29
|
+
|
30
|
+
class AskEnglishWord < AskWordFromDictionary
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === DATA
|
34
|
+
# ========================================================================= #
|
35
|
+
if defined?(DATA) == 'constant'
|
36
|
+
if DATA.respond_to? :read
|
37
|
+
_ = DATA.read
|
38
|
+
else
|
39
|
+
e 'DATA does not respond to :read'
|
40
|
+
end
|
41
|
+
else
|
42
|
+
_ = ''
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === DEFAULT_DELAY
|
47
|
+
# ========================================================================= #
|
48
|
+
if _.to_s.empty? # Next, define the default delay.
|
49
|
+
DEFAULT_DELAY = 2.2 # How long to wait before asking a question.
|
50
|
+
else
|
51
|
+
_ = _.first if _.is_a? Array
|
52
|
+
DEFAULT_DELAY = _.strip.to_f
|
53
|
+
end
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === AskEnglishWord::THIS_FILE
|
57
|
+
# ========================================================================= #
|
58
|
+
THIS_FILE = THIS_FILE_HERE = __FILE__.to_s
|
59
|
+
|
60
|
+
unless ENV['DICTIONARIES_FILE'] and File.exist?(ENV['DICTIONARIES_FILE'])
|
61
|
+
Dictionaries.set_main_file(THIS_FILE) # Assign it at once.
|
62
|
+
end
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === initialize
|
66
|
+
# ========================================================================= #
|
67
|
+
def initialize(
|
68
|
+
commandline_arguments = ARGV
|
69
|
+
)
|
70
|
+
super(commandline_arguments, self.class.main_file?)
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === Dictionaries::AskEnglishWord.main_file?
|
75
|
+
# ========================================================================= #
|
76
|
+
def self.main_file?
|
77
|
+
Dictionaries.main_file?
|
78
|
+
end
|
79
|
+
|
80
|
+
# ========================================================================= #
|
81
|
+
# === Dictionaries::AskEnglishWord.dataset?
|
82
|
+
#
|
83
|
+
# Note that this method will load the dataset from the main file anew
|
84
|
+
# whenever you invoke it.
|
85
|
+
# ========================================================================= #
|
86
|
+
def self.dataset?
|
87
|
+
YAML.load_file(self.main_file?)
|
88
|
+
end
|
89
|
+
|
90
|
+
# ========================================================================= #
|
91
|
+
# === Dictionaries::AskEnglishWord.n_entries?
|
92
|
+
#
|
93
|
+
# Feedback how many entries are registered.
|
94
|
+
# ========================================================================= #
|
95
|
+
def self.n_entries?
|
96
|
+
_ = dataset?
|
97
|
+
n_entries = _.size
|
98
|
+
return n_entries
|
99
|
+
end; self.instance_eval { alias n_questions? n_entries? } # === AskEnglishWord.n_questions?
|
100
|
+
|
101
|
+
# ========================================================================= #
|
102
|
+
# === Dictionaries::AskEnglishWord[]
|
103
|
+
# ========================================================================= #
|
104
|
+
def self.[](i = ARGV)
|
105
|
+
new(i)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
# =========================================================================== #
|
111
|
+
# === Dictionaries.ask_english_word
|
112
|
+
# =========================================================================== #
|
113
|
+
def self.ask_english_word
|
114
|
+
AskEnglishWord.new
|
115
|
+
end
|
116
|
+
|
117
|
+
# =========================================================================== #
|
118
|
+
# === Dictionaries.path_to_the_english_file?
|
119
|
+
#
|
120
|
+
# This method may return a String, as a file path, such as
|
121
|
+
# "/home/Programs/Ruby/2.7.2/lib/ruby/site_ruby/2.7.0/dictionaries/yaml/english.yml".
|
122
|
+
# =========================================================================== #
|
123
|
+
def self.path_to_the_english_file?
|
124
|
+
Dictionaries.main_file?
|
125
|
+
end
|
126
|
+
|
127
|
+
# =========================================================================== #
|
128
|
+
# === Dictionaries.n_entries?
|
129
|
+
# =========================================================================== #
|
130
|
+
def self.n_entries?
|
131
|
+
::Dictionaries::AskEnglishWord.n_entries?
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
if __FILE__ == $PROGRAM_NAME
|
137
|
+
Dictionaries::AskEnglishWord.new(ARGV)
|
138
|
+
end # askeng
|
139
|
+
# This is the delay to use for this class.
|
140
|
+
__END__
|
141
|
+
1.8
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# =========================================================================== #
|
4
|
+
# === Dictionaries::AskItalianWord
|
5
|
+
# =========================================================================== #
|
6
|
+
require 'dictionaries/class/class.rb'
|
7
|
+
|
8
|
+
module Dictionaries
|
9
|
+
|
10
|
+
class AskItalianWord < AskWordFromDictionary
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === DATA
|
14
|
+
# ========================================================================= #
|
15
|
+
if defined?(DATA) == 'constant'
|
16
|
+
if DATA.respond_to? :read
|
17
|
+
_ = DATA.read
|
18
|
+
else
|
19
|
+
e 'DATA does not respond to :read'
|
20
|
+
end
|
21
|
+
else
|
22
|
+
_ = ''
|
23
|
+
end
|
24
|
+
if _.to_s.empty? # Next, define the default delay.
|
25
|
+
DEFAULT_DELAY = 2.6 # How long to wait before asking a question.
|
26
|
+
else
|
27
|
+
_ = _.first if _.is_a? Array
|
28
|
+
DEFAULT_DELAY = _.strip.to_f
|
29
|
+
end
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === THIS_FILE
|
33
|
+
# ========================================================================= #
|
34
|
+
THIS_FILE = THIS_FILE_HERE = __FILE__.to_s
|
35
|
+
|
36
|
+
unless ENV['DICTIONARIES_FILE'] and File.exist?(ENV['DICTIONARIES_FILE'])
|
37
|
+
Dictionaries.set_main_file(THIS_FILE)
|
38
|
+
end
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === AskItalianWord.main_file?
|
42
|
+
# ========================================================================= #
|
43
|
+
def self.main_file?
|
44
|
+
Dictionaries.main_file?
|
45
|
+
end
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === AskItalianWord.dataset?
|
49
|
+
# ========================================================================= #
|
50
|
+
def self.dataset?
|
51
|
+
YAML.load_file(self.main_file?)
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === initialize
|
56
|
+
# ========================================================================= #
|
57
|
+
def initialize(commandline_arguments = ARGV)
|
58
|
+
super(commandline_arguments, self.class.main_file?)
|
59
|
+
end
|
60
|
+
|
61
|
+
# ========================================================================= #
|
62
|
+
# === AskItalianWord[]
|
63
|
+
# ========================================================================= #
|
64
|
+
def self.[](i)
|
65
|
+
self.new(i)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# =========================================================================== #
|
71
|
+
# === Dictionaries.ask_italian_word
|
72
|
+
# =========================================================================== #
|
73
|
+
def self.ask_italian_word
|
74
|
+
AskItalianWord.new
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
if __FILE__ == $PROGRAM_NAME
|
80
|
+
Dictionaries::AskItalianWord.new(ARGV)
|
81
|
+
end # askita
|
82
|
+
# This is the delay to use for this class.
|
83
|
+
__END__
|
84
|
+
2.2
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Dictionaries::Base
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'dictionaries/base/base.rb'
|
8
|
+
# class Foobar < Base
|
9
|
+
# =========================================================================== #
|
10
|
+
module Dictionaries
|
11
|
+
|
12
|
+
class Base # === Dictionaries::Base
|
13
|
+
|
14
|
+
require 'dictionaries/constants/constants.rb'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'colours'
|
18
|
+
include ::Colours
|
19
|
+
rescue LoadError; end
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'opn'
|
23
|
+
rescue LoadError; end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'open'
|
27
|
+
rescue LoadError; end
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === set_commandline_arguments
|
31
|
+
# ========================================================================= #
|
32
|
+
def set_commandline_arguments(i = '')
|
33
|
+
i = [i].flatten.compact
|
34
|
+
@commandline_arguments = i
|
35
|
+
end
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === commandline_arguments?
|
39
|
+
# ========================================================================= #
|
40
|
+
def commandline_arguments?
|
41
|
+
@commandline_arguments
|
42
|
+
end
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === first_argument?
|
46
|
+
# ========================================================================= #
|
47
|
+
def first_argument?
|
48
|
+
@commandline_arguments.first
|
49
|
+
end; alias first? first_argument? # === first?
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === reset (reset tag)
|
53
|
+
# ========================================================================= #
|
54
|
+
def reset
|
55
|
+
end
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === rev (rev tag)
|
59
|
+
# ========================================================================= #
|
60
|
+
def rev
|
61
|
+
::Colours.rev
|
62
|
+
end
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === sfancy
|
66
|
+
# ========================================================================= #
|
67
|
+
def sfancy(i)
|
68
|
+
::Colours.sfancy(i.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === opne
|
73
|
+
# ========================================================================= #
|
74
|
+
def opne(i = '')
|
75
|
+
opnn; e i
|
76
|
+
end
|
77
|
+
|
78
|
+
end; end
|