-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.rb
208 lines (190 loc) · 4.65 KB
/
cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env ruby
# By David Valin <[email protected]>
require 'rubygems'
require 'gematria'
require 'sqlite3'
require 'ruby-graphviz'
ARGV.delete(0)
EXPORT_GRAPH = ARGV.include? "--graph"
EXPORT_TEXT = ARGV.include? "--text"
ONLY_EXPORT =
(ARGV.size == 1 && EXPORT_GRAPH) ||
(ARGV.size == 1 && EXPORT_TEXT) ||
(ARGV.size == 2 && (EXPORT_GRAPH && EXPORT_TEXT))
DB = SQLite3::Database.open Dir.home+'/g.db'
DB.execute "CREATE TABLE IF NOT EXISTS searches(search TEXT, hbr TEXT, eng TEXT, smp TEXT)"
# mapping from https://www.gematrix.org/?word=abcdefghijklmnopqrstuvwxyz
Gematria::Tables.add_table :hbr,
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
'e' => 5,
'f' => 6,
'g' => 7,
'h' => 8,
'i' => 9,
'j' => 600,
'k' => 10,
'l' => 20,
'm' => 30,
'n' => 40,
'o' => 50,
'p' => 60,
'q' => 70,
'r' => 80,
's' => 90,
't' => 100,
'u' => 200,
'v' => 700,
'w' => 900,
'x' => 300,
'y' => 400,
'z' => 500
# mapping from https://www.gematrix.org/?word=abcdefghijklmnopqrstuvwxyz
Gematria::Tables.add_table :eng,
'a' => 6,
'b' => 12,
'c' => 18,
'd' => 24,
'e' => 30,
'f' => 36,
'g' => 42,
'h' => 48,
'i' => 54,
'j' => 60,
'k' => 66,
'l' => 72,
'm' => 78,
'n' => 84,
'o' => 90,
'p' => 96,
'q' => 102,
'r' => 108,
's' => 114,
't' => 120,
'u' => 126,
'v' => 132,
'w' => 138,
'x' => 144,
'y' => 150,
'z' => 156
# mapping from https://www.gematrix.org/?word=abcdefghijklmnopqrstuvwxyz
Gematria::Tables.add_table :smp,
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
'e' => 5,
'f' => 6,
'g' => 7,
'h' => 8,
'i' => 9,
'j' => 10,
'k' => 11,
'l' => 12,
'm' => 13,
'n' => 14,
'o' => 15,
'p' => 16,
'q' => 17,
'r' => 18,
's' => 19,
't' => 20,
'u' => 21,
'v' => 22,
'w' => 23,
'x' => 24,
'y' => 25,
'z' => 26
if not ONLY_EXPORT
search_query_tmp = ARGV.select {|s| s != "--graph"}
search_query = search_query_tmp.join(" ")
name_hbr = Gematria::Calculator.new search_query, :hbr
name_eng = Gematria::Calculator.new search_query, :eng
name_smp = Gematria::Calculator.new search_query, :smp
puts "\n"
puts "hebrew: \t" + name_hbr.converted.to_s
puts " english: \t" + name_eng.converted.to_s
puts " simple: \t" + name_smp.converted.to_s
puts "\n"
# Track this search
DB.execute "INSERT INTO searches (search, hbr, eng, smp) VALUES (?, ?, ?, ?)",
search_query,
name_hbr.converted.to_s,
name_eng.converted.to_s,
name_smp.converted.to_s
# Find other searches with the same value
# ... in hebrew table
results_hbr = DB.query "SELECT DISTINCT search FROM searches WHERE hbr=? and search!=?",
name_hbr.converted.to_s,
search_query
# ... in english table
results_eng = DB.query "SELECT DISTINCT search FROM searches WHERE eng=? and search!=?",
name_eng.converted.to_s,
search_query
# ... in simple table
results_smp = DB.query "SELECT DISTINCT search FROM searches WHERE smp=? and search!=?",
name_smp.converted.to_s,
search_query
puts " Other previous searches matching numerical value:\n"
results_hbr.each {|s| puts " "+s.join('')+" (hebrew value)"}
results_eng.each {|s| puts " "+s.join('')+" (english value)"}
results_smp.each {|s| puts " "+s.join('')+" (simple value)"}
puts "\n"
end
# Export a png graphviz graph for any of "hbr", "eng" or "smp" gematria tables
def export(lang)
all_searches = DB.query "SELECT DISTINCT search, "+lang+" FROM searches"
groups = all_searches.group_by do |row|
row[1]
end
if EXPORT_TEXT
file = File.open("gematria_#{lang}.txt", "w")
end
# puts all_searches
groups.keys.each do |key|
terms_groups = groups[key].map do |row|
row[0]
end
if terms_groups.length > 1
if EXPORT_GRAPH
g = GraphViz.new(:G, :type => :digraph)
end
if EXPORT_TEXT
file.write "#{key} (#{lang})\n"
end
terms_groups.each do |term|
if EXPORT_GRAPH
g.add_nodes(term)
end
if EXPORT_TEXT
file.write "\t\t#{term}\n"
end
end
if EXPORT_GRAPH
terms_groups.each do |term_left|
terms_groups.each do |term_right|
term_left != term_right &&
g.add_edges(term_left, term_right, :dir => :none)
end
end
filename = "#{lang}_#{groups[key][0][1]}"
g.output(:png => "#{filename}.png")
end
if EXPORT_TEXT
file.write "\n\n"
end
end
end
if EXPORT_TEXT
file.close
end
end
# Export graphviz hierarchy graphs for hebrew, english and simple gematria tables
# using all searches stored in the database
if EXPORT_GRAPH || EXPORT_TEXT
export("hbr")
export("eng")
export("smp")
end