Skip to content

Commit

Permalink
feature: export relations as text
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidValin committed May 9, 2023
1 parent 237c013 commit 4d6cfe2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Use gematria directrly from your terminal!
```
[x] Search a word or phrase and find its hebrew, english and simple gematria value
[x] When retrieving a gematria value for a search term, find previous search terms with the same gematria value
[x] Generate a visual graph with searched terms which have a relation between each other in hebrew, english or simple gematria tables
[x] Export a visual graph with searched terms which match their hebrew, english or simple gematria table values (graphviz)
[x] Export a txt file with searched terms which match their hebrew, english or simple gematria table values
[x] Store all searches in a sqlite database in your user home directory (g.db filename)
```

Expand All @@ -32,14 +33,18 @@ If you want to find the gematria values for a specific term (word or phrase) use

The previous 3 terms match their hebrew gematria value.

##### Search a term
##### Export relations

If you want to generate a graphviz graph in PNG which renders relations based on the gematria values of all the searches stored in the database call:

`g --graph`

This will create one png file for each language + numerical match value (using hebrew, english and simple gematria tables)

You can also export it as text using:

`g --text`

### About mapping tables

https://www.gematrix.org/?word=abcdefghijklmnopqrstuvwxyz has been used as a reference to construct the mapping tables for "hebrew", "english" and "simple".
Expand Down
56 changes: 41 additions & 15 deletions cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

ARGV.delete(0)
EXPORT_GRAPH = ARGV.include? "--graph"
ONLY_EXPORT = ARGV.size == 1 && EXPORT_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)"
Expand Down Expand Up @@ -146,37 +151,58 @@
end

# Export a png graphviz graph for any of "hbr", "eng" or "smp" gematria tables
def export_graph(lang)
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|
g = GraphViz.new(:G, :type => :digraph)
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|
g.add_nodes(term)
if EXPORT_GRAPH
g.add_nodes(term)
end
if EXPORT_TEXT
file.write "\t\t#{term}\n"
end
end
end
terms_groups.each do |term_left|
terms_groups.each do |term_right|
g.add_edges(term_left, term_right, :dir => :none) if term_left != term_right
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
if terms_groups.length > 1
g.output(:png => "#{lang}_#{groups[key][0][1]}.png")
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_graph("hbr")
export_graph("eng")
export_graph("smp")
if EXPORT_GRAPH || EXPORT_TEXT
export("hbr")
export("eng")
export("smp")
end

0 comments on commit 4d6cfe2

Please sign in to comment.