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.

Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +164 -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 +136 -0
  7. data/lib/dictionaries/ask_english_word.rb +141 -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/gtk2/dictionary.rb +36 -0
  16. data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +34 -0
  17. data/lib/dictionaries/gui/shared_code/dictionaries/dictionary_module.rb +393 -0
  18. data/lib/dictionaries/gui/tk/README.md +2 -0
  19. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  20. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  21. data/lib/dictionaries/project/project_yaml_directory.rb +25 -0
  22. data/lib/dictionaries/require_project/require_project.rb +11 -0
  23. data/lib/dictionaries/sinatra/app.rb +105 -0
  24. data/lib/dictionaries/sinatra/english_to_german.rb +82 -0
  25. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  26. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  27. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  28. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  29. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  30. data/lib/dictionaries/toplevel_methods/misc.rb +129 -0
  31. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  32. data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
  33. data/lib/dictionaries/version/version.rb +17 -0
  34. data/lib/dictionaries/yaml/chinese.yml +21 -0
  35. data/lib/dictionaries/yaml/danish.yml +4 -0
  36. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  37. data/lib/dictionaries/yaml/dutch.yml +3 -0
  38. data/lib/dictionaries/yaml/english.yml +2427 -0
  39. data/lib/dictionaries/yaml/farsi.yml +8 -0
  40. data/lib/dictionaries/yaml/finnish.yml +2 -0
  41. data/lib/dictionaries/yaml/italian.yml +499 -0
  42. data/lib/dictionaries/yaml/japanese.yml +15 -0
  43. data/lib/dictionaries/yaml/portugese.yml +42 -0
  44. data/lib/dictionaries/yaml/russian.yml +10 -0
  45. data/lib/dictionaries/yaml/spanish.yml +130 -0
  46. data/lib/dictionaries/yaml/swedish.yml +101 -0
  47. data/lib/dictionaries.rb +1 -0
  48. metadata +208 -0
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'sinatra/base.rb'
6
+
7
+ module Dictionaries
8
+
9
+ class Sinatra < ::Sinatra::Base
10
+
11
+ require 'dictionaries/toplevel_methods/english_to_german.rb'
12
+
13
+ # ========================================================================= #
14
+ # === /english_to_german
15
+ #
16
+ # This is the root of our web-application.
17
+ # ========================================================================= #
18
+ get('/english_to_german'){
19
+ return_english_to_german_form
20
+ }
21
+
22
+ # ========================================================================= #
23
+ # === return_english_to_german_form
24
+ # ========================================================================= #
25
+ def return_english_to_german_form
26
+ route_to_this_action = '/english_to_german/'
27
+ html_header_default_title_and_start_of_the_body_tag+
28
+ h3('Input an english word next to see the translation.')+
29
+ div(css_style: 'padding: 0.1em') {
30
+ p(
31
+ '<b>Enter the word here:</b>', css_style: 'padding:0.15em'
32
+ )+
33
+ form(action: route_to_this_action, id: 'english_to_german', css_style: 'margin-left:1em; margin-top:2px') {
34
+ '<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
35
+ return_search_button
36
+ }
37
+ }
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === /english_to_german
42
+ #
43
+ # This is the root of our web-application.
44
+ # ========================================================================= #
45
+ get('/english_to_german/*'){
46
+ _ = params[:splat]
47
+ if params.has_key?('user_input')
48
+ _ = params.fetch('user_input')
49
+ end
50
+ _ = _.join if _.is_a? Array
51
+ translated_word = Dictionaries.english_to_german(_)
52
+ if translated_word
53
+ html_header_default_title_and_start_of_the_body_tag+
54
+ p('This translates to: '\
55
+ '<b style="font-size: larger; color: darkblue">'+translated_word+'</b>')+
56
+ br+
57
+ return_english_to_german_form
58
+ else
59
+ html_header_default_title_and_start_of_the_body_tag+
60
+ p('The key '+_.to_s+' is not registered in the Dictionaries word file.')
61
+ end
62
+ }
63
+
64
+ # ========================================================================= #
65
+ # === html_header_default_title_and_start_of_the_body_tag
66
+ # ========================================================================= #
67
+ def html_header_default_title_and_start_of_the_body_tag
68
+ "<html>\n"\
69
+ "<title>Dictionaries</title>\n"\
70
+ "<body>\n"
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === return_search_button
75
+ # ========================================================================= #
76
+ def return_search_button
77
+ '<input type="submit" name="user_input_submit" value="Search" '\
78
+ 'style="font-weight: bold; font-size: larger; '\
79
+ 'border: 2px dotted slateblue; margin: 4px">'
80
+ end
81
+
82
+ end; end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/e.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries.e
11
+ # ========================================================================= #
12
+ def self.e(i = '')
13
+ puts i
14
+ end
15
+
16
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/english_to_german.rb'
6
+ # =========================================================================== #
7
+ require 'dictionaries/toplevel_methods/has_key.rb'
8
+ require 'dictionaries/toplevel_methods/misc.rb'
9
+
10
+ module Dictionaries
11
+
12
+ # ========================================================================= #
13
+ # === Dictionaries.english_to_german
14
+ #
15
+ # This method will return nil if the key has not been found in the
16
+ # Dictionaries dataset.
17
+ # ========================================================================= #
18
+ def self.english_to_german(i)
19
+ i = i.join.strip if i.is_a? Array
20
+ converted_word = nil
21
+ if Dictionaries.has_key? i
22
+ converted_word = Dictionaries[i]
23
+ end
24
+ converted_word
25
+ end; self.instance_eval { alias translate_this_from_english_to_german english_to_german } # === Dictionaries.translate_this_from_english_to_german
26
+
27
+ end
28
+
29
+ if __FILE__ == $PROGRAM_NAME
30
+ pp Dictionaries.english_to_german(ARGV)
31
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/has_key.rb'
6
+ # Dictionaries.has_key?
7
+ # =========================================================================== #
8
+ module Dictionaries
9
+
10
+ require 'dictionaries/ask_english_word.rb'
11
+
12
+ # ========================================================================= #
13
+ # === Dictionaries.has_key?
14
+ #
15
+ # Query whether the main file of the Dictionaries namespace, has the
16
+ # given input key at hand.
17
+ #
18
+ # Returns:
19
+ # true if the key is included
20
+ # false otherwise
21
+ #
22
+ # Invocation examples:
23
+ #
24
+ # Dictionaries.has_key? 'apprehensions' # => true
25
+ # Dictionaries.has_key? 'apprehensio'
26
+ #
27
+ # ========================================================================= #
28
+ def self.has_key?(this_key)
29
+ Dictionaries::AskEnglishWord.dataset?.has_key?(this_key)
30
+ end
31
+
32
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/is_on_roebe.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries.is_on_roebe?
11
+ # ========================================================================= #
12
+ def self.is_on_roebe?
13
+ (ENV['IS_ROEBE'].to_s == '1')
14
+ end
15
+
16
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/main_file.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === @main_file
11
+ #
12
+ # This module-level instance variable keeps track of the main file in
13
+ # use.
14
+ # ========================================================================= #
15
+ @main_file = nil
16
+
17
+ # ========================================================================= #
18
+ # === DICTIONARIES_FILE
19
+ #
20
+ # Add support for the environment variable DICTIONARIES_FILE here.
21
+ # ========================================================================= #
22
+ if ENV['DICTIONARIES_FILE'] and
23
+ File.exist?(ENV['DICTIONARIES_FILE'])
24
+ @main_file = ENV['DICTIONARIES_FILE'].to_s
25
+ end
26
+
27
+ # ========================================================================= #
28
+ # === Dictionaries.return_name_from_compound
29
+ #
30
+ # This method will return 'italian' if the input is 'ask_italian_word'.
31
+ # ========================================================================= #
32
+ def self.return_name_from_compound(
33
+ i = Dictionaries.main_file?
34
+ )
35
+ i = i.to_s
36
+ i = File.basename(i).gsub(/.rb/, '').gsub(/.yml/, '')
37
+ if i.include? '_'
38
+ i = i.split('_')[1] # Grab the middle part here.
39
+ end
40
+ i
41
+ end
42
+
43
+ # ========================================================================= #
44
+ # === Dictionaries.set_main_file
45
+ #
46
+ # Use this method to designate the main yaml file which should contain
47
+ # the language-specific translations.
48
+ #
49
+ # If the input includes a '/' token and also ends with '.rb' then we
50
+ # assume that it may be in the form of this:
51
+ #
52
+ # /Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/dictionaries/lib/dictionaries/ask_italian_word.rb
53
+ #
54
+ # So we will instead use the second part of the last part.
55
+ #
56
+ # Usage example:
57
+ #
58
+ # Dictionaries.set_main_file(THIS_FILE)
59
+ #
60
+ # ========================================================================= #
61
+ def self.set_main_file(i = :default_file)
62
+ case i
63
+ when :default_file,
64
+ :default
65
+ i = FILE_ENGLISH_WORDS
66
+ end
67
+ if i.include? '/'
68
+ if i.end_with? '.rb'
69
+ i = File.basename(i).sub(/.rb^/,'')
70
+ if i.include? '_'
71
+ i = Dictionaries.return_name_from_compound(i) # Grab the middle part here.
72
+ i = DICTIONARIES_DIR+i+'.yml'
73
+ end
74
+ end
75
+ end
76
+ @main_file = i
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === Dictionaries.main_file?
81
+ #
82
+ # Query method over the @main_file module-level instance variable.
83
+ # ========================================================================= #
84
+ def self.main_file?
85
+ @main_file
86
+ end; self.instance_eval { alias main_file main_file? } # === Dictionaries.main_file
87
+
88
+ end
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/misc.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ require 'yaml'
10
+ require 'dictionaries/constants.rb'
11
+ require 'dictionaries/toplevel_methods/main_file.rb'
12
+ require 'dictionaries/toplevel_methods/has_key.rb'
13
+
14
+ # ========================================================================= #
15
+ # === Dictionaries[]
16
+ #
17
+ # Currently this method will always reload the main file. In the future
18
+ # we may change this approach, but for now this has to suffice (May 2019).
19
+ #
20
+ # The method will return either the translated string - or nil. Nil
21
+ # indicates that the main Hash does not include that key; in other words,
22
+ # that the word is not registered.
23
+ # ========================================================================= #
24
+ def self.[](i = ARGV)
25
+ i = i.join.strip if i.is_a? Array
26
+ this_file = Dictionaries.main_file?
27
+ if this_file.nil?
28
+ Dictionaries.set_main_file(:default) # Must initialize it in this case.
29
+ this_file = Dictionaries.main_file?
30
+ end
31
+ if this_file
32
+ dataset = YAML.load_file(this_file)
33
+ dataset[i] # Return the result here.
34
+ else
35
+ nil
36
+ end
37
+ end
38
+
39
+ # ========================================================================= #
40
+ # === Dictionaries.return_array_of_translated_words_from_online_leo
41
+ #
42
+ # This method can be used to query the online dictionary from leo.
43
+ #
44
+ # It will then return an Array of translations.
45
+ #
46
+ # Note that this currently only works for the translation from english
47
+ # to german, not the other way around, even though that is not too
48
+ # hard to implement either.
49
+ # ========================================================================= #
50
+ def self.return_array_of_translated_words_from_online_leo(this_word)
51
+ if this_word.is_a? Array
52
+ this_word = this_word.join(' ').strip
53
+ end
54
+ require 'open-uri'
55
+ remote_url = "https://dict.leo.org/german-english/#{this_word}"
56
+ remote_dataset = URI.open(remote_url).read
57
+ # ======================================================================= #
58
+ # See: https://rubular.com/r/OOXwAc6PVqjU5Q
59
+ # ======================================================================= #
60
+ use_this_regex =
61
+ /<words><word>([a-zA-Z\s]+)\<\/word><\/words>/
62
+ scanned_results = remote_dataset.scan(use_this_regex).flatten
63
+ # ======================================================================= #
64
+ # This result may look like so:
65
+ # [["cat"], ["die Katze"]
66
+ # We have to sanitize it still.
67
+ # ======================================================================= #
68
+ scanned_results.reject! {|entry| entry.start_with?(this_word) }
69
+ return scanned_results # Note that the full Array is returned.
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === Dictionaries.return_unique_words_from_this_file
74
+ #
75
+ # This method will read in the words from an existing local file.
76
+ #
77
+ # Some files may be huge, though, and then this method becomes
78
+ # quite useless, so we really should discard a lot of data after a
79
+ # certain threshold, to keep memory usage low.
80
+ # ========================================================================= #
81
+ def self.return_unique_words_from_this_file(
82
+ this_file,
83
+ optional_arguments = :english
84
+ )
85
+ dataset = nil
86
+ if this_file.is_a? Array
87
+ this_file = this_file.join(' ').strip
88
+ end
89
+ if this_file and File.file?(this_file)
90
+ dataset = File.read(this_file)
91
+ end
92
+ result = [] # ← This variable will store the unique words found in the file.
93
+ case optional_arguments
94
+ # ======================================================================= #
95
+ # === :english
96
+ # ======================================================================= #
97
+ when :english,
98
+ :default
99
+ # ===================================================================== #
100
+ # Query unknown words in english. We will compare the words to the
101
+ # available variants.
102
+ # ===================================================================== #
103
+ result = dataset.scan(/\w+/).map {|entry| entry.downcase } # ← Obtain all words here.
104
+ # ===================================================================== #
105
+ # Next, reject those that are registered:
106
+ # ===================================================================== #
107
+ result.reject! {|this_word|
108
+ ::Dictionaries.has_key?(this_word)
109
+ }
110
+ end if dataset
111
+ return result.uniq.sort
112
+ end
113
+
114
+ end
115
+
116
+ if __FILE__ == $PROGRAM_NAME
117
+ alias e puts
118
+ #puts Dictionaries[ARGV]
119
+ e 'Possible words for cat:'
120
+ pp Dictionaries.return_array_of_translated_words_from_online_leo('cat')
121
+ # ========================================================================= #
122
+ # The next chunk of code is to test reading unique words from a given
123
+ # local file.
124
+ # ========================================================================= #
125
+ puts '-'*80
126
+ _ = Dictionaries.return_unique_words_from_this_file('/Depot/j/foobar.md')
127
+ pp _
128
+ pp _.size
129
+ end # rb misc.rb cat
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Just bundle together some requires through this file here.
6
+ # =========================================================================== #
7
+ require 'dictionaries/commandline/parse_commandline.rb'
8
+ require 'dictionaries/toplevel_methods/e.rb'
9
+ require 'dictionaries/toplevel_methods/show_help.rb'
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/toplevel_methods/show_help.rb'
6
+ # =========================================================================== #
7
+ require 'dictionaries/toplevel_methods/e.rb'
8
+
9
+ module Dictionaries
10
+
11
+ # ========================================================================= #
12
+ # === Dictionaries.show_help
13
+ #
14
+ # To invoke this, try:
15
+ #
16
+ # dictionaries --help
17
+ #
18
+ # ========================================================================= #
19
+ def self.show_help
20
+ help_string = <<EOF
21
+ These options are currently available:
22
+
23
+ --n_words? # Show how many words are available
24
+ --gui # Start the GTK GUI; aliases exist to this, such as --gtk
25
+
26
+ EOF
27
+ e help_string
28
+ end
29
+
30
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module Dictionaries
6
+
7
+ # ========================================================================= #
8
+ # === VERSION
9
+ # ========================================================================= #
10
+ VERSION = '0.2.192'
11
+
12
+ # ========================================================================= #
13
+ # === LAST_UPDATE
14
+ # ========================================================================= #
15
+ LAST_UPDATE = '05.10.2021'
16
+
17
+ end
@@ -0,0 +1,21 @@
1
+ # =========================================================================== #
2
+ # === chinese.yml
3
+ #
4
+ # CHINESE or MANDARIN - Singlish,Singaporean Slang TAG
5
+ # rf dict chinese
6
+ # =========================================================================== #
7
+ nie hau: hallo
8
+ hao: ja/gut
9
+ Ganbao: gewonnen
10
+ shije: schwester
11
+ wobazaju: i dont care
12
+ budumo: dont touch it
13
+ buyaotawo: "Dont hit me." bu yao ta wo
14
+ sian: boring
15
+ dao: Weg
16
+ chai: Tee
17
+ wei: "hallo"?
18
+ shue: ja
19
+ shü-she: ~ja, in ordnung. Danke
20
+ yang: Sonne
21
+ sei tschien: auf wiedersehen
@@ -0,0 +1,4 @@
1
+ # List danish resources.
2
+
3
+ # s tig
4
+ smil: lächeln
@@ -0,0 +1 @@
1
+ elegisch: klagend # added 19.10.2003
@@ -0,0 +1,3 @@
1
+
2
+ # k tig
3
+ kopen: kaufen (to buy)