mindwords 0.4.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mindwords.rb +131 -98
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ea1cb6b906664113ef2137b3cad143b365d37c9eb0612df38a0b9e2cfdfeac
|
4
|
+
data.tar.gz: 8d4a298c78f32c500a941699791b1f6b952075c15b67fb088392c8860fb01fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87afa7b5bd0b7f2cf225177259df456021e90155f57d40712042b13a37105bf879fcea494ce0b05f2b53911717dbf3cebaf6a6b9cfff6d7f3fb1056b6d59e945
|
7
|
+
data.tar.gz: a1c42b7e6b6de6c12e25b0de57d0ca980b8f9cc6ec1cefd71e1851f4426795285106802e6ae22c9f95539573f72abaf8b1f0432ce9b706cac86962725b73dbc7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mindwords.rb
CHANGED
@@ -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,53 @@ class MindWords
|
|
19
20
|
using ColouredText
|
20
21
|
using HashCopy
|
21
22
|
|
23
|
+
attr_accessor :lines, :filepath
|
22
24
|
|
23
|
-
def initialize(
|
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
|
-
|
61
|
-
|
62
|
-
e2.parent.add e
|
63
|
-
e2.delete
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
|
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
|
-
|
29
|
+
s, type = RXFHelper.read raws
|
88
30
|
|
89
|
-
|
90
|
-
|
91
|
-
|
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 add(line)
|
38
|
+
@lines << line
|
39
|
+
end
|
40
|
+
|
41
|
+
def breadcrumb()
|
42
|
+
@parent.attributes[:breadcrumb].split(/ +\/ +/) if @parent
|
43
|
+
end
|
44
|
+
|
45
|
+
|
117
46
|
def element(id)
|
118
47
|
|
119
|
-
doc = Rexle.new(
|
48
|
+
doc = Rexle.new(to_xml())
|
120
49
|
e = doc.root.element("//*[@id='#{id}']")
|
121
50
|
#e.attributes[:breadcrumb].to_s if e
|
122
51
|
|
123
|
-
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def hashtags()
|
55
|
+
@parent.attributes[:hashtags].split if @parent
|
56
|
+
end
|
57
|
+
|
58
|
+
def save(file=@filepath)
|
59
|
+
|
60
|
+
return if @lines.empty?
|
61
|
+
|
62
|
+
puts 'before save' if @debug
|
63
|
+
File.write file, to_s()
|
64
|
+
|
65
|
+
end
|
124
66
|
|
125
67
|
def search(keyword)
|
126
68
|
|
127
|
-
a = @
|
69
|
+
a = @lines.grep(/#{keyword}/i).map do |line|
|
128
70
|
|
129
71
|
puts 'line: ' + line.inspect if @debug
|
130
72
|
|
@@ -141,12 +83,16 @@ class MindWords
|
|
141
83
|
|
142
84
|
a2 = a.sort_by(&:last).map(&:first)
|
143
85
|
puts 'a2: ' + a2.inspect if @debug
|
144
|
-
|
86
|
+
e = element(keyword.downcase.gsub(/ +/,'-'))
|
87
|
+
|
88
|
+
return nil if e.nil?
|
89
|
+
|
90
|
+
MindWords.new(a2.join, parent: e, debug: @debug)
|
145
91
|
|
146
92
|
end
|
147
93
|
|
148
94
|
def sort()
|
149
|
-
s = @
|
95
|
+
s = @lines.sort.join
|
150
96
|
|
151
97
|
def s.to_s()
|
152
98
|
self.lines.map do |x|
|
@@ -159,13 +105,13 @@ class MindWords
|
|
159
105
|
end
|
160
106
|
|
161
107
|
def sort!()
|
162
|
-
@
|
108
|
+
@lines = sort().lines
|
163
109
|
self
|
164
110
|
end
|
165
111
|
|
166
112
|
def tag_sort()
|
167
113
|
|
168
|
-
h = @
|
114
|
+
h = @lines.group_by {|x| x[/#\w+/]}
|
169
115
|
s = h.sort.map {|key, value| value.sort }.join
|
170
116
|
|
171
117
|
def s.to_s()
|
@@ -180,7 +126,7 @@ class MindWords
|
|
180
126
|
end
|
181
127
|
|
182
128
|
def tag_sort!()
|
183
|
-
@
|
129
|
+
@lines = tag_sort().lines
|
184
130
|
self
|
185
131
|
end
|
186
132
|
|
@@ -193,15 +139,16 @@ class MindWords
|
|
193
139
|
end
|
194
140
|
|
195
141
|
def to_outline(sort: true)
|
142
|
+
build()
|
196
143
|
sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
|
197
144
|
end
|
198
145
|
|
199
146
|
def to_s(colour: false)
|
200
147
|
|
201
148
|
header = "<?mindwords?>\n\n"
|
202
|
-
return header + @
|
149
|
+
return header + @lines.map(&:chomp).join("\n") unless colour
|
203
150
|
|
204
|
-
body = @
|
151
|
+
body = @lines.map do |x|
|
205
152
|
title, hashtags = x.split(/(?=#)/,2)
|
206
153
|
title + hashtags.chomp.brown
|
207
154
|
end.join("\n")
|
@@ -215,11 +162,97 @@ class MindWords
|
|
215
162
|
end
|
216
163
|
|
217
164
|
def to_xml()
|
165
|
+
build() unless @xml
|
218
166
|
@xml
|
219
167
|
end
|
220
168
|
|
221
169
|
private
|
222
170
|
|
171
|
+
def build()
|
172
|
+
|
173
|
+
h = {}
|
174
|
+
|
175
|
+
@lines.each do |line|
|
176
|
+
|
177
|
+
title, rawtags = line.split(/ (?=#)/,2)
|
178
|
+
|
179
|
+
rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
|
180
|
+
tag = rawtag.gsub(/ +/, '_')
|
181
|
+
h[tag] ||= []
|
182
|
+
h[tag] << title
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
@hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
|
188
|
+
|
189
|
+
|
190
|
+
a = rexlize(h)
|
191
|
+
doc = Rexle.new(['root', {}, '', *a])
|
192
|
+
|
193
|
+
# apply node nesting
|
194
|
+
|
195
|
+
doc.root.elements.each do |e|
|
196
|
+
|
197
|
+
doc.root.xpath('//' + e.name).each do |e2|
|
198
|
+
|
199
|
+
next if e2 === e
|
200
|
+
|
201
|
+
e2.parent.add e
|
202
|
+
e2.delete
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
# remove duplicates which appear in the same branch above the nested node
|
210
|
+
rm_duplicates(doc)
|
211
|
+
|
212
|
+
# remove redundant nodes (outsiders)
|
213
|
+
# a redundant node is where all children exist in existing nested nodes
|
214
|
+
|
215
|
+
redundants = doc.root.elements.map do |e|
|
216
|
+
|
217
|
+
r = e.elements.all? {|x| !x.has_elements?}
|
218
|
+
puts "%s %s" % [e.name, r] if @debug
|
219
|
+
dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
|
220
|
+
puts 'dups: ' + dups.inspect if @debug
|
221
|
+
e.backtrack.to_s if dups
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
redundants.compact.each {|x| doc.element(x).delete }
|
226
|
+
|
227
|
+
|
228
|
+
node = if @parent then
|
229
|
+
found = doc.root.element('//' + @parent.name)
|
230
|
+
found ? found : doc.root
|
231
|
+
else
|
232
|
+
doc.root
|
233
|
+
end
|
234
|
+
|
235
|
+
@outline = treeize node
|
236
|
+
|
237
|
+
node.root.each_recursive do |e|
|
238
|
+
|
239
|
+
e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
|
240
|
+
|
241
|
+
s = e.parent.attributes[:breadcrumb] ? \
|
242
|
+
e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
|
243
|
+
e.attributes[:breadcrumb] = s + e.value.strip
|
244
|
+
|
245
|
+
r = @lines.grep(/^#{e.attributes[:title]} #/i)
|
246
|
+
next unless r.any?
|
247
|
+
e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
|
248
|
+
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
@xml = node.xml pretty: true
|
253
|
+
|
254
|
+
end
|
255
|
+
|
223
256
|
def rexlize(a)
|
224
257
|
|
225
258
|
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
|
4
|
+
version: 0.5.4
|
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-
|
38
|
+
date: 2021-01-29 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
|