mindwords 0.4.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4070b252c0702dbfa6cb778a8717e75e60cf5de4454f1e475f496bec0bd4328d
4
- data.tar.gz: 52493b20e6b137e396136b58a8c9a89e45650bff9d44caa73c9a78bfa86c8174
3
+ metadata.gz: c0d833b4c7bb6f1226f6c6d5a8489fed1ba6c8d5a2410bbb6df2b61a9285bc4d
4
+ data.tar.gz: 0cc6c2b9ac7cb8e829b52ba224d04579ad0fb20eb15b8bcf8c39c2ba365c6a3c
5
5
  SHA512:
6
- metadata.gz: e7576fde49c1d5fccc4ce87ae583e0648c4511a0637afbce67265bc57812ec8fe74a9237db6664e03632a11d95289ab14a08343392ead7a685a7afec2fe20a07
7
- data.tar.gz: df0d3b1b29866892eaa111e579da3a6e906266a524954b98ef9d5665d192c665f5bf5eaec15cef1708cc39fc2499ddf48774400e449ef868cc8f5dbfe1bfde2c
6
+ metadata.gz: 6f2608e84d67e2303cc61a349a50147028b54f6f537aefb92bd0a6bf15dade2d5e418b84f3a9a543d545d0235fb65d171fd106ad24e9b6ca7239ecef131a961e
7
+ data.tar.gz: bd98ce9223b9343b1c827946f972f5ac1420c79484bf11e26e60f8fead39f42a4323682ed684fcee5e0cefa1239ffd9c387623fff31e99567d3ec7319ecd7e34
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- :���@yƲ+M7�>C�������~_ �Х�btj��~��6Ӿ�N��u�ST�27}7� ��)C�K�i[Q:�L�5��+���%w�?�t�PnJ
2
- �s@0vH�`C%��䴮�QC�C;�㕑+�Js�>�Ly YU��ybZ�����}M���-��r
3
- DA3*վ������=�`78�͎L���
1
+ `X�_�ݪF�y�$.��u��P�ރEN�@�� O���#G��E���g�����
2
+ ���=˲�7{�ߤ����|�$��,
3
+ YX9�qo�Pb��o�~���4�Q��w]v&�@�G��i�G��QFy��ܻs�<��rg}����I ���{AU ��Q���P��3i�,���ui�qf� Q��9���+�NT��ng��ļj��gۖF_v������2ySƧ��K��0�I���S
4
+ f6R1��)�����w��:�O�0�K5�����IQ�����c��v�@���Z��d:�_`��Q|QN*���kn�]%ڧ1+������4D-���ZH/1�K�'T��3e�ٯ���$��
@@ -3,6 +3,7 @@
3
3
  # file: mindwords.rb
4
4
 
5
5
  require 'rexle'
6
+ require 'rxfhelper'
6
7
  require 'line-tree'
7
8
 
8
9
  module HashCopy
@@ -19,112 +20,47 @@ class MindWords
19
20
  using ColouredText
20
21
  using HashCopy
21
22
 
23
+ attr_accessor :lines, :filepath
22
24
 
23
- def initialize(s, parent: nil, debug: false)
25
+ def initialize(raws='', parent: nil, debug: false)
24
26
 
25
- @debug = debug
26
- @a = s.strip.gsub(/^\n/,'').lines
27
- @a.shift if @a.first =~ /<\?mindwords\?>/
28
-
29
- lines = @a.map do |line|
30
-
31
- word = line.split(/ (?=#)/,2)
32
-
33
- end
34
-
35
- h = {}
36
- @hashtags = {}
37
-
38
- lines.each do |title, rawtags|
39
-
40
- rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
41
- tag = rawtag.gsub(/ +/, '_')
42
- h[tag] ||= []
43
- h[tag] << title
44
- end
45
-
46
- end
47
-
48
- @hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
49
-
50
-
51
- a = rexlize(h)
52
- doc = Rexle.new(['root', {}, '', *a])
53
-
54
- # apply node nesting
55
-
56
- doc.root.elements.each do |e|
57
-
58
- doc.root.xpath('//' + e.name).each do |e2|
27
+ @parent, @debug = parent, debug
59
28
 
60
- next if e2 === e
61
-
62
- e2.parent.add e
63
- e2.delete
64
-
65
- end
66
-
67
- end
68
-
29
+ s, type = RXFHelper.read raws
69
30
 
70
- # remove duplicates which appear in the same branch above the nested node
71
- rm_duplicates(doc)
72
-
73
- # remove redundant nodes (outsiders)
74
- # a redundant node is where all children exist in existing nested nodes
75
-
76
- redundants = doc.root.elements.map do |e|
77
-
78
- r = e.elements.all? {|x| !x.has_elements?}
79
- puts "%s %s" % [e.name, r] if @debug
80
- dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
81
- puts 'dups: ' + dups.inspect if @debug
82
- e.backtrack.to_s if dups
83
-
84
- end
85
-
86
- redundants.compact.each {|x| doc.element(x).delete }
87
-
88
-
89
- node = if parent then
90
- found = doc.root.element('//' + parent)
91
- found ? found : doc.root
92
- else
93
- doc.root
94
- end
95
-
96
- @outline = treeize node
97
-
98
- node.root.each_recursive do |e|
99
-
100
- e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
101
-
102
- s = e.parent.attributes[:breadcrumb] ? \
103
- e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
104
- e.attributes[:breadcrumb] = s + e.value.strip
105
-
106
- r = @a.grep(/^#{e.attributes[:title]} #/i)
107
- next unless r.any?
108
- e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
109
-
110
-
111
- end
112
-
113
- @xml = node.xml pretty: true
31
+ @filepath = raws if type == :file or type == :dfs
32
+ @lines = s.strip.gsub(/^\n/,'').lines
33
+ @lines.shift if @lines.first =~ /<\?mindwords\?>/
114
34
 
115
35
  end
116
36
 
37
+ def breadcrumb()
38
+ @parent.attributes[:breadcrumb].split(/ +\/ +/) if @parent
39
+ end
40
+
41
+
117
42
  def element(id)
118
43
 
119
- doc = Rexle.new(@xml)
44
+ doc = Rexle.new(to_xml())
120
45
  e = doc.root.element("//*[@id='#{id}']")
121
46
  #e.attributes[:breadcrumb].to_s if e
122
47
 
123
- end
48
+ end
49
+
50
+ def hashtags()
51
+ @parent.attributes[:hashtags].split if @parent
52
+ end
53
+
54
+ def save(file=@filepath)
55
+
56
+ puts 'before save' if @debug
57
+ File.write file, to_s()
58
+
59
+ end
124
60
 
125
61
  def search(keyword)
126
62
 
127
- a = @a.grep(/#{keyword}/i).map do |line|
63
+ a = @lines.grep(/#{keyword}/i).map do |line|
128
64
 
129
65
  puts 'line: ' + line.inspect if @debug
130
66
 
@@ -141,12 +77,16 @@ class MindWords
141
77
 
142
78
  a2 = a.sort_by(&:last).map(&:first)
143
79
  puts 'a2: ' + a2.inspect if @debug
144
- MindWords.new(a2.join, parent: keyword, debug: @debug)
80
+ e = element(keyword.downcase.gsub(/ +/,'-'))
81
+
82
+ return nil if e.nil?
83
+
84
+ MindWords.new(a2.join, parent: e, debug: @debug)
145
85
 
146
86
  end
147
87
 
148
88
  def sort()
149
- s = @a.sort.join
89
+ s = @lines.sort.join
150
90
 
151
91
  def s.to_s()
152
92
  self.lines.map do |x|
@@ -159,13 +99,13 @@ class MindWords
159
99
  end
160
100
 
161
101
  def sort!()
162
- @a = sort().lines
102
+ @lines = sort().lines
163
103
  self
164
104
  end
165
105
 
166
106
  def tag_sort()
167
107
 
168
- h = @a.group_by {|x| x[/#\w+/]}
108
+ h = @lines.group_by {|x| x[/#\w+/]}
169
109
  s = h.sort.map {|key, value| value.sort }.join
170
110
 
171
111
  def s.to_s()
@@ -180,7 +120,7 @@ class MindWords
180
120
  end
181
121
 
182
122
  def tag_sort!()
183
- @a = tag_sort().lines
123
+ @lines = tag_sort().lines
184
124
  self
185
125
  end
186
126
 
@@ -193,15 +133,16 @@ class MindWords
193
133
  end
194
134
 
195
135
  def to_outline(sort: true)
136
+ build()
196
137
  sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
197
138
  end
198
139
 
199
140
  def to_s(colour: false)
200
141
 
201
142
  header = "<?mindwords?>\n\n"
202
- return header + @a.join unless colour
143
+ return header + @lines.join unless colour
203
144
 
204
- body = @a.map do |x|
145
+ body = @lines.map do |x|
205
146
  title, hashtags = x.split(/(?=#)/,2)
206
147
  title + hashtags.chomp.brown
207
148
  end.join("\n")
@@ -211,15 +152,101 @@ class MindWords
211
152
  end
212
153
 
213
154
  def to_words()
214
- to_outline.lines.map {|x| x[/\w[\w ]+/] }
155
+ to_outline.lines.map {|x| x[/\w[\w ]+/] }.uniq
215
156
  end
216
157
 
217
158
  def to_xml()
159
+ build() unless @xml
218
160
  @xml
219
161
  end
220
162
 
221
163
  private
222
164
 
165
+ def build()
166
+
167
+ h = {}
168
+
169
+ @lines.each do |line|
170
+
171
+ title, rawtags = line.split(/ (?=#)/,2)
172
+
173
+ rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
174
+ tag = rawtag.gsub(/ +/, '_')
175
+ h[tag] ||= []
176
+ h[tag] << title
177
+ end
178
+
179
+ end
180
+
181
+ @hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
182
+
183
+
184
+ a = rexlize(h)
185
+ doc = Rexle.new(['root', {}, '', *a])
186
+
187
+ # apply node nesting
188
+
189
+ doc.root.elements.each do |e|
190
+
191
+ doc.root.xpath('//' + e.name).each do |e2|
192
+
193
+ next if e2 === e
194
+
195
+ e2.parent.add e
196
+ e2.delete
197
+
198
+ end
199
+
200
+ end
201
+
202
+
203
+ # remove duplicates which appear in the same branch above the nested node
204
+ rm_duplicates(doc)
205
+
206
+ # remove redundant nodes (outsiders)
207
+ # a redundant node is where all children exist in existing nested nodes
208
+
209
+ redundants = doc.root.elements.map do |e|
210
+
211
+ r = e.elements.all? {|x| !x.has_elements?}
212
+ puts "%s %s" % [e.name, r] if @debug
213
+ dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
214
+ puts 'dups: ' + dups.inspect if @debug
215
+ e.backtrack.to_s if dups
216
+
217
+ end
218
+
219
+ redundants.compact.each {|x| doc.element(x).delete }
220
+
221
+
222
+ node = if @parent then
223
+ found = doc.root.element('//' + @parent.name)
224
+ found ? found : doc.root
225
+ else
226
+ doc.root
227
+ end
228
+
229
+ @outline = treeize node
230
+
231
+ node.root.each_recursive do |e|
232
+
233
+ e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
234
+
235
+ s = e.parent.attributes[:breadcrumb] ? \
236
+ e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
237
+ e.attributes[:breadcrumb] = s + e.value.strip
238
+
239
+ r = @lines.grep(/^#{e.attributes[:title]} #/i)
240
+ next unless r.any?
241
+ e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
242
+
243
+
244
+ end
245
+
246
+ @xml = node.xml pretty: true
247
+
248
+ end
249
+
223
250
  def rexlize(a)
224
251
 
225
252
  a.map do |x|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindwords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  aWH7D2AmhOpqNwWnPHzWR/yzpigAVTrvpHfRxZleQj6Z/090nIH2KR0RdioMmPFq
36
36
  3+574KQzs/gR9Y5a+iMcvHRN
37
37
  -----END CERTIFICATE-----
38
- date: 2021-01-22 00:00:00.000000000 Z
38
+ date: 2021-01-28 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: line-tree
@@ -57,6 +57,26 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 0.9.1
60
+ - !ruby/object:Gem::Dependency
61
+ name: rxfhelper
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.1'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.3
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.1.3
60
80
  description:
61
81
  email: digital.robertson@gmail.com
62
82
  executables: []
metadata.gz.sig CHANGED
Binary file