mindwords 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4d617b7606074c5392810716b83f5ea18a45bd2f9bcbc3cbd3c8264c4efda15
4
+ data.tar.gz: 77459002b1868120333d8d173ef7012db25e29b977a265dd60f85405825a377b
5
+ SHA512:
6
+ metadata.gz: f9bafe174e81786a07e60e1665116f5c9fd0c966642322bddf5f9898f95ce5474d1a3ec80573ed6a0056751e63cbf1e13210610459db5d8b85d77865db0daa39
7
+ data.tar.gz: 6aedd18fb09a55aa78b3cc2c7c59db08edca77a2ed5e47c1049bb5bd069d34f1d4b5438fb36367d35a4ae9c91c5ec4970eb975eebfe3b0c286982f322b2b16b9
Binary file
@@ -0,0 +1,3 @@
1
+ �Ȍ=�ݧ�G�������YFF��)R)���P�+�K�z�Z��qX�Dmq���� (?�uHo���-����Y�l*�RN��Bs�2����fr�D���d}�����B�p�;�KpB���xGN��C#{�J��Q�s�&lLK��.��{��E�8���Zeq�4j�����oC���w�� ��>���!���.(
2
+ �I�s~�
3
+ أ�O9��xOvW����Q��YV����j�� �Xt�9ƃ� A�����v6�����1P��!����
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: mindwords.rb
4
+
5
+ require 'rexle'
6
+
7
+ class MindWords
8
+
9
+ def initialize(s, debug: false)
10
+
11
+ @debug = debug
12
+
13
+ lines = s.strip.lines.map do |line|
14
+
15
+ word = line.split(/ (?=#)/,2)
16
+
17
+ end
18
+
19
+ h = {}
20
+
21
+ lines.each do |x|
22
+
23
+ x.last.scan(/#(\w+)/).flatten(1).each do |rawtag|
24
+ tag = rawtag.gsub(/ +/, '_')
25
+ h[tag] ||= []
26
+ h[tag] << x.first
27
+ end
28
+
29
+ end
30
+
31
+ # does the key exist as a field?
32
+
33
+ h.keys.each do |key|
34
+
35
+ r = h.detect {|_, value| value.include? key}
36
+ next unless r
37
+ h[r.first].delete key
38
+ h[r.first] << {key => h[key]}
39
+ #puts r.inspect
40
+ h.delete key
41
+
42
+ end
43
+
44
+ a = rexlize(h)
45
+ doc = Rexle.new(['root', {}, '', *a])
46
+
47
+ duplicates = []
48
+ doc.root.each_recursive do |e|
49
+
50
+ puts 'e: ' + e.name.inspect if @debug
51
+ rows = e.parent.xpath('//' + e.name)
52
+ next if rows.length < 2
53
+
54
+ rows[1..-1].each do |e2|
55
+ puts 'e2: ' + e2.name.inspect if @debug
56
+ duplicates << [e.backtrack.to_s, e2.backtrack.to_s] #unless e2.has_elements?
57
+ end
58
+ end
59
+
60
+ duplicates.each do |path, oldpath|
61
+ e = doc.element(path);
62
+ e2 = doc.element(oldpath);
63
+ e2.parent.add e
64
+ e2.delete
65
+ end
66
+
67
+ # remove redundant nodes
68
+ # a redundant node is where all children exist in existing nested nodes
69
+
70
+ redundants = doc.root.elements.map do |e|
71
+
72
+ r = e.elements.all? {|x| !x.has_elements?}
73
+ puts "%s %s" % [e.name, r] if @debug
74
+ dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
75
+ puts 'dups: ' + dups.inspect if @debug
76
+ e.backtrack.to_s if dups
77
+
78
+ end
79
+
80
+ redundants.compact.each {|x| doc.element(x).delete }
81
+
82
+ @outline = treeize doc.root
83
+
84
+ end
85
+
86
+ def to_outline()
87
+ @outline
88
+ end
89
+
90
+ private
91
+
92
+ def rexlize(a)
93
+
94
+ a.map do |x|
95
+
96
+ puts 'x: ' + x.inspect if @debug
97
+
98
+ case x
99
+ when String
100
+ [x.gsub(/ +/,'_'), {}, x]
101
+ when Hash
102
+ [x.keys.first, {}, x.keys.first.gsub(/_/,' '), *rexlize(x.values.first)]
103
+ when Array
104
+ [x.first, {}, x.first.gsub(/_/,' '), *rexlize(x.last)]
105
+ end
106
+ end
107
+
108
+ end
109
+
110
+ def treeize(node, indent=0)
111
+
112
+ s, *children = node.children
113
+
114
+ lines = children.map do |e|
115
+
116
+ puts 'e: ' + e.inspect if @debug
117
+ if e.is_a? Rexle::Element then
118
+ (' ' * indent) + e.value.to_s + "\n" + treeize(e,indent+1)
119
+ end
120
+ end
121
+
122
+ lines.join
123
+ end
124
+
125
+ end
126
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mindwords
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwMTA2MDAzNzI2WhcN
15
+ MjIwMTA2MDAzNzI2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCnNKTu
17
+ gn/UJQjyq6a2T4UUemzEz8RnPLYDFkt+iM4mXm7dqSkZ5EdSEHdJ26r2P07yZjyB
18
+ wg/WciIAG2tStBa9Kz3JLe4PveWMTlWDy0SruFAlUYVo8xaZjJmn7eAYFQz9mvVM
19
+ 6HYp0ov8hDtYiDuhcmJ9tlVciusDcGuF9J9XoG3wH75EgRCVbxVXPTufhJNxAfmg
20
+ Z8Z6pGm6gVRZ4YJ50+14vwTyyTjB3uFmJtjIn4UhDmAP3l1YUEQq0RCqEgdigzu7
21
+ k1gX0A5Fs+5BKqK9kTlpZuceDH4Hqcmm4DPZ+asiXIYoRetlYaw/QJMpVpgOQ4tU
22
+ PP0ZGl/QUSmrru/5uK+P4xOUL07O1dd+K6tyR8SC3Gh4Wzow8rUtyh7cXPz58bGY
23
+ RtZaWPTWgz8FZs3S7NcIBdGU0Hlj8Z5QL26LatKIRsJz1yNaV8dRWZbhU9ML6RRJ
24
+ 7T2avgjLyj1WWyx3Sg8afxxZ0Odp5wBc1LiqdqI+OybheGZdR1z17k/Xyj8CAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUWkD96lfk
26
+ uPyGnc/MJwjZ5vZICwEwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAbe9+Fvsl1/YO5V70fwm9KI6qDR8TBYVSgFBBHnBb
29
+ vua8Qp+neqsLq/NVF/MAgBa8klFOw0LLPjKphKLSbJd7pb34etJytsIWcF2WLCGG
30
+ s9JBtt3URieOcvKVyCnjAA4aQ3YGvgaM3t94y/LaoSQZEgu8385NczGI8GCFSEV5
31
+ 0pv/71aTh42DuIbFrF5Qf7XMncgMzxZuVWaWuU25Nh4bK6swzSV8Pba89c8LhVj2
32
+ WUxqYCA9Lrgw2H/RWxQIXS1xQ+zXLHc+ExzJ/qEDef7wsz3wIYRoGHbhciXxLHce
33
+ +0EOblxngt+AdCB4PmQlVA5LdFSRzxMv84tGrnhAGefjGPe1KzegthuN7sl0yugD
34
+ tiF/wCtUE7D7XQOINuJSGP2e+9XU3GmTZQvrdEuOO3LcTSU9jfn04leXaQ4pwv2M
35
+ aWH7D2AmhOpqNwWnPHzWR/yzpigAVTrvpHfRxZleQj6Z/090nIH2KR0RdioMmPFq
36
+ 3+574KQzs/gR9Y5a+iMcvHRN
37
+ -----END CERTIFICATE-----
38
+ date: 2021-01-06 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rexle
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.5.9
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.5'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.5.9
60
+ description:
61
+ email: digital.robertson@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/mindwords.rb
67
+ homepage: https://github.com/jrobertson/mindwords
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Helps get what's in your mind into a structure using words and hashtags.
91
+ test_files: []
Binary file