dictionaries 0.2.184

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 (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +136 -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 +119 -0
  7. data/lib/dictionaries.rb +1 -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 +60 -0
  15. data/lib/dictionaries/constants.rb +133 -0
  16. data/lib/dictionaries/gui/gtk2/dictionary.rb +36 -0
  17. data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +34 -0
  18. data/lib/dictionaries/gui/shared_code/dictionaries/dictionary_module.rb +362 -0
  19. data/lib/dictionaries/gui/tk/README.md +2 -0
  20. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  21. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  22. data/lib/dictionaries/project/project_yaml_directory.rb +25 -0
  23. data/lib/dictionaries/require_project/require_project.rb +11 -0
  24. data/lib/dictionaries/sinatra/app.rb +102 -0
  25. data/lib/dictionaries/sinatra/english_to_german.rb +82 -0
  26. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  27. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  28. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  29. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  30. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  31. data/lib/dictionaries/toplevel_methods/misc.rb +123 -0
  32. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  33. data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
  34. data/lib/dictionaries/version/version.rb +17 -0
  35. data/lib/dictionaries/yaml/chinese.yml +21 -0
  36. data/lib/dictionaries/yaml/danish.yml +4 -0
  37. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  38. data/lib/dictionaries/yaml/dutch.yml +3 -0
  39. data/lib/dictionaries/yaml/english.yml +2328 -0
  40. data/lib/dictionaries/yaml/farsi.yml +8 -0
  41. data/lib/dictionaries/yaml/finnish.yml +2 -0
  42. data/lib/dictionaries/yaml/italian.yml +499 -0
  43. data/lib/dictionaries/yaml/japanese.yml +15 -0
  44. data/lib/dictionaries/yaml/portugese.yml +42 -0
  45. data/lib/dictionaries/yaml/russian.yml +10 -0
  46. data/lib/dictionaries/yaml/spanish.yml +128 -0
  47. data/lib/dictionaries/yaml/swedish.yml +101 -0
  48. metadata +208 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 543e04679b80ce72082208e97783a6df1cacd35371410a86a1394d2a66614efe
4
+ data.tar.gz: 96d6192afb769000399a4f3425b2417421acc231b9480a90602ec9eaa5e0ec2b
5
+ SHA512:
6
+ metadata.gz: 7013aadc2d6a56e90e94f58b1606cc8842790d9da60df19b6a54a407a46d24736a6c943bc6ef57d3ec4c07475e3d59fa5b26e8ffc6d77425ba37f245f555f315
7
+ data.tar.gz: bcdef37d043a0a63883745682850e4f8bebeb95fa1442b8b1ee36af3d487e191c0456e57a3645ad2e22629c55fa4d63f413142ffd20af46f51d5ca372babba4a
data/README.md ADDED
@@ -0,0 +1,136 @@
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
+ ## GUI component
6
+
7
+ The **GUI component** of the dictionaries gem currently
8
+ defaults to **GTK2**.
9
+
10
+ It is in a very early, incomplete beta stage.
11
+
12
+ First, install the gtk2 gem:
13
+
14
+ gem install gtk2
15
+
16
+ Then install the gtk_module:
17
+
18
+ gem install gtk_module
19
+
20
+ Now you can start the GUI component:
21
+
22
+ dictionaries --gui
23
+
24
+ See also the help options.
25
+
26
+ dictionaries --help
27
+
28
+ ## Environment variable to use a specific yaml file
29
+
30
+ You can use an <b>environment variable</b> to denote the default
31
+ yaml file in use. This allows you to use your own yaml file
32
+ format, rather than the yaml files that are distributed with
33
+ this gem.
34
+
35
+ The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
36
+ It shall point to your yaml file that holds the key-value pairs.
37
+
38
+ For example, if your file is at /opt/czech.yml, then
39
+ DICTIONARIES_FILE should point at that location.
40
+
41
+ In bash, this may be equivalent to:
42
+
43
+ export DICTIONARIES_FILE=/opt/czech.yml
44
+
45
+ Note that in the long run, the dictionaries gem could be extended
46
+ with these yaml files - or allow means to download these files
47
+ over the www. But before we can do so, let's aim for at the least
48
+ 100 words in such a file before we would consider distributing
49
+ it or offering means to distribute said file.
50
+
51
+ ## sinatra
52
+
53
+ To start the sinatra interface, do:
54
+
55
+ dictionaries --sinatra
56
+
57
+ ## Difficult english sentences
58
+
59
+ English is not the most difficult language in the world, but when it
60
+ comes to proper pronounciation of words, english can be surprisingly
61
+ difficult.
62
+
63
+ This subsection may keep a listing of sentences that, for one reason
64
+ or the other, can be somewhat difficult to **read out aloud** without
65
+ mistake, on a first try. It is just a fun-subsection, not meant to be
66
+ taken too seriously; and it is quite subjective.
67
+
68
+ Without any further ado, here comes a listing of sentences that may
69
+ be difficult to pronounce properly so:
70
+
71
+ I would like to distribute something.
72
+
73
+ ## Obtaining all translations into german for a given english word
74
+
75
+ Since as of November 2020 the following API exists:
76
+
77
+ Dictionaries.return_array_of_translated_words_from_online_leo('cat')
78
+ Dictionaries.return_array_of_translated_words_from_online_leo('dog')
79
+ Dictionaries.return_array_of_translated_words_from_online_leo('human')
80
+
81
+ This will return an Array of german names. It does not work 100% perfectly
82
+ as it is based on a regex; and using a regex to parse HTML is never a
83
+ trivial way. But if you just want to get the first entry, just call
84
+ .first on it, and in most cases this is the best, most likely
85
+ translation available.
86
+
87
+ The regex has to find matches to entries such as the following one:
88
+
89
+ </repr><words><word>der Jazzfan</word></words>
90
+
91
+ Anyone to come up with a more accurate regex is welcome to share it. :)
92
+
93
+ This functionality was specifically necessary because I needed to
94
+ use this in the ruby-gtk bindings for this project.
95
+
96
+ ## Dictionaries.return_unique_words_from_this_file
97
+
98
+ This method will return all words that are presently not registered
99
+ in the english dictionary.
100
+
101
+ The idea here is for me to slowly add more english words into the
102
+ yaml file. I won't add every english word that exists, but I will
103
+ try to aim for a seizable number in the long run, such as
104
+ 5000 english words - already halfway there. \o/
105
+
106
+ ## Licence
107
+
108
+ Until the 17th of October 2019, this project was using the GPLv2
109
+ licence (no later clause).
110
+
111
+ However had, I believe that the GPLv2 licence is not great for
112
+ a project that focuses on existing words in real languages, aka
113
+ dictionaries. Thus, I have decided to change the licence into
114
+ the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
115
+
116
+ So the gem is now MIT licenced. \o/
117
+
118
+ For a description of that licence, see
119
+ https://opensource.org/licenses/MIT.
120
+
121
+
122
+ ## Contact information
123
+
124
+ If your creative mind has ideas and specific suggestions to make this
125
+ gem more useful in general, feel free to drop me an email at any
126
+ time, via:
127
+
128
+ shevegen@gmail.com
129
+
130
+ (Do keep in mind that responding to emails may take some time, depending
131
+ on the amount of work I may have at that moment, due to reallife. I will,
132
+ however had, read feedback. Patches and code changes are welcome too
133
+ of course, as long as they are in the spirit of the project at
134
+ hand, e. g. fitting to the general theme.)
135
+
136
+ Thank you.
data/bin/dictionaries ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'dictionaries'
6
+
7
+ Dictionaries.parse_commandline(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'dictionaries'
6
+
7
+ pp Dictionaries.return_unique_words_from_this_file(ARGV)
@@ -0,0 +1,85 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Dictionaries.
3
+ # =========================================================================== #
4
+ require 'dictionaries/ask_english_word.rb'
5
+ require 'dictionaries/version/version.rb'
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 = 'shevegen@gmail.com'
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 = '>= '+RUBY_VERSION
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_in_browser'
82
+ s.add_dependency 'save_file'
83
+ s.add_dependency 'xorg_buffer'
84
+
85
+ }
data/doc/README.gen ADDED
@@ -0,0 +1,119 @@
1
+ ADD_RUBY_BADGE
2
+
3
+ ## GUI component
4
+
5
+ The **GUI component** of the dictionaries gem currently
6
+ defaults to **GTK2**.
7
+
8
+ It is in a very early, incomplete beta stage.
9
+
10
+ First, install the gtk2 gem:
11
+
12
+ gem install gtk2
13
+
14
+ Then install the gtk_module:
15
+
16
+ gem install gtk_module
17
+
18
+ Now you can start the GUI component:
19
+
20
+ dictionaries --gui
21
+
22
+ See also the help options.
23
+
24
+ dictionaries --help
25
+
26
+ ## Environment variable to use a specific yaml file
27
+
28
+ You can use an <b>environment variable</b> to denote the default
29
+ yaml file in use. This allows you to use your own yaml file
30
+ format, rather than the yaml files that are distributed with
31
+ this gem.
32
+
33
+ The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
34
+ It shall point to your yaml file that holds the key-value pairs.
35
+
36
+ For example, if your file is at /opt/czech.yml, then
37
+ DICTIONARIES_FILE should point at that location.
38
+
39
+ In bash, this may be equivalent to:
40
+
41
+ export DICTIONARIES_FILE=/opt/czech.yml
42
+
43
+ Note that in the long run, the dictionaries gem could be extended
44
+ with these yaml files - or allow means to download these files
45
+ over the www. But before we can do so, let's aim for at the least
46
+ 100 words in such a file before we would consider distributing
47
+ it or offering means to distribute said file.
48
+
49
+ ## sinatra
50
+
51
+ To start the sinatra interface, do:
52
+
53
+ dictionaries --sinatra
54
+
55
+ ## Difficult english sentences
56
+
57
+ English is not the most difficult language in the world, but when it
58
+ comes to proper pronounciation of words, english can be surprisingly
59
+ difficult.
60
+
61
+ This subsection may keep a listing of sentences that, for one reason
62
+ or the other, can be somewhat difficult to **read out aloud** without
63
+ mistake, on a first try. It is just a fun-subsection, not meant to be
64
+ taken too seriously; and it is quite subjective.
65
+
66
+ Without any further ado, here comes a listing of sentences that may
67
+ be difficult to pronounce properly so:
68
+
69
+ I would like to distribute something.
70
+
71
+ ## Obtaining all translations into german for a given english word
72
+
73
+ Since as of November 2020 the following API exists:
74
+
75
+ Dictionaries.return_array_of_translated_words_from_online_leo('cat')
76
+ Dictionaries.return_array_of_translated_words_from_online_leo('dog')
77
+ Dictionaries.return_array_of_translated_words_from_online_leo('human')
78
+
79
+ This will return an Array of german names. It does not work 100% perfectly
80
+ as it is based on a regex; and using a regex to parse HTML is never a
81
+ trivial way. But if you just want to get the first entry, just call
82
+ .first on it, and in most cases this is the best, most likely
83
+ translation available.
84
+
85
+ The regex has to find matches to entries such as the following one:
86
+
87
+ </repr><words><word>der Jazzfan</word></words>
88
+
89
+ Anyone to come up with a more accurate regex is welcome to share it. :)
90
+
91
+ This functionality was specifically necessary because I needed to
92
+ use this in the ruby-gtk bindings for this project.
93
+
94
+ ## Dictionaries.return_unique_words_from_this_file
95
+
96
+ This method will return all words that are presently not registered
97
+ in the english dictionary.
98
+
99
+ The idea here is for me to slowly add more english words into the
100
+ yaml file. I won't add every english word that exists, but I will
101
+ try to aim for a seizable number in the long run, such as
102
+ 5000 english words - already halfway there. \o/
103
+
104
+ ## Licence
105
+
106
+ Until the 17th of October 2019, this project was using the GPLv2
107
+ licence (no later clause).
108
+
109
+ However had, I believe that the GPLv2 licence is not great for
110
+ a project that focuses on existing words in real languages, aka
111
+ dictionaries. Thus, I have decided to change the licence into
112
+ the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
113
+
114
+ So the gem is now MIT licenced. \o/
115
+
116
+ For a description of that licence, see
117
+ https://opensource.org/licenses/MIT.
118
+
119
+ ADD_CONTACT_INFORMATION
@@ -0,0 +1 @@
1
+ require 'dictionaries/require_project/require_project.rb'
@@ -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