dictionaries 0.2.177

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 (44) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +103 -0
  3. data/bin/dictionaries +7 -0
  4. data/dictionaries.gemspec +85 -0
  5. data/doc/README.gen +86 -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 +672 -0
  10. data/lib/dictionaries/class/colours.rb +55 -0
  11. data/lib/dictionaries/class/set_search_for_this_word.rb +143 -0
  12. data/lib/dictionaries/commandline/parse_commandline.rb +60 -0
  13. data/lib/dictionaries/constants.rb +133 -0
  14. data/lib/dictionaries/gui/gtk/dictionary.rb +216 -0
  15. data/lib/dictionaries/gui/tk/README.md +2 -0
  16. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  17. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  18. data/lib/dictionaries/project/project_yaml_directory.rb +23 -0
  19. data/lib/dictionaries/require_project/require_project.rb +10 -0
  20. data/lib/dictionaries/sinatra/app.rb +93 -0
  21. data/lib/dictionaries/sinatra/english_to_german.rb +81 -0
  22. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  23. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  24. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  25. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  26. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  27. data/lib/dictionaries/toplevel_methods/misc.rb +42 -0
  28. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  29. data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
  30. data/lib/dictionaries/version/version.rb +17 -0
  31. data/lib/dictionaries/yaml/chinese.yml +19 -0
  32. data/lib/dictionaries/yaml/danish.yml +4 -0
  33. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  34. data/lib/dictionaries/yaml/dutch.yml +3 -0
  35. data/lib/dictionaries/yaml/english.yml +2247 -0
  36. data/lib/dictionaries/yaml/farsi.yml +8 -0
  37. data/lib/dictionaries/yaml/finnish.yml +2 -0
  38. data/lib/dictionaries/yaml/italian.yml +499 -0
  39. data/lib/dictionaries/yaml/japanese.yml +15 -0
  40. data/lib/dictionaries/yaml/portugese.yml +42 -0
  41. data/lib/dictionaries/yaml/russian.yml +10 -0
  42. data/lib/dictionaries/yaml/spanish.yml +126 -0
  43. data/lib/dictionaries/yaml/swedish.yml +113 -0
  44. metadata +204 -0
@@ -0,0 +1,2 @@
1
+ This directory includes experimental tk code. The main GUI is
2
+ ruby-gtk, so this is just a fallback.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::GUI::Tk::Dictionary
6
+ #
7
+ # This is a small TK-wrapper.
8
+ # =========================================================================== #
9
+ # require 'dictionaries/gui/tk/dictionary.rb'
10
+ # =========================================================================== #
11
+ begin
12
+ require 'tk'
13
+ rescue LoadError; end
14
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
15
+ require 'dictionaries/toplevel_methods/e.rb'
16
+
17
+ module Dictionaries
18
+
19
+ module GUI
20
+
21
+ module Tk
22
+
23
+ class Dictionary < ::TkFrame # < Base === Dictionaries::GUI::Tk::Dictionary.new
24
+
25
+ include Colours::E
26
+
27
+ # ========================================================================= #
28
+ # === initialize
29
+ # ========================================================================= #
30
+ def initialize(
31
+ i = nil,
32
+ run_already = true
33
+ )
34
+ super()
35
+ reset
36
+ set_input(i)
37
+ title "TK wrapper for the Dictionaries project"
38
+ run if run_already
39
+ end
40
+
41
+ # ========================================================================= #
42
+ # === reset (reset tag)
43
+ # ========================================================================= #
44
+ def reset
45
+ end
46
+
47
+ # ========================================================================= #
48
+ # === set_input
49
+ # ========================================================================= #
50
+ def set_input(i = '')
51
+ i = i.first if i.is_a? Array
52
+ i = i.to_s.dup
53
+ @input = i
54
+ end
55
+
56
+ # ========================================================================= #
57
+ # === input?
58
+ # ========================================================================= #
59
+ def input?
60
+ @input
61
+ end
62
+
63
+ # ========================================================================= #
64
+ # === run (run tag)
65
+ # ========================================================================= #
66
+ def run
67
+ TkLabel.new(root) do
68
+ text 'Hello, World!'
69
+ pack { padx 15 ; pady 15; side 'left' }
70
+ end
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === Dictionaries::GUI:Tk::Dictionary[]
75
+ # ========================================================================= #
76
+ def self.[](i = '')
77
+ self.new(i)
78
+ end
79
+
80
+ end; end; end; end
81
+
82
+ if __FILE__ == $PROGRAM_NAME
83
+ Dictionaries::GUI:Tk::Dictionary.new(ARGV)
84
+ ::Tk.mainloop
85
+ end # dictionary.rb
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/project/project_base_directory.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries::PROJECT_BASE_DIRECTORY
11
+ # ========================================================================= #
12
+ PROJECT_BASE_DIRECTORY =
13
+ File.absolute_path("#{__dir__}/..")+'/'
14
+
15
+ # ========================================================================= #
16
+ # === Dictionaries.project_base_dir?
17
+ # ========================================================================= #
18
+ def self.project_base_dir?
19
+ PROJECT_BASE_DIRECTORY
20
+ end
21
+
22
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file will point to the yaml directory of the Dictionaries project.
6
+ # =========================================================================== #
7
+ require 'dictionaries/project/project_base_directory.rb'
8
+
9
+ module Dictionaries # require 'dictionaries/project_base_directory.rb'
10
+
11
+ # ========================================================================= #
12
+ # === PROJECT_YAML_DIRECTORY
13
+ # ========================================================================= #
14
+ PROJECT_YAML_DIRECTORY = "#{PROJECT_BASE_DIRECTORY}yaml/"
15
+
16
+ # ========================================================================= #
17
+ # === Dictionaries.project_yaml_dir?
18
+ # ========================================================================= #
19
+ def self.project_yaml_dir?
20
+ PROJECT_YAML_DIRECTORY
21
+ end; self.instance_eval { alias dictionary_directory? project_yaml_dir? } # === Dictionaries.dictionary_directory?
22
+
23
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/ask_english_word.rb'
6
+ require 'dictionaries/ask_italian_word.rb'
7
+ require 'dictionaries/toplevel_methods/has_key.rb' # This file requires the files above.
8
+ require 'dictionaries/toplevel_methods/module_methods.rb'
9
+ require 'dictionaries/toplevel_methods/english_to_german.rb'
10
+ require 'dictionaries/toplevel_methods/is_on_roebe.rb'
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::Sinatra
6
+ # =========================================================================== #
7
+ # require 'dictionaries/sinatra/app.rb'
8
+ # =========================================================================== #
9
+ require 'sinatra/base.rb'
10
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
11
+ require 'dictionaries/toplevel_methods/is_on_roebe.rb'
12
+ require 'html_tags'
13
+ require 'dictionaries/sinatra/english_to_german.rb'
14
+
15
+ module Dictionaries
16
+
17
+ class Sinatra < ::Sinatra::Base
18
+
19
+ include Colours
20
+ include Colours::E
21
+ include HtmlTags::BaseModule
22
+
23
+ # ========================================================================= #
24
+ # === USE_THIS_PORT
25
+ # ========================================================================= #
26
+ USE_THIS_PORT = '5252'
27
+
28
+ set :port, USE_THIS_PORT
29
+
30
+ # ========================================================================= #
31
+ # === initialize
32
+ # ========================================================================= #
33
+ def initialize
34
+ super()
35
+ reset
36
+ if ::Dictionaries.is_on_roebe?
37
+ require 'open_in_browser'
38
+ # ===================================================================== #
39
+ # Tell us which port will be used:
40
+ # ===================================================================== #
41
+ target = "http://localhost:#{USE_THIS_PORT}/"
42
+ e sfancy(target)
43
+ Thread.new {
44
+ sleep 1.0
45
+ OpenInBrowser[target]
46
+ }
47
+ end
48
+ end
49
+
50
+ # ========================================================================= #
51
+ # === reset
52
+ # ========================================================================= #
53
+ def reset
54
+ end
55
+
56
+ # ========================================================================= #
57
+ # === / Entry point
58
+ #
59
+ # This is the root of our web-application.
60
+ # ========================================================================= #
61
+ get('/'){
62
+ html_header_default_title_and_start_of_the_body_tag+
63
+ p('Available translations:')+
64
+ a('/english_to_german')+
65
+ br+
66
+ a('/german_to_english')+
67
+ br
68
+ }
69
+
70
+ # ========================================================================= #
71
+ # === not_found
72
+ # ========================================================================= #
73
+ not_found {
74
+ p('This particular <b>API</b> was not found.')
75
+ }
76
+
77
+ end
78
+
79
+ # =========================================================================== #
80
+ # === Dictionaries.start_sinatra_interface
81
+ #
82
+ # This method can be used to start the sinatra interface.
83
+ # =========================================================================== #
84
+ def self.start_sinatra_interface
85
+ e 'Trying to start the sinatra-interface of the Dictionaries project.'
86
+ ::Dictionaries::Sinatra.run!
87
+ end
88
+
89
+ end
90
+
91
+ if __FILE__ == $PROGRAM_NAME
92
+ Dictionaries.start_sinatra_interface
93
+ end # dictionaries --sinatra
@@ -0,0 +1,81 @@
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
+ require 'sinatra/base.rb'
7
+
8
+ module Dictionaries
9
+
10
+ class Sinatra < ::Sinatra::Base
11
+
12
+ # ========================================================================= #
13
+ # === /english_to_german
14
+ #
15
+ # This is the root of our web-application.
16
+ # ========================================================================= #
17
+ get('/english_to_german'){
18
+ return_english_to_german_form
19
+ }
20
+
21
+ # ========================================================================= #
22
+ # === return_english_to_german_form
23
+ # ========================================================================= #
24
+ def return_english_to_german_form
25
+ route_to_this_action = '/english_to_german/'
26
+ html_header_default_title_and_start_of_the_body_tag+
27
+ h3('Input an english word next to see the translation.')+
28
+ div(css_style: 'padding: 0.1em') {
29
+ p(
30
+ '<b>Enter the word here:</b>', css_style: 'padding:0.15em'
31
+ )+
32
+ form(action: route_to_this_action, id: 'english_to_german', css_style: 'margin-left:1em; margin-top:2px') {
33
+ '<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
34
+ return_search_button
35
+ }
36
+ }
37
+ end
38
+
39
+ # ========================================================================= #
40
+ # === /english_to_german
41
+ #
42
+ # This is the root of our web-application.
43
+ # ========================================================================= #
44
+ get('/english_to_german/*'){
45
+ _ = params[:splat]
46
+ if params.has_key?('user_input')
47
+ _ = params.fetch('user_input')
48
+ end
49
+ _ = _.join if _.is_a? Array
50
+ translated_word = Dictionaries.english_to_german(_)
51
+ if translated_word
52
+ html_header_default_title_and_start_of_the_body_tag+
53
+ p('This translates to: '\
54
+ '<b style="font-size: larger; color: darkblue">'+translated_word+'</b>')+
55
+ br+
56
+ return_english_to_german_form
57
+ else
58
+ html_header_default_title_and_start_of_the_body_tag+
59
+ p('The key '+_.to_s+' is not registered in the Dictionaries word file.')
60
+ end
61
+ }
62
+
63
+ # ========================================================================= #
64
+ # === html_header_default_title_and_start_of_the_body_tag
65
+ # ========================================================================= #
66
+ def html_header_default_title_and_start_of_the_body_tag
67
+ "<html>\n"\
68
+ "<title>Dictionaries</title>\n"\
69
+ "<body>\n"
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === return_search_button
74
+ # ========================================================================= #
75
+ def return_search_button
76
+ '<input type="submit" name="user_input_submit" value="Search" '\
77
+ 'style="font-weight: bold; font-size: larger; '\
78
+ 'border: 2px dotted slateblue; margin: 4px">'
79
+ end
80
+
81
+ 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
+ require 'dictionaries/ask_english_word.rb'
9
+
10
+ module Dictionaries
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'
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