dictionaries 0.2.179

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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +126 -0
  3. data/bin/dictionaries +7 -0
  4. data/dictionaries.gemspec +85 -0
  5. data/doc/README.gen +109 -0
  6. data/lib/dictionaries.rb +1 -0
  7. data/lib/dictionaries/ask_english_word.rb +135 -0
  8. data/lib/dictionaries/ask_italian_word.rb +84 -0
  9. data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
  10. data/lib/dictionaries/class/colours.rb +55 -0
  11. data/lib/dictionaries/class/constants.rb +16 -0
  12. data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
  13. data/lib/dictionaries/commandline/parse_commandline.rb +60 -0
  14. data/lib/dictionaries/constants.rb +133 -0
  15. data/lib/dictionaries/gui/gtk/constants.rb +25 -0
  16. data/lib/dictionaries/gui/gtk/dictionary.rb +330 -0
  17. data/lib/dictionaries/gui/tk/README.md +2 -0
  18. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  19. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  20. data/lib/dictionaries/project/project_yaml_directory.rb +23 -0
  21. data/lib/dictionaries/require_project/require_project.rb +10 -0
  22. data/lib/dictionaries/sinatra/app.rb +100 -0
  23. data/lib/dictionaries/sinatra/english_to_german.rb +81 -0
  24. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  25. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  26. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  27. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  28. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  29. data/lib/dictionaries/toplevel_methods/misc.rb +76 -0
  30. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  31. data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
  32. data/lib/dictionaries/version/version.rb +17 -0
  33. data/lib/dictionaries/yaml/chinese.yml +19 -0
  34. data/lib/dictionaries/yaml/danish.yml +4 -0
  35. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  36. data/lib/dictionaries/yaml/dutch.yml +3 -0
  37. data/lib/dictionaries/yaml/english.yml +2259 -0
  38. data/lib/dictionaries/yaml/farsi.yml +8 -0
  39. data/lib/dictionaries/yaml/finnish.yml +2 -0
  40. data/lib/dictionaries/yaml/italian.yml +499 -0
  41. data/lib/dictionaries/yaml/japanese.yml +15 -0
  42. data/lib/dictionaries/yaml/portugese.yml +42 -0
  43. data/lib/dictionaries/yaml/russian.yml +10 -0
  44. data/lib/dictionaries/yaml/spanish.yml +128 -0
  45. data/lib/dictionaries/yaml/swedish.yml +113 -0
  46. metadata +205 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59d7db82b51fa115bb50828cee0fb7216c0bde3195e93a431cfe56e14e0c4d77
4
+ data.tar.gz: 7717f0f6b66610bfe912b51cab2dad7d012b3430ba366b7963b0d1ba5bbb1c3e
5
+ SHA512:
6
+ metadata.gz: 8cf53b70fe499b6b6a454551dc0f2b20c9accb18c5b3e2ec582c86708528461188c43ba74c18431c726e221af82b2fcdb072a6dbd35d55ab3d927f72710ba736
7
+ data.tar.gz: 0f4a88949ae5554f9c863ce56bc44002b061ac58a3b851aedb70ab87312c24e227c7656aacec037359a40cf8af0b430d9e75833544b0e5e562957f74b6c552b4
@@ -0,0 +1,126 @@
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
+ ## Licence
97
+
98
+ Until the 17th of October 2019, this project was using the GPLv2
99
+ licence (no later clause).
100
+
101
+ However had, I believe that the GPLv2 licence is not great for
102
+ a project that focuses on existing words in real languages, aka
103
+ dictionaries. Thus, I have decided to change the licence into
104
+ the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
105
+
106
+ So the gem is now MIT licenced. \o/
107
+
108
+ For a description of that licence, see
109
+ https://opensource.org/licenses/MIT.
110
+
111
+
112
+ ## Contact information
113
+
114
+ If your creative mind has ideas and specific suggestions to make this
115
+ gem more useful in general, feel free to drop me an email at any
116
+ time, via:
117
+
118
+ shevegen@gmail.com
119
+
120
+ (Do keep in mind that responding to emails may take some time, depending
121
+ on the amount of work I may have at that moment, due to reallife. I will,
122
+ however had, read feedback. Patches and code changes are welcome too
123
+ of course, as long as they are in the spirit of the project at
124
+ hand, e. g. fitting to the general theme.)
125
+
126
+ Thank you.
@@ -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,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
+ }
@@ -0,0 +1,109 @@
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
+ ## Licence
95
+
96
+ Until the 17th of October 2019, this project was using the GPLv2
97
+ licence (no later clause).
98
+
99
+ However had, I believe that the GPLv2 licence is not great for
100
+ a project that focuses on existing words in real languages, aka
101
+ dictionaries. Thus, I have decided to change the licence into
102
+ the MIT licence on that day (17.11.2019, in dd.mm.yyyy notation).
103
+
104
+ So the gem is now MIT licenced. \o/
105
+
106
+ For a description of that licence, see
107
+ https://opensource.org/licenses/MIT.
108
+
109
+ ADD_CONTACT_INFORMATION
@@ -0,0 +1 @@
1
+ require 'dictionaries/require_project/require_project.rb'
@@ -0,0 +1,135 @@
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
+ # require 'dictionaries'
18
+ # Dictionaries::AskEnglishWord.new
19
+ # Dictionaries.ask_english_word
20
+ # =========================================================================== #
21
+ # require 'dictionaries/ask_english_word.rb'
22
+ # =========================================================================== #
23
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
24
+
25
+ module Dictionaries
26
+
27
+ class AskEnglishWord < AskWordFromDictionary
28
+
29
+ # ========================================================================= #
30
+ # === DATA
31
+ # ========================================================================= #
32
+ if defined?(DATA) == 'constant'
33
+ if DATA.respond_to? :read
34
+ _ = DATA.read
35
+ else
36
+ e 'DATA does not respond to :read'
37
+ end
38
+ else
39
+ _ = ''
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === DEFAULT_DELAY
44
+ # ========================================================================= #
45
+ if _.to_s.empty? # Next, define the default delay.
46
+ DEFAULT_DELAY = 2.2 # How long to wait before asking a question.
47
+ else
48
+ _ = _.first if _.is_a? Array
49
+ DEFAULT_DELAY = _.strip.to_f
50
+ end
51
+
52
+ # ========================================================================= #
53
+ # === AskEnglishWord::THIS_FILE
54
+ # ========================================================================= #
55
+ THIS_FILE = THIS_FILE_HERE = __FILE__.to_s
56
+
57
+ unless ENV['DICTIONARIES_FILE'] and File.exist?(ENV['DICTIONARIES_FILE'])
58
+ Dictionaries.set_main_file(THIS_FILE) # Assign it at once.
59
+ end
60
+
61
+ # ========================================================================= #
62
+ # === initialize
63
+ # ========================================================================= #
64
+ def initialize(
65
+ commandline_arguments = ARGV
66
+ )
67
+ super(commandline_arguments, self.class.main_file?)
68
+ end
69
+
70
+ # ========================================================================= #
71
+ # === Dictionaries::AskEnglishWord.main_file?
72
+ # ========================================================================= #
73
+ def self.main_file?
74
+ Dictionaries.main_file?
75
+ end
76
+
77
+ # ========================================================================= #
78
+ # === Dictionaries::AskEnglishWord.dataset?
79
+ #
80
+ # Note that this method will load the dataset from the main file anew
81
+ # whenever you invoke it.
82
+ # ========================================================================= #
83
+ def self.dataset?
84
+ YAML.load_file(self.main_file?)
85
+ end
86
+
87
+ # ========================================================================= #
88
+ # === Dictionaries::AskEnglishWord.n_entries?
89
+ #
90
+ # Feedback how many entries are registered.
91
+ # ========================================================================= #
92
+ def self.n_entries?
93
+ _ = dataset?
94
+ n_entries = _.size
95
+ return n_entries
96
+ end; self.instance_eval { alias n_questions? n_entries? } # === AskEnglishWord.n_questions?
97
+
98
+ # ========================================================================= #
99
+ # === Dictionaries::AskEnglishWord[]
100
+ # ========================================================================= #
101
+ def self.[](i)
102
+ self.new(i)
103
+ end
104
+
105
+ end
106
+
107
+ # =========================================================================== #
108
+ # === Dictionaries.ask_english_word
109
+ # =========================================================================== #
110
+ def self.ask_english_word
111
+ AskEnglishWord.new
112
+ end
113
+
114
+ # =========================================================================== #
115
+ # === Dictionaries.path_to_the_english_file?
116
+ # =========================================================================== #
117
+ def self.path_to_the_english_file?
118
+ Dictionaries.main_file?
119
+ end
120
+
121
+ # =========================================================================== #
122
+ # === Dictionaries.n_entries?
123
+ # =========================================================================== #
124
+ def self.n_entries?
125
+ ::Dictionaries::AskEnglishWord.n_entries?
126
+ end
127
+
128
+ end
129
+
130
+ if __FILE__ == $PROGRAM_NAME
131
+ Dictionaries::AskEnglishWord.new(ARGV)
132
+ end # askeng
133
+ # This is the delay to use for this class.
134
+ __END__
135
+ 1.8