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,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
|
+
# /home/x/programming/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,231 @@
|
|
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
|
+
|
11
|
+
begin
|
12
|
+
require 'save_file/module'
|
13
|
+
rescue LoadError; end
|
14
|
+
|
15
|
+
require 'dictionaries/constants/constants.rb'
|
16
|
+
require 'dictionaries/toplevel_methods/main_file.rb'
|
17
|
+
require 'dictionaries/toplevel_methods/has_key.rb'
|
18
|
+
|
19
|
+
# ========================================================================= #
|
20
|
+
# === Dictionaries.english_key_values?
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.english_key_values?(
|
23
|
+
this_file = Dictionaries.main_file?
|
24
|
+
)
|
25
|
+
dataset = YAML.load_file(this_file)
|
26
|
+
return dataset
|
27
|
+
end
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === Dictionaries.create_javascript_file
|
31
|
+
#
|
32
|
+
# This method will create a .js file, into the current working directory.
|
33
|
+
#
|
34
|
+
# Invocation example:
|
35
|
+
#
|
36
|
+
# require 'dictionaries'; result = Dictionaries.create_javascript_file
|
37
|
+
#
|
38
|
+
# ========================================================================= #
|
39
|
+
def self.create_javascript_file(
|
40
|
+
into = File.absolute_path('dictionary.js'),
|
41
|
+
dataset = english_key_values?
|
42
|
+
)
|
43
|
+
what = <<-EOF
|
44
|
+
function return_english_dictionary() {
|
45
|
+
|
46
|
+
var dictionary = {};
|
47
|
+
|
48
|
+
EOF
|
49
|
+
what = what.dup
|
50
|
+
dataset.each {|key, value|
|
51
|
+
value = value.gsub(/"/,'\"') if value.include?('"')
|
52
|
+
what << " dictionary[\"#{key}\"] = \"#{value}\";\n"
|
53
|
+
}
|
54
|
+
what << " return dictionary;\n"
|
55
|
+
what << "}\n"
|
56
|
+
SaveFile.write_what_into(what, into)
|
57
|
+
return into
|
58
|
+
end
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === Dictionaries.generate_pdf_file
|
62
|
+
#
|
63
|
+
# This method can be used to generate a .pdf file.
|
64
|
+
# ========================================================================= #
|
65
|
+
def self.generate_pdf_file(
|
66
|
+
use_this_font = 'Courier', # Helvetica-Bold' # #'Times-Roman'
|
67
|
+
use_this_font_size = 12
|
68
|
+
)
|
69
|
+
require 'prawn'
|
70
|
+
::Prawn::Fonts::AFM.hide_m17n_warning = true
|
71
|
+
right_arrow = ' -> '.dup.encode(
|
72
|
+
'Windows-1252', invalid: :replace, undef: :replace, replace: ''
|
73
|
+
)
|
74
|
+
dataset = YAML.load_file(Dictionaries.file_english)
|
75
|
+
into = File.absolute_path('english_to_german_dictionary.pdf')
|
76
|
+
Prawn::Document.generate(into) {
|
77
|
+
font use_this_font
|
78
|
+
font_size use_this_font_size
|
79
|
+
text(
|
80
|
+
"English to German dictionary: "\
|
81
|
+
"#{dataset.keys.size.to_s} translated words\n\n"
|
82
|
+
)
|
83
|
+
# ===================================================================== #
|
84
|
+
# Iterate over our exam dataset next.
|
85
|
+
# ===================================================================== #
|
86
|
+
dataset.each_pair {|key, value|
|
87
|
+
indent(8) {
|
88
|
+
key = key.dup if key.frozen?
|
89
|
+
value = value.dup if value.frozen?
|
90
|
+
result = key.encode(
|
91
|
+
'Windows-1252', invalid: :replace, undef: :replace, replace: ''
|
92
|
+
)+
|
93
|
+
right_arrow+
|
94
|
+
value.encode(
|
95
|
+
'Windows-1252', invalid: :replace, undef: :replace, replace: ''
|
96
|
+
)
|
97
|
+
text(result, {size: 10})
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
e 'Stored into `'+into+'`.'
|
102
|
+
end
|
103
|
+
|
104
|
+
# ========================================================================= #
|
105
|
+
# === Dictionaries.return_array_of_translated_words_from_online_leo
|
106
|
+
#
|
107
|
+
# This method can be used to query the online dictionary from leo.
|
108
|
+
#
|
109
|
+
# It will then return an Array of translations.
|
110
|
+
#
|
111
|
+
# Note that this currently only works for the translation from english
|
112
|
+
# to german, not the other way around, even though that is not too
|
113
|
+
# hard to implement either.
|
114
|
+
# ========================================================================= #
|
115
|
+
def self.return_array_of_translated_words_from_online_leo(this_word)
|
116
|
+
if this_word.is_a? Array
|
117
|
+
this_word = this_word.join(' ').strip
|
118
|
+
end
|
119
|
+
require 'open-uri'
|
120
|
+
remote_url = "https://dict.leo.org/german-english/#{this_word}"
|
121
|
+
remote_dataset = URI.open(remote_url).read
|
122
|
+
# ======================================================================= #
|
123
|
+
# See: https://rubular.com/r/OOXwAc6PVqjU5Q
|
124
|
+
# ======================================================================= #
|
125
|
+
use_this_regex =
|
126
|
+
/<words><word>([a-zA-Z\s]+)\<\/word><\/words>/
|
127
|
+
scanned_results = remote_dataset.scan(use_this_regex).flatten
|
128
|
+
# ======================================================================= #
|
129
|
+
# This result may look like so:
|
130
|
+
# [["cat"], ["die Katze"]
|
131
|
+
# We have to sanitize it still.
|
132
|
+
# ======================================================================= #
|
133
|
+
scanned_results.reject! {|entry| entry.start_with?(this_word) }
|
134
|
+
return scanned_results # Note that the full Array is returned.
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === Dictionaries.return_unique_words_from_this_file
|
139
|
+
#
|
140
|
+
# This method will read in the words from an existing local file.
|
141
|
+
#
|
142
|
+
# Some files may be huge, though, and then this method becomes
|
143
|
+
# quite useless, so we really should discard a lot of data after a
|
144
|
+
# certain threshold, to keep memory usage low.
|
145
|
+
# ========================================================================= #
|
146
|
+
def self.return_unique_words_from_this_file(
|
147
|
+
this_file,
|
148
|
+
optional_arguments = :english,
|
149
|
+
remove_html_tags = false
|
150
|
+
)
|
151
|
+
case remove_html_tags
|
152
|
+
# ======================================================================= #
|
153
|
+
# === :remove_HTML_tags
|
154
|
+
# ======================================================================= #
|
155
|
+
when :remove_HTML_tags
|
156
|
+
remove_html_tags = true
|
157
|
+
end
|
158
|
+
dataset = nil
|
159
|
+
if this_file.is_a? Array
|
160
|
+
this_file = this_file.join(' ').strip
|
161
|
+
end
|
162
|
+
if this_file and File.file?(this_file)
|
163
|
+
dataset = File.read(this_file)
|
164
|
+
if remove_html_tags
|
165
|
+
require 'cyberweb/toplevel_methods/misc.rb'
|
166
|
+
dataset = ::Cyberweb.remove_html(dataset)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
result = [] # ← This variable will store the unique words found in the file.
|
170
|
+
case optional_arguments
|
171
|
+
# ======================================================================= #
|
172
|
+
# === :english
|
173
|
+
# ======================================================================= #
|
174
|
+
when :english,
|
175
|
+
:default
|
176
|
+
# ===================================================================== #
|
177
|
+
# Query unknown words in english. We will compare the words to the
|
178
|
+
# available variants.
|
179
|
+
# ===================================================================== #
|
180
|
+
result = dataset.scan(/\w+/).map {|entry| entry.downcase } # ← Obtain all words here.
|
181
|
+
# ===================================================================== #
|
182
|
+
# Next, reject those that are registered:
|
183
|
+
# ===================================================================== #
|
184
|
+
result.reject! {|this_word|
|
185
|
+
::Dictionaries.has_key?(this_word)
|
186
|
+
}
|
187
|
+
end if dataset
|
188
|
+
return result.uniq.sort
|
189
|
+
end
|
190
|
+
|
191
|
+
# ========================================================================= #
|
192
|
+
# === Dictionaries[]
|
193
|
+
#
|
194
|
+
# Currently this method will always reload the main file. In the future
|
195
|
+
# we may change this approach, but for now this has to suffice (May 2019).
|
196
|
+
#
|
197
|
+
# The method will return either the translated string - or nil. Nil
|
198
|
+
# indicates that the main Hash does not include that key; in other words,
|
199
|
+
# that the word is not registered.
|
200
|
+
# ========================================================================= #
|
201
|
+
def self.[](i = ARGV)
|
202
|
+
i = i.join.strip if i.is_a? Array
|
203
|
+
this_file = Dictionaries.main_file?
|
204
|
+
if this_file.nil?
|
205
|
+
Dictionaries.set_main_file(:default) # Must initialize it in this case.
|
206
|
+
this_file = Dictionaries.main_file?
|
207
|
+
end
|
208
|
+
if this_file
|
209
|
+
dataset = YAML.load_file(this_file)
|
210
|
+
dataset[i] # Return the result here.
|
211
|
+
else
|
212
|
+
nil
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
if __FILE__ == $PROGRAM_NAME
|
219
|
+
alias e puts
|
220
|
+
#puts Dictionaries[ARGV]
|
221
|
+
e 'Possible words for cat:'
|
222
|
+
pp Dictionaries.return_array_of_translated_words_from_online_leo('cat')
|
223
|
+
# ========================================================================= #
|
224
|
+
# The next chunk of code is to test reading unique words from a given
|
225
|
+
# local file.
|
226
|
+
# ========================================================================= #
|
227
|
+
puts '-'*80
|
228
|
+
_ = Dictionaries.return_unique_words_from_this_file('/Depot/j/foobar.md')
|
229
|
+
pp _
|
230
|
+
pp _.size
|
231
|
+
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,31 @@
|
|
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
|
+
--read=www.nytimes.com.html # Read from a specific file, to find unique words
|
26
|
+
|
27
|
+
EOF
|
28
|
+
e help_string
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/version/version.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Dictionaries
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === VERSION
|
11
|
+
# ========================================================================= #
|
12
|
+
VERSION = '0.3.70'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === LAST_UPDATE
|
16
|
+
# ========================================================================= #
|
17
|
+
LAST_UPDATE = '02.12.2023'
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# === chinese.yml
|
3
|
+
#
|
4
|
+
# CHINESE or MANDARIN - Singlish,Singaporean Slang TAG
|
5
|
+
# rf dict chinese
|
6
|
+
# =========================================================================== #
|
7
|
+
|
8
|
+
'nie hau': hallo
|
9
|
+
'hao': 'ja/gut'
|
10
|
+
ganbao: gewonnen
|
11
|
+
shije: schwester
|
12
|
+
wobazaju: I dont care
|
13
|
+
budumo: dont touch it
|
14
|
+
buyaotawo: |
|
15
|
+
"Dont hit me." bu yao ta wo
|
16
|
+
sian: boring
|
17
|
+
dao: Weg
|
18
|
+
chai: Tee
|
19
|
+
wei: "hallo"
|
20
|
+
shue: ja
|
21
|
+
|
22
|
+
'shü-she': '~ja, in ordnung. Danke'
|
23
|
+
yang: Sonne
|
24
|
+
sei tschien: auf wiedersehen
|
25
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
elegisch: klagend # added 19.10.2003
|