dictionaries 0.3.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dictionaries might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +354 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +84 -0
- data/doc/README.gen +292 -0
- data/doc/todo/todo.md +8 -0
- data/lib/dictionaries/ask_english_word.rb +141 -0
- data/lib/dictionaries/ask_italian_word.rb +84 -0
- data/lib/dictionaries/base/base.rb +78 -0
- data/lib/dictionaries/class/class.rb +903 -0
- data/lib/dictionaries/commandline/parse_commandline.rb +85 -0
- data/lib/dictionaries/constants/constants.rb +134 -0
- data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +457 -0
- data/lib/dictionaries/gui/tk/README.md +2 -0
- data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
- data/lib/dictionaries/helper_module/helper_module.rb +60 -0
- data/lib/dictionaries/project/project.rb +36 -0
- data/lib/dictionaries/require_project/require_project.rb +14 -0
- data/lib/dictionaries/sinatra/app.rb +123 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
- data/lib/dictionaries/spell_checker/README.md +5 -0
- data/lib/dictionaries/spell_checker/spell_checker.rb +133 -0
- data/lib/dictionaries/statistics/statistics.rb +59 -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 +231 -0
- data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
- data/lib/dictionaries/toplevel_methods/show_help.rb +31 -0
- data/lib/dictionaries/version/version.rb +19 -0
- data/lib/dictionaries/yaml/chinese.yml +25 -0
- data/lib/dictionaries/yaml/danish.yml +4 -0
- data/lib/dictionaries/yaml/deutsche_fremdw/303/266rter.yml +1 -0
- data/lib/dictionaries/yaml/dutch.yml +3 -0
- data/lib/dictionaries/yaml/english.yml +3157 -0
- data/lib/dictionaries/yaml/farsi.yml +8 -0
- data/lib/dictionaries/yaml/finnish.yml +2 -0
- data/lib/dictionaries/yaml/italian.yml +532 -0
- data/lib/dictionaries/yaml/japanese.yml +15 -0
- data/lib/dictionaries/yaml/norwegian.yml +26 -0
- data/lib/dictionaries/yaml/polish.yml +2 -0
- data/lib/dictionaries/yaml/portugese.yml +41 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +147 -0
- data/lib/dictionaries/yaml/swedish.yml +104 -0
- data/lib/dictionaries.rb +1 -0
- data/test/translation_example.html +2758 -0
- metadata +211 -0
@@ -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/class.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,60 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/helper_module/helper_module.rb'
|
6
|
+
# include Dictionaries::HelperModule
|
7
|
+
# =========================================================================== #
|
8
|
+
module Dictionaries
|
9
|
+
|
10
|
+
module HelperModule
|
11
|
+
|
12
|
+
require 'html_tags'
|
13
|
+
include HtmlTags
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === Dictionaries::HelperModule.return_search_button
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.return_search_button
|
19
|
+
'<input type="submit" name="user_input_submit" value="Search" '\
|
20
|
+
'style="font-weight: bold; font-size: larger; '\
|
21
|
+
'border: 2px dotted slateblue; margin: 4px; margin-left: 2em">'
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === Dictionaries::HelperModule.html_header_default_title_and_start_of_the_body_tag
|
26
|
+
# ========================================================================= #
|
27
|
+
def self.html_header_default_title_and_start_of_the_body_tag
|
28
|
+
"<html>\n"\
|
29
|
+
"<title>Dictionaries</title>\n"\
|
30
|
+
"<body>\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === Dictionaries::HelperModule.return_english_to_german_form
|
35
|
+
# ========================================================================= #
|
36
|
+
def self.return_english_to_german_form
|
37
|
+
route_to_this_action = '/english_to_german/'
|
38
|
+
html_header_default_title_and_start_of_the_body_tag+
|
39
|
+
HtmlTags.h5('Input an english word to see the translation.')+
|
40
|
+
HtmlTags.div(css_style: 'padding: 0.1em') {
|
41
|
+
HtmlTags.p(
|
42
|
+
'<b>Enter the word here:</b>',
|
43
|
+
css_style: 'padding: 0.15em'
|
44
|
+
)+
|
45
|
+
HtmlTags.form(action: route_to_this_action,
|
46
|
+
id: 'english_to_german',
|
47
|
+
css_style: 'margin-left:1em; margin-top:2px') {
|
48
|
+
'<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
|
49
|
+
return_search_button
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end; end
|
55
|
+
|
56
|
+
if __FILE__ == $PROGRAM_NAME
|
57
|
+
alias e puts
|
58
|
+
include Dictionaries::HelperModule
|
59
|
+
e Dictionaries::HelperModule.return_english_to_german_form
|
60
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
module Dictionaries
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === Dictionaries::PROJECT_BASE_DIRECTORY
|
13
|
+
# ========================================================================= #
|
14
|
+
PROJECT_BASE_DIRECTORY =
|
15
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === Dictionaries.project_base_dir?
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.project_base_dir?
|
21
|
+
PROJECT_BASE_DIRECTORY
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === PROJECT_YAML_DIRECTORY
|
26
|
+
# ========================================================================= #
|
27
|
+
PROJECT_YAML_DIRECTORY = "#{PROJECT_BASE_DIRECTORY}yaml/"
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === Dictionaries.project_yaml_dir?
|
31
|
+
# ========================================================================= #
|
32
|
+
def self.project_yaml_dir?
|
33
|
+
PROJECT_YAML_DIRECTORY
|
34
|
+
end; self.instance_eval { alias dictionary_directory? project_yaml_dir? } # === Dictionaries.dictionary_directory?
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/require_project/require_project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'dictionaries/project/project.rb'
|
8
|
+
require 'dictionaries/ask_italian_word.rb'
|
9
|
+
require 'dictionaries/toplevel_methods/has_key.rb' # This file requires the files above.
|
10
|
+
require 'dictionaries/toplevel_methods/module_methods.rb'
|
11
|
+
require 'dictionaries/toplevel_methods/english_to_german.rb'
|
12
|
+
require 'dictionaries/toplevel_methods/is_on_roebe.rb'
|
13
|
+
require 'dictionaries/sinatra/app.rb'
|
14
|
+
require 'dictionaries/statistics/statistics.rb'
|
@@ -0,0 +1,123 @@
|
|
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
|
+
begin
|
10
|
+
|
11
|
+
require 'sinatra/base.rb'
|
12
|
+
|
13
|
+
module Dictionaries
|
14
|
+
|
15
|
+
class Sinatra < ::Sinatra::Base
|
16
|
+
|
17
|
+
require 'dictionaries/class/class.rb'
|
18
|
+
require 'dictionaries/toplevel_methods/is_on_roebe.rb'
|
19
|
+
require 'dictionaries/sinatra/english_to_german.rb'
|
20
|
+
|
21
|
+
include ::Colours
|
22
|
+
include ::Colours::E
|
23
|
+
begin
|
24
|
+
require 'html_tags'
|
25
|
+
include HtmlTags::BaseModule
|
26
|
+
rescue LoadError; end
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === USE_THIS_PORT
|
30
|
+
# ========================================================================= #
|
31
|
+
USE_THIS_PORT = '5252'
|
32
|
+
|
33
|
+
set :port, USE_THIS_PORT
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === initialize
|
37
|
+
# ========================================================================= #
|
38
|
+
def initialize(
|
39
|
+
i = ARGV
|
40
|
+
)
|
41
|
+
super()
|
42
|
+
reset
|
43
|
+
consider_opening_the_page_in_the_browser(i)
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === reset (reset tag)
|
48
|
+
# ========================================================================= #
|
49
|
+
def reset
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === consider_opening_the_page_in_the_browser
|
54
|
+
# ========================================================================= #
|
55
|
+
def consider_opening_the_page_in_the_browser(
|
56
|
+
shall_we_open_the_page_in_the_browser = ::Dictionaries.is_on_roebe?
|
57
|
+
)
|
58
|
+
case shall_we_open_the_page_in_the_browser
|
59
|
+
# ======================================================================= #
|
60
|
+
# === :do_not_open_in_the_browser
|
61
|
+
# ======================================================================= #
|
62
|
+
when :do_not_open_in_the_browser,
|
63
|
+
:dont_connect,
|
64
|
+
:dont
|
65
|
+
shall_we_open_the_page_in_the_browser = false
|
66
|
+
end
|
67
|
+
if shall_we_open_the_page_in_the_browser
|
68
|
+
begin
|
69
|
+
require 'open'
|
70
|
+
rescue LoadError; end
|
71
|
+
# ===================================================================== #
|
72
|
+
# Tell us which port will be used:
|
73
|
+
# ===================================================================== #
|
74
|
+
target = "http://localhost:#{USE_THIS_PORT}/"
|
75
|
+
e sfancy(target)
|
76
|
+
Thread.new {
|
77
|
+
sleep 0.8
|
78
|
+
Open.in_browser(target)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === / Entry point
|
85
|
+
#
|
86
|
+
# This is the root of our web-application.
|
87
|
+
# ========================================================================= #
|
88
|
+
get('/'){
|
89
|
+
html_header_default_title_and_start_of_the_body_tag+
|
90
|
+
p('The following translation-tables are available:')+
|
91
|
+
HtmlTags.a('/english_to_german', css_style: 'margin-left: 2em')+
|
92
|
+
br+
|
93
|
+
HtmlTags.a('/german_to_english', css_style: 'margin-left: 2em')+
|
94
|
+
br
|
95
|
+
}
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === not_found
|
99
|
+
# ========================================================================= #
|
100
|
+
not_found {
|
101
|
+
p('This particular <b>API</b> was not found.')
|
102
|
+
}
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
# =========================================================================== #
|
107
|
+
# === Dictionaries.start_sinatra_interface
|
108
|
+
#
|
109
|
+
# This method can be used to start the sinatra interface.
|
110
|
+
# =========================================================================== #
|
111
|
+
def self.start_sinatra_interface
|
112
|
+
e 'Trying to start the sinatra-interface of the Dictionaries project.'
|
113
|
+
::Dictionaries::Sinatra.run!
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
rescue LoadError
|
119
|
+
end
|
120
|
+
|
121
|
+
if __FILE__ == $PROGRAM_NAME
|
122
|
+
Dictionaries.start_sinatra_interface
|
123
|
+
end # dictionaries --sinatra
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# 'dictionaries/english_to_german.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'sinatra/base.rb'
|
8
|
+
|
9
|
+
module Dictionaries
|
10
|
+
|
11
|
+
class Sinatra < ::Sinatra::Base
|
12
|
+
|
13
|
+
require 'dictionaries/toplevel_methods/english_to_german.rb'
|
14
|
+
require 'dictionaries/helper_module/helper_module.rb'
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === /english_to_german
|
18
|
+
#
|
19
|
+
# This is the root of our web-application.
|
20
|
+
# ========================================================================= #
|
21
|
+
get('/english_to_german'){
|
22
|
+
return_english_to_german_form
|
23
|
+
}
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === return_english_to_german_form
|
27
|
+
# ========================================================================= #
|
28
|
+
def return_english_to_german_form
|
29
|
+
route_to_this_action = '/english_to_german/'
|
30
|
+
html_header_default_title_and_start_of_the_body_tag+
|
31
|
+
h5('Input an english word to see the translation.')+
|
32
|
+
div(css_style: 'padding: 0.1em') {
|
33
|
+
p(
|
34
|
+
'<b>Enter the word here:</b>',
|
35
|
+
css_style: 'padding: 0.15em'
|
36
|
+
)+
|
37
|
+
form(action: route_to_this_action,
|
38
|
+
id: 'english_to_german',
|
39
|
+
css_style: 'margin-left:1em; margin-top:2px') {
|
40
|
+
'<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
|
41
|
+
return_search_button
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === html_header_default_title_and_start_of_the_body_tag
|
48
|
+
# ========================================================================= #
|
49
|
+
def html_header_default_title_and_start_of_the_body_tag
|
50
|
+
return Dictionaries::HelperModule.html_header_default_title_and_start_of_the_body_tag
|
51
|
+
end
|
52
|
+
|
53
|
+
# ========================================================================= #
|
54
|
+
# === return_search_button
|
55
|
+
# ========================================================================= #
|
56
|
+
def return_search_button
|
57
|
+
return Dictionaries::HelperModule.return_search_button
|
58
|
+
end
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === /english_to_german
|
62
|
+
#
|
63
|
+
# This is the root of our web-application.
|
64
|
+
# ========================================================================= #
|
65
|
+
get('/english_to_german/*'){
|
66
|
+
_ = params[:splat]
|
67
|
+
_ = params.fetch('user_input') if params.has_key?('user_input')
|
68
|
+
_ = _.join if _.is_a? Array
|
69
|
+
# ======================================================================= #
|
70
|
+
# Obtain the translated word next:
|
71
|
+
# ======================================================================= #
|
72
|
+
translated_word = Dictionaries.english_to_german(_)
|
73
|
+
if translated_word
|
74
|
+
html_header_default_title_and_start_of_the_body_tag+
|
75
|
+
p('The word <b>'+_.to_s+'</b> translates to: '\
|
76
|
+
'<b style="font-size: larger; color: darkblue">'+translated_word+'</b>')+
|
77
|
+
return_english_to_german_form
|
78
|
+
else
|
79
|
+
html_header_default_title_and_start_of_the_body_tag+
|
80
|
+
p('The key '+_.to_s+' is not registered in the Dictionaries word file.')
|
81
|
+
end
|
82
|
+
}
|
83
|
+
|
84
|
+
end; end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Dictionaries::SpellChecker
|
6
|
+
#
|
7
|
+
# Usage example:
|
8
|
+
#
|
9
|
+
# Dictionaries::SpellChecker.new(ARGV)
|
10
|
+
#
|
11
|
+
# =========================================================================== #
|
12
|
+
# require 'dictionaries/spell_checker/spell_checker.rb'
|
13
|
+
# Dictionaries::SpellChecker.new(ARGV)
|
14
|
+
# =========================================================================== #
|
15
|
+
require 'dictionaries/base/base.rb'
|
16
|
+
|
17
|
+
module Dictionaries
|
18
|
+
|
19
|
+
class SpellChecker < Base # === Dictionaries::SpellChecker
|
20
|
+
|
21
|
+
# ========================================================================= #
|
22
|
+
# === NAMESPACE
|
23
|
+
# ========================================================================= #
|
24
|
+
NAMESPACE = inspect
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === FILE_IGNORE_THESE_WORDS
|
28
|
+
# ========================================================================= #
|
29
|
+
FILE_IGNORE_THESE_WORDS = 'IGNORE_THESE_WORDS.md'
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === initialize
|
33
|
+
# ========================================================================= #
|
34
|
+
def initialize(
|
35
|
+
commandline_arguments = nil,
|
36
|
+
run_already = true
|
37
|
+
)
|
38
|
+
reset
|
39
|
+
set_commandline_arguments(
|
40
|
+
commandline_arguments
|
41
|
+
)
|
42
|
+
run if run_already
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === reset (reset tag)
|
47
|
+
# ========================================================================= #
|
48
|
+
def reset
|
49
|
+
super()
|
50
|
+
# ======================================================================= #
|
51
|
+
# === @namespace
|
52
|
+
# ======================================================================= #
|
53
|
+
@namespace = NAMESPACE
|
54
|
+
# ======================================================================= #
|
55
|
+
# === @ignore_these_words
|
56
|
+
#
|
57
|
+
# The following variable specifies which words or word-like entries
|
58
|
+
# this class has to ignore. This is typically supplied by the user,
|
59
|
+
# such as by reading from the file IGNORE_THESE_WORDS.md.
|
60
|
+
# ======================================================================= #
|
61
|
+
@ignore_these_words = []
|
62
|
+
end
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === report_how_many_words_were_found
|
66
|
+
# ========================================================================= #
|
67
|
+
def report_how_many_words_were_found(array)
|
68
|
+
e rev+'Found '+array.size.to_s+' words.'
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === run (run tag)
|
73
|
+
# ========================================================================= #
|
74
|
+
def run
|
75
|
+
_ = first_argument?
|
76
|
+
if _ and File.file?(_)
|
77
|
+
# ===================================================================== #
|
78
|
+
# Read dataset from a locally existing file:
|
79
|
+
# ===================================================================== #
|
80
|
+
dataset = File.read(_).tr("\n",' ')
|
81
|
+
splitted = dataset.
|
82
|
+
split(/[^[[:word:]]]+/) # This splits on each word. Works fairly well.
|
83
|
+
report_how_many_words_were_found(splitted)
|
84
|
+
do_compare_each_discovered_word_towards_the_english_dictionary(splitted)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === do_compare_each_discovered_word_towards_the_english_dictionary
|
90
|
+
# ========================================================================= #
|
91
|
+
def do_compare_each_discovered_word_towards_the_english_dictionary(
|
92
|
+
array_all_discovered_words
|
93
|
+
)
|
94
|
+
if File.exist? FILE_IGNORE_THESE_WORDS
|
95
|
+
@ignore_these_words << YAML.load_file(FILE_IGNORE_THESE_WORDS)
|
96
|
+
@ignore_these_words.flatten!
|
97
|
+
@ignore_these_words.uniq!
|
98
|
+
@ignore_these_words.compact!
|
99
|
+
end
|
100
|
+
hash_english_dictionary = YAML.load_file(Dictionaries.file_english?)
|
101
|
+
e rev+'Now comparing each discovered word towards the english dictionary.'
|
102
|
+
array_these_words_are_not_part_of_the_yaml_file = []
|
103
|
+
uniq = array_all_discovered_words.uniq.sort # Always keep these entries sorted.
|
104
|
+
uniq.each {|this_word|
|
105
|
+
this_word = this_word.to_s.downcase # Always keep them downcased here.
|
106
|
+
result = hash_english_dictionary.has_key?(this_word)
|
107
|
+
if result
|
108
|
+
# e 'Yup, found '+this_word.to_s+'.' # This is fairly useless, hence why it is commented out.
|
109
|
+
# elsif @ignore_these_words.include? this_word
|
110
|
+
# If we have to debug then we can enter this clause.
|
111
|
+
else
|
112
|
+
e "#{rev}No matching entry found for the word `#{sfancy(this_word)}`."
|
113
|
+
array_these_words_are_not_part_of_the_yaml_file << this_word
|
114
|
+
end
|
115
|
+
}
|
116
|
+
unless array_these_words_are_not_part_of_the_yaml_file.empty?
|
117
|
+
e array_these_words_are_not_part_of_the_yaml_file.size.to_s+
|
118
|
+
' words are not registered in the .yml file.'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# ========================================================================= #
|
123
|
+
# === Dictionaries::SpellChecker[]
|
124
|
+
# ========================================================================= #
|
125
|
+
def self.[](i = ARGV)
|
126
|
+
new(i)
|
127
|
+
end
|
128
|
+
|
129
|
+
end; end
|
130
|
+
|
131
|
+
if __FILE__ == $PROGRAM_NAME
|
132
|
+
Dictionaries::SpellChecker.new(ARGV)
|
133
|
+
end # spellchecker /home/x/studium/TU_WIEN/060.015_Grundlagen_wissenschaftlichen_Arbeitens/chapters/03_Robert_Kunz_09703011_Cyborg_supremacy.tex
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Dictionaries::Statistics
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'dictionaries/statistics/statistics.rb'
|
8
|
+
# Dictionaries::Statistics.report
|
9
|
+
# =========================================================================== #
|
10
|
+
module Dictionaries
|
11
|
+
|
12
|
+
module Statistics # === Dictionaries::Statistics
|
13
|
+
|
14
|
+
require 'dictionaries/constants/constants.rb'
|
15
|
+
require 'dictionaries/toplevel_methods/misc.rb'
|
16
|
+
require 'dictionaries/project/project.rb'
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === Dictionaries::Statistics.e
|
20
|
+
# ========================================================================= #
|
21
|
+
def self.e(i = '')
|
22
|
+
puts i
|
23
|
+
end
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === Dictionaries::Statistics.report
|
27
|
+
# ========================================================================= #
|
28
|
+
def self.report
|
29
|
+
require 'yaml'
|
30
|
+
begin
|
31
|
+
require 'colours'
|
32
|
+
rescue LoadError; end
|
33
|
+
all_files = Dir[
|
34
|
+
Dictionaries.project_yaml_dir?+'*'
|
35
|
+
].reject {|entry| entry.include?('deutsche_fremdwörter.yml') }
|
36
|
+
e ::Colours.rev+'The statistics for each .yml file available in this project are'
|
37
|
+
e 'as follows:'
|
38
|
+
e
|
39
|
+
all_files.each {|this_file|
|
40
|
+
begin
|
41
|
+
dataset = YAML.load_file(this_file)
|
42
|
+
if dataset
|
43
|
+
e " #{File.basename(this_file).delete_suffix('.yml').ljust(15)} "+
|
44
|
+
"#{::Colours.steelblue(dataset.keys.size.to_s.rjust(4))} words."
|
45
|
+
else
|
46
|
+
e 'No data is available for '+this_file+'.'
|
47
|
+
end
|
48
|
+
rescue => error
|
49
|
+
pp error
|
50
|
+
end
|
51
|
+
}
|
52
|
+
e
|
53
|
+
end
|
54
|
+
|
55
|
+
end; end
|
56
|
+
|
57
|
+
if __FILE__ == $PROGRAM_NAME
|
58
|
+
Dictionaries::Statistics.report
|
59
|
+
end # statistics.rb
|
@@ -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
|
+
module Dictionaries
|
8
|
+
|
9
|
+
require 'dictionaries/toplevel_methods/has_key.rb'
|
10
|
+
require 'dictionaries/toplevel_methods/misc.rb'
|
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
|