diff --git a/README.md b/README.md index 51479a5..a10e4e7 100644 --- a/README.md +++ b/README.md @@ -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) ``` @@ -32,7 +33,7 @@ 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: @@ -40,6 +41,10 @@ If you want to generate a graphviz graph in PNG which renders relations based on 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". diff --git a/cli.rb b/cli.rb index a2996e1..fa9b26f 100644 --- a/cli.rb +++ b/cli.rb @@ -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)" @@ -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