dictionaries 0.2.192
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 +164 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +85 -0
- data/doc/README.gen +136 -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 +60 -0
- data/lib/dictionaries/constants.rb +133 -0
- data/lib/dictionaries/gui/gtk2/dictionary.rb +36 -0
- data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +34 -0
- data/lib/dictionaries/gui/shared_code/dictionaries/dictionary_module.rb +393 -0
- data/lib/dictionaries/gui/tk/README.md +2 -0
- data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
- data/lib/dictionaries/project/project_base_directory.rb +22 -0
- data/lib/dictionaries/project/project_yaml_directory.rb +25 -0
- data/lib/dictionaries/require_project/require_project.rb +11 -0
- data/lib/dictionaries/sinatra/app.rb +105 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +82 -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 +129 -0
- data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
- data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
- data/lib/dictionaries/version/version.rb +17 -0
- data/lib/dictionaries/yaml/chinese.yml +21 -0
- data/lib/dictionaries/yaml/danish.yml +4 -0
- data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
- data/lib/dictionaries/yaml/dutch.yml +3 -0
- data/lib/dictionaries/yaml/english.yml +2427 -0
- data/lib/dictionaries/yaml/farsi.yml +8 -0
- data/lib/dictionaries/yaml/finnish.yml +2 -0
- data/lib/dictionaries/yaml/italian.yml +499 -0
- data/lib/dictionaries/yaml/japanese.yml +15 -0
- data/lib/dictionaries/yaml/portugese.yml +42 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +130 -0
- data/lib/dictionaries/yaml/swedish.yml +101 -0
- data/lib/dictionaries.rb +1 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 767b9f0c3307571e23fc6a40bfeef6ec14bf8d48b3648022f574cf7dbd02f8a7
|
4
|
+
data.tar.gz: 9271f8757304211c4719783035def6ab07f13ad721438d9bcd7686cfd9dce851
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf6816df052a55911ecfb50b3b62d43add64a548c9144cb4aff4ee5abb3a9ccc2fc87d61ba2e5c8cadf58da821818ee4d6a2b69de6274f9d1598eade8afc2e36
|
7
|
+
data.tar.gz: 9546ecf66e9bb0785e9de9863c66a6828177a5ed4eb3b3ff7c71fe6c11b5cb0ce0c5eff3c1cbedfac6ff43e0eefc98c34690a0303ee5054615cd7b660b183579
|
data/README.md
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
|
2
|
+
[![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dictionaries.svg)](https://badge.fury.io/rb/dictionaries)
|
4
|
+
|
5
|
+
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">05.10.2021</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">12:01:35</span> o'clock.
|
6
|
+
|
7
|
+
## Environment variable to use a specific yaml file
|
8
|
+
|
9
|
+
You can use an <b>environment variable</b> to denote the default
|
10
|
+
yaml file in use. This allows you to use your own yaml file
|
11
|
+
format, rather than the yaml files that are distributed with
|
12
|
+
this gem.
|
13
|
+
|
14
|
+
The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
|
15
|
+
It shall point to your yaml file that holds the key-value pairs.
|
16
|
+
|
17
|
+
For example, if your file is at /opt/czech.yml, then
|
18
|
+
DICTIONARIES_FILE should point at that location.
|
19
|
+
|
20
|
+
In bash, this may be equivalent to:
|
21
|
+
|
22
|
+
export DICTIONARIES_FILE=/opt/czech.yml
|
23
|
+
|
24
|
+
Note that in the long run, the dictionaries gem could be extended
|
25
|
+
with these yaml files - or allow means to download these files
|
26
|
+
over the www. But before we can do so, let's aim for at the least
|
27
|
+
100 words in such a file before we would consider distributing
|
28
|
+
it or offering means to distribute said file.
|
29
|
+
|
30
|
+
## sinatra
|
31
|
+
|
32
|
+
To start the sinatra interface of the dictionaries gem, do:
|
33
|
+
|
34
|
+
dictionaries --sinatra
|
35
|
+
|
36
|
+
## Difficult english sentences
|
37
|
+
|
38
|
+
English is not the most difficult language in the world, but when it
|
39
|
+
comes to proper pronounciation of words, english can be surprisingly
|
40
|
+
difficult.
|
41
|
+
|
42
|
+
This subsection may keep a listing of sentences that, for one reason
|
43
|
+
or the other, can be somewhat difficult to **read out aloud** without
|
44
|
+
mistake, on a first try. It is just a fun-subsection, not meant to be
|
45
|
+
taken too seriously; and it is quite subjective.
|
46
|
+
|
47
|
+
Without any further ado, here comes a listing of sentences that may
|
48
|
+
be difficult to pronounce properly so:
|
49
|
+
|
50
|
+
I would like to distribute something.
|
51
|
+
|
52
|
+
## Obtaining all translations into german for a given english word
|
53
|
+
|
54
|
+
Since as of **November 2020** the following API exists:
|
55
|
+
|
56
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('cat')
|
57
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('dog')
|
58
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('human')
|
59
|
+
|
60
|
+
This will return an Array of german names. It does not work 100% perfectly
|
61
|
+
as it is based on a regex; and using a regex to parse HTML is never a
|
62
|
+
trivial way. But if you just want to get the first entry, just call
|
63
|
+
.first on it, and in most cases this is the best, most likely
|
64
|
+
translation available.
|
65
|
+
|
66
|
+
The regex has to find matches to entries such as the following one:
|
67
|
+
|
68
|
+
</repr><words><word>der Jazzfan</word></words>
|
69
|
+
|
70
|
+
Anyone to come up with a more accurate regex is welcome to share it. :)
|
71
|
+
|
72
|
+
This functionality was specifically necessary because I needed to
|
73
|
+
use this in the ruby-gtk bindings for this project.
|
74
|
+
|
75
|
+
## Dictionaries.return_unique_words_from_this_file
|
76
|
+
|
77
|
+
This method will return all words that are presently not registered
|
78
|
+
in the english dictionary.
|
79
|
+
|
80
|
+
The idea here is for me to slowly add more english words into the
|
81
|
+
yaml file. I won't add every english word that exists, but I will
|
82
|
+
try to aim for a seizable number in the long run, such as
|
83
|
+
5000 english words - already halfway there. \o/
|
84
|
+
|
85
|
+
|
86
|
+
## GUI component
|
87
|
+
|
88
|
+
The **GUI component** of the dictionaries gem defaults to
|
89
|
+
**GTK3** finally. It is not a very advanced GUI, though.
|
90
|
+
|
91
|
+
First, install the gtk3 gem:
|
92
|
+
|
93
|
+
gem install gtk3
|
94
|
+
|
95
|
+
Then install the gtk_paradise project:
|
96
|
+
|
97
|
+
gem install gtk_paradise
|
98
|
+
|
99
|
+
Now you should be able to start the GUI component if the above
|
100
|
+
has worked:
|
101
|
+
|
102
|
+
dictionaries --gui
|
103
|
+
|
104
|
+
See also the help options.
|
105
|
+
|
106
|
+
dictionaries --help
|
107
|
+
|
108
|
+
You may need to install some .h files if you use a specific
|
109
|
+
Linux distribution; look at the relevant -dev packages for
|
110
|
+
this. Or just compile from source. :)
|
111
|
+
|
112
|
+
The current version of ruby-gtk3 in October 2021 looks like
|
113
|
+
this:
|
114
|
+
|
115
|
+
<img src="https://i.imgur.com/K430Kae.png" style="margin-left: 2em">
|
116
|
+
|
117
|
+
Yes, this isn't very pretty; I just wanted to focus a bit on
|
118
|
+
the functionality. Tons of things are missing, such as
|
119
|
+
switching to other .yml files from within the GUI itself.
|
120
|
+
I just wanted to showcase a demo - the convert from
|
121
|
+
english-to-german functionality is working, though, so
|
122
|
+
the GUI is functional, even if not super-pretty.
|
123
|
+
|
124
|
+
## Licence
|
125
|
+
|
126
|
+
Until the 17th of October 2019, this project was using the GPLv2
|
127
|
+
licence (no later clause).
|
128
|
+
|
129
|
+
However had, I believe that the GPLv2 licence is not great for
|
130
|
+
a project that focuses on existing words in real languages, aka
|
131
|
+
dictionaries. Thus, I have decided to change the licence into
|
132
|
+
the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
|
133
|
+
|
134
|
+
So the gem is now MIT licenced. \o/
|
135
|
+
|
136
|
+
For a description of that licence, see
|
137
|
+
https://opensource.org/licenses/MIT.
|
138
|
+
|
139
|
+
|
140
|
+
## Contact information
|
141
|
+
|
142
|
+
If your creative mind has ideas and specific suggestions to make this
|
143
|
+
gem more useful in general, feel free to drop me an email at any
|
144
|
+
time, via:
|
145
|
+
|
146
|
+
shevy@inbox.lt
|
147
|
+
|
148
|
+
Before that email I used an email account at Google gmail, but in **2021** I
|
149
|
+
decided to slowly abandon gmail for various reasons. In part this is because
|
150
|
+
the UI annoys me (on non-chrome browser loading takes too long), but also
|
151
|
+
because of Google's attempt to establish mass surveillance via its
|
152
|
+
federated cohorts sniffing (FLoC). I do not know what happened at Google,
|
153
|
+
but enough is enough - there is only so much you can take while supporting
|
154
|
+
greed. When it comes to data mining done by private groups, ultimately
|
155
|
+
the user became the product.
|
156
|
+
|
157
|
+
Do keep in mind that responding to emails may take some time,
|
158
|
+
depending on the amount of work I may have at that moment, due
|
159
|
+
to reallife time constraints. I will, however had, read feedback
|
160
|
+
eventually. Patches and code changes are welcome too, of course,
|
161
|
+
as long as they are in the spirit of the project at hand, e. g.
|
162
|
+
fitting to the general theme. For this I may make use of github
|
163
|
+
as a discussion site, but this has a low priority right now.
|
164
|
+
|
data/bin/dictionaries
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Project Dictionaries.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'dictionaries'
|
5
|
+
require 'roebe'
|
6
|
+
|
7
|
+
Gem::Specification.new { |s|
|
8
|
+
|
9
|
+
s.name = 'dictionaries'
|
10
|
+
s.version = Dictionaries::VERSION
|
11
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
12
|
+
|
13
|
+
DESCRIPTION = <<-EOF
|
14
|
+
|
15
|
+
This project is called dictionaries.
|
16
|
+
|
17
|
+
It used to be called ask_english_words but the name was changed towards
|
18
|
+
"dictionaries", when the focus became on dictionaries in general rather
|
19
|
+
than merely translations from and to the english language.
|
20
|
+
|
21
|
+
There are a total of #{Dictionaries.n_entries?} english words
|
22
|
+
registered, with the associated german translation. (It is
|
23
|
+
german primarily because that is my native language, but in
|
24
|
+
principle this project could be extended to include other
|
25
|
+
languages as well. You only need to add a yaml file containing
|
26
|
+
the key-value pairs.)
|
27
|
+
|
28
|
+
If you need a more comprehensive dictionary, I can recommend
|
29
|
+
the file de-en.txt that is part of the tu-chemnitz
|
30
|
+
distribution ( https://www-user.tu-chemnitz.de/~fri/ding/ ). That
|
31
|
+
file is really huge - about 20 MB.
|
32
|
+
|
33
|
+
In principle, the dictionaries project could be extended to
|
34
|
+
make use of that massive file instead. I will be thinking
|
35
|
+
about this for the time being (starting at July 2018).
|
36
|
+
|
37
|
+
EOF
|
38
|
+
|
39
|
+
s.summary = DESCRIPTION
|
40
|
+
s.description = DESCRIPTION
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# Show this message when a user installs this project.
|
44
|
+
# ========================================================================= #
|
45
|
+
s.post_install_message = <<-EOF
|
46
|
+
|
47
|
+
This project can ask or translate english or italian words (or words
|
48
|
+
from any other language, as long as a .yml file is supplied that
|
49
|
+
contains these key-value pair entries).
|
50
|
+
|
51
|
+
This project is probably not very useful for other people, but it helps
|
52
|
+
me to improve my knowledge about the english or italian language or
|
53
|
+
any other language.
|
54
|
+
|
55
|
+
For more information, have a look at the main README.md file, which
|
56
|
+
can also be found on the hompage of this gem at rubygems.org, on
|
57
|
+
the bottom right side (see https://www.rubydoc.info/gems/dictionaries/ ).
|
58
|
+
|
59
|
+
EOF
|
60
|
+
|
61
|
+
s.extra_rdoc_files = %w()
|
62
|
+
|
63
|
+
s.authors = ['Robert A. Heiler']
|
64
|
+
s.email = Roebe.email?
|
65
|
+
s.files = Dir['**/*']
|
66
|
+
# s.files << 'README.md'
|
67
|
+
# s.files << 'USAGE.md'
|
68
|
+
s.license = 'MIT'
|
69
|
+
s.homepage = 'https://www.rubydoc.info/gems/dictionaries/'
|
70
|
+
|
71
|
+
s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
|
72
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
73
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
74
|
+
|
75
|
+
# ========================================================================= #
|
76
|
+
# External dependencies for the project:
|
77
|
+
# ========================================================================= #
|
78
|
+
s.add_dependency 'colours'
|
79
|
+
s.add_dependency 'generate_shell_completion'
|
80
|
+
s.add_dependency 'opn'
|
81
|
+
s.add_dependency 'open'
|
82
|
+
s.add_dependency 'save_file'
|
83
|
+
s.add_dependency 'xorg_buffer'
|
84
|
+
|
85
|
+
}
|
data/doc/README.gen
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
ADD_RUBY_BADGE
|
2
|
+
ADD_TIME_STAMP
|
3
|
+
|
4
|
+
## Environment variable to use a specific yaml file
|
5
|
+
|
6
|
+
You can use an <b>environment variable</b> to denote the default
|
7
|
+
yaml file in use. This allows you to use your own yaml file
|
8
|
+
format, rather than the yaml files that are distributed with
|
9
|
+
this gem.
|
10
|
+
|
11
|
+
The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
|
12
|
+
It shall point to your yaml file that holds the key-value pairs.
|
13
|
+
|
14
|
+
For example, if your file is at /opt/czech.yml, then
|
15
|
+
DICTIONARIES_FILE should point at that location.
|
16
|
+
|
17
|
+
In bash, this may be equivalent to:
|
18
|
+
|
19
|
+
export DICTIONARIES_FILE=/opt/czech.yml
|
20
|
+
|
21
|
+
Note that in the long run, the dictionaries gem could be extended
|
22
|
+
with these yaml files - or allow means to download these files
|
23
|
+
over the www. But before we can do so, let's aim for at the least
|
24
|
+
100 words in such a file before we would consider distributing
|
25
|
+
it or offering means to distribute said file.
|
26
|
+
|
27
|
+
## sinatra
|
28
|
+
|
29
|
+
To start the sinatra interface of the dictionaries gem, do:
|
30
|
+
|
31
|
+
dictionaries --sinatra
|
32
|
+
|
33
|
+
## Difficult english sentences
|
34
|
+
|
35
|
+
English is not the most difficult language in the world, but when it
|
36
|
+
comes to proper pronounciation of words, english can be surprisingly
|
37
|
+
difficult.
|
38
|
+
|
39
|
+
This subsection may keep a listing of sentences that, for one reason
|
40
|
+
or the other, can be somewhat difficult to **read out aloud** without
|
41
|
+
mistake, on a first try. It is just a fun-subsection, not meant to be
|
42
|
+
taken too seriously; and it is quite subjective.
|
43
|
+
|
44
|
+
Without any further ado, here comes a listing of sentences that may
|
45
|
+
be difficult to pronounce properly so:
|
46
|
+
|
47
|
+
I would like to distribute something.
|
48
|
+
|
49
|
+
## Obtaining all translations into german for a given english word
|
50
|
+
|
51
|
+
Since as of **November 2020** the following API exists:
|
52
|
+
|
53
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('cat')
|
54
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('dog')
|
55
|
+
Dictionaries.return_array_of_translated_words_from_online_leo('human')
|
56
|
+
|
57
|
+
This will return an Array of german names. It does not work 100% perfectly
|
58
|
+
as it is based on a regex; and using a regex to parse HTML is never a
|
59
|
+
trivial way. But if you just want to get the first entry, just call
|
60
|
+
.first on it, and in most cases this is the best, most likely
|
61
|
+
translation available.
|
62
|
+
|
63
|
+
The regex has to find matches to entries such as the following one:
|
64
|
+
|
65
|
+
</repr><words><word>der Jazzfan</word></words>
|
66
|
+
|
67
|
+
Anyone to come up with a more accurate regex is welcome to share it. :)
|
68
|
+
|
69
|
+
This functionality was specifically necessary because I needed to
|
70
|
+
use this in the ruby-gtk bindings for this project.
|
71
|
+
|
72
|
+
## Dictionaries.return_unique_words_from_this_file
|
73
|
+
|
74
|
+
This method will return all words that are presently not registered
|
75
|
+
in the english dictionary.
|
76
|
+
|
77
|
+
The idea here is for me to slowly add more english words into the
|
78
|
+
yaml file. I won't add every english word that exists, but I will
|
79
|
+
try to aim for a seizable number in the long run, such as
|
80
|
+
5000 english words - already halfway there. \o/
|
81
|
+
|
82
|
+
|
83
|
+
## GUI component
|
84
|
+
|
85
|
+
The **GUI component** of the dictionaries gem defaults to
|
86
|
+
**GTK3** finally. It is not a very advanced GUI, though.
|
87
|
+
|
88
|
+
First, install the gtk3 gem:
|
89
|
+
|
90
|
+
gem install gtk3
|
91
|
+
|
92
|
+
Then install the gtk_paradise project:
|
93
|
+
|
94
|
+
gem install gtk_paradise
|
95
|
+
|
96
|
+
Now you should be able to start the GUI component if the above
|
97
|
+
has worked:
|
98
|
+
|
99
|
+
dictionaries --gui
|
100
|
+
|
101
|
+
See also the help options.
|
102
|
+
|
103
|
+
dictionaries --help
|
104
|
+
|
105
|
+
You may need to install some .h files if you use a specific
|
106
|
+
Linux distribution; look at the relevant -dev packages for
|
107
|
+
this. Or just compile from source. :)
|
108
|
+
|
109
|
+
The current version of ruby-gtk3 in October 2021 looks like
|
110
|
+
this:
|
111
|
+
|
112
|
+
<img src="https://i.imgur.com/K430Kae.png" style="margin-left: 2em">
|
113
|
+
|
114
|
+
Yes, this isn't very pretty; I just wanted to focus a bit on
|
115
|
+
the functionality. Tons of things are missing, such as
|
116
|
+
switching to other .yml files from within the GUI itself.
|
117
|
+
I just wanted to showcase a demo - the convert from
|
118
|
+
english-to-german functionality is working, though, so
|
119
|
+
the GUI is functional, even if not super-pretty.
|
120
|
+
|
121
|
+
## Licence
|
122
|
+
|
123
|
+
Until the 17th of October 2019, this project was using the GPLv2
|
124
|
+
licence (no later clause).
|
125
|
+
|
126
|
+
However had, I believe that the GPLv2 licence is not great for
|
127
|
+
a project that focuses on existing words in real languages, aka
|
128
|
+
dictionaries. Thus, I have decided to change the licence into
|
129
|
+
the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
|
130
|
+
|
131
|
+
So the gem is now MIT licenced. \o/
|
132
|
+
|
133
|
+
For a description of that licence, see
|
134
|
+
https://opensource.org/licenses/MIT.
|
135
|
+
|
136
|
+
ADD_CONTACT_INFORMATION
|
@@ -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/ask_word_from_dictionary.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)
|
105
|
+
self.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/ask_word_from_dictionary.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
|