mindwords 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mindwords.rb +99 -97
- metadata +1 -1
- 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: cecbfa6443266445084268c94ccedf12ca1f1c4a8e601a510ad49d375c54e910
|
4
|
+
data.tar.gz: 184f031666fbc23c62ca1fb7b61bbfbce99a1bd88c75072fc9645153f4e1f502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fd523b6544be615a5a1112deca758af2cc5f6053f03e48c4382acecd413f32db9ed440d572171be342fd64141c0f34debd18f7bd6ebc615cf125029e86ce3f4
|
7
|
+
data.tar.gz: 047f68b8746aa20cda1bff2e9c09472fee21f70d4f36cee1599576b71f6243b5107e45f632eedf2ab2e953e9df00867dda4b9a94ec13f896f6d38a136cda9ed9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mindwords.rb
CHANGED
@@ -20,100 +20,15 @@ class MindWords
|
|
20
20
|
using ColouredText
|
21
21
|
using HashCopy
|
22
22
|
|
23
|
+
attr_accessor :lines
|
23
24
|
|
24
25
|
def initialize(raws, parent: nil, debug: false)
|
25
26
|
|
26
|
-
@debug = debug
|
27
|
+
@parent, @debug = parent, debug
|
27
28
|
|
28
29
|
s, _ = RXFHelper.read raws
|
29
|
-
@
|
30
|
-
@
|
31
|
-
|
32
|
-
lines = @a.map do |line|
|
33
|
-
|
34
|
-
word = line.split(/ (?=#)/,2)
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
h = {}
|
39
|
-
@hashtags = {}
|
40
|
-
|
41
|
-
lines.each do |title, rawtags|
|
42
|
-
|
43
|
-
rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
|
44
|
-
tag = rawtag.gsub(/ +/, '_')
|
45
|
-
h[tag] ||= []
|
46
|
-
h[tag] << title
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
@hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
|
52
|
-
|
53
|
-
|
54
|
-
a = rexlize(h)
|
55
|
-
doc = Rexle.new(['root', {}, '', *a])
|
56
|
-
|
57
|
-
# apply node nesting
|
58
|
-
|
59
|
-
doc.root.elements.each do |e|
|
60
|
-
|
61
|
-
doc.root.xpath('//' + e.name).each do |e2|
|
62
|
-
|
63
|
-
next if e2 === e
|
64
|
-
|
65
|
-
e2.parent.add e
|
66
|
-
e2.delete
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# remove duplicates which appear in the same branch above the nested node
|
74
|
-
rm_duplicates(doc)
|
75
|
-
|
76
|
-
# remove redundant nodes (outsiders)
|
77
|
-
# a redundant node is where all children exist in existing nested nodes
|
78
|
-
|
79
|
-
redundants = doc.root.elements.map do |e|
|
80
|
-
|
81
|
-
r = e.elements.all? {|x| !x.has_elements?}
|
82
|
-
puts "%s %s" % [e.name, r] if @debug
|
83
|
-
dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
|
84
|
-
puts 'dups: ' + dups.inspect if @debug
|
85
|
-
e.backtrack.to_s if dups
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
redundants.compact.each {|x| doc.element(x).delete }
|
90
|
-
|
91
|
-
|
92
|
-
node = if parent then
|
93
|
-
found = doc.root.element('//' + parent)
|
94
|
-
found ? found : doc.root
|
95
|
-
else
|
96
|
-
doc.root
|
97
|
-
end
|
98
|
-
|
99
|
-
@outline = treeize node
|
100
|
-
|
101
|
-
node.root.each_recursive do |e|
|
102
|
-
|
103
|
-
e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
|
104
|
-
|
105
|
-
s = e.parent.attributes[:breadcrumb] ? \
|
106
|
-
e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
|
107
|
-
e.attributes[:breadcrumb] = s + e.value.strip
|
108
|
-
|
109
|
-
r = @a.grep(/^#{e.attributes[:title]} #/i)
|
110
|
-
next unless r.any?
|
111
|
-
e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
@xml = node.xml pretty: true
|
30
|
+
@lines = s.strip.gsub(/^\n/,'').lines
|
31
|
+
@lines.shift if @lines.first =~ /<\?mindwords\?>/
|
117
32
|
|
118
33
|
end
|
119
34
|
|
@@ -123,11 +38,12 @@ class MindWords
|
|
123
38
|
e = doc.root.element("//*[@id='#{id}']")
|
124
39
|
#e.attributes[:breadcrumb].to_s if e
|
125
40
|
|
126
|
-
end
|
41
|
+
end
|
42
|
+
|
127
43
|
|
128
44
|
def search(keyword)
|
129
45
|
|
130
|
-
a = @
|
46
|
+
a = @lines.grep(/#{keyword}/i).map do |line|
|
131
47
|
|
132
48
|
puts 'line: ' + line.inspect if @debug
|
133
49
|
|
@@ -149,7 +65,7 @@ class MindWords
|
|
149
65
|
end
|
150
66
|
|
151
67
|
def sort()
|
152
|
-
s = @
|
68
|
+
s = @lines.sort.join
|
153
69
|
|
154
70
|
def s.to_s()
|
155
71
|
self.lines.map do |x|
|
@@ -162,13 +78,13 @@ class MindWords
|
|
162
78
|
end
|
163
79
|
|
164
80
|
def sort!()
|
165
|
-
@
|
81
|
+
@lines = sort().lines
|
166
82
|
self
|
167
83
|
end
|
168
84
|
|
169
85
|
def tag_sort()
|
170
86
|
|
171
|
-
h = @
|
87
|
+
h = @lines.group_by {|x| x[/#\w+/]}
|
172
88
|
s = h.sort.map {|key, value| value.sort }.join
|
173
89
|
|
174
90
|
def s.to_s()
|
@@ -183,7 +99,7 @@ class MindWords
|
|
183
99
|
end
|
184
100
|
|
185
101
|
def tag_sort!()
|
186
|
-
@
|
102
|
+
@lines = tag_sort().lines
|
187
103
|
self
|
188
104
|
end
|
189
105
|
|
@@ -196,15 +112,16 @@ class MindWords
|
|
196
112
|
end
|
197
113
|
|
198
114
|
def to_outline(sort: true)
|
115
|
+
build()
|
199
116
|
sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
|
200
117
|
end
|
201
118
|
|
202
119
|
def to_s(colour: false)
|
203
120
|
|
204
121
|
header = "<?mindwords?>\n\n"
|
205
|
-
return header + @
|
122
|
+
return header + @lines.join unless colour
|
206
123
|
|
207
|
-
body = @
|
124
|
+
body = @lines.map do |x|
|
208
125
|
title, hashtags = x.split(/(?=#)/,2)
|
209
126
|
title + hashtags.chomp.brown
|
210
127
|
end.join("\n")
|
@@ -223,6 +140,91 @@ class MindWords
|
|
223
140
|
|
224
141
|
private
|
225
142
|
|
143
|
+
def build()
|
144
|
+
|
145
|
+
h = {}
|
146
|
+
|
147
|
+
@lines.each do |line|
|
148
|
+
|
149
|
+
title, rawtags = line.split(/ (?=#)/,2)
|
150
|
+
|
151
|
+
rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
|
152
|
+
tag = rawtag.gsub(/ +/, '_')
|
153
|
+
h[tag] ||= []
|
154
|
+
h[tag] << title
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
@hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
|
160
|
+
|
161
|
+
|
162
|
+
a = rexlize(h)
|
163
|
+
doc = Rexle.new(['root', {}, '', *a])
|
164
|
+
|
165
|
+
# apply node nesting
|
166
|
+
|
167
|
+
doc.root.elements.each do |e|
|
168
|
+
|
169
|
+
doc.root.xpath('//' + e.name).each do |e2|
|
170
|
+
|
171
|
+
next if e2 === e
|
172
|
+
|
173
|
+
e2.parent.add e
|
174
|
+
e2.delete
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# remove duplicates which appear in the same branch above the nested node
|
182
|
+
rm_duplicates(doc)
|
183
|
+
|
184
|
+
# remove redundant nodes (outsiders)
|
185
|
+
# a redundant node is where all children exist in existing nested nodes
|
186
|
+
|
187
|
+
redundants = doc.root.elements.map do |e|
|
188
|
+
|
189
|
+
r = e.elements.all? {|x| !x.has_elements?}
|
190
|
+
puts "%s %s" % [e.name, r] if @debug
|
191
|
+
dups = e.elements.all? {|x| doc.root.xpath('//' + x.name).length > 1}
|
192
|
+
puts 'dups: ' + dups.inspect if @debug
|
193
|
+
e.backtrack.to_s if dups
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
redundants.compact.each {|x| doc.element(x).delete }
|
198
|
+
|
199
|
+
|
200
|
+
node = if @parent then
|
201
|
+
found = doc.root.element('//' + @parent)
|
202
|
+
found ? found : doc.root
|
203
|
+
else
|
204
|
+
doc.root
|
205
|
+
end
|
206
|
+
|
207
|
+
@outline = treeize node
|
208
|
+
|
209
|
+
node.root.each_recursive do |e|
|
210
|
+
|
211
|
+
e.attributes[:id] = e.attributes[:title].downcase.gsub(/ +/,'-')
|
212
|
+
|
213
|
+
s = e.parent.attributes[:breadcrumb] ? \
|
214
|
+
e.parent.attributes[:breadcrumb].to_s + ' / ' : ''
|
215
|
+
e.attributes[:breadcrumb] = s + e.value.strip
|
216
|
+
|
217
|
+
r = @lines.grep(/^#{e.attributes[:title]} #/i)
|
218
|
+
next unless r.any?
|
219
|
+
e.attributes[:hashtags] = r[0].scan(/(?<=#)\w+/).join(' ')
|
220
|
+
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
@xml = node.xml pretty: true
|
225
|
+
|
226
|
+
end
|
227
|
+
|
226
228
|
def rexlize(a)
|
227
229
|
|
228
230
|
a.map do |x|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|