mindwords 0.1.2 → 0.4.1
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 +111 -39
- metadata +9 -8
- 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: 4070b252c0702dbfa6cb778a8717e75e60cf5de4454f1e475f496bec0bd4328d
|
4
|
+
data.tar.gz: 52493b20e6b137e396136b58a8c9a89e45650bff9d44caa73c9a78bfa86c8174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7576fde49c1d5fccc4ce87ae583e0648c4511a0637afbce67265bc57812ec8fe74a9237db6664e03632a11d95289ab14a08343392ead7a685a7afec2fe20a07
|
7
|
+
data.tar.gz: df0d3b1b29866892eaa111e579da3a6e906266a524954b98ef9d5665d192c665f5bf5eaec15cef1708cc39fc2499ddf48774400e449ef868cc8f5dbfe1bfde2c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mindwords.rb
CHANGED
@@ -3,51 +3,69 @@
|
|
3
3
|
# file: mindwords.rb
|
4
4
|
|
5
5
|
require 'rexle'
|
6
|
+
require 'line-tree'
|
7
|
+
|
8
|
+
module HashCopy
|
9
|
+
refine Hash do
|
10
|
+
|
11
|
+
def deep_clone()
|
12
|
+
Marshal.load(Marshal.dump(self))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
6
17
|
|
7
18
|
class MindWords
|
8
19
|
using ColouredText
|
20
|
+
using HashCopy
|
21
|
+
|
9
22
|
|
10
|
-
def initialize(s, debug: false)
|
23
|
+
def initialize(s, parent: nil, debug: false)
|
11
24
|
|
12
25
|
@debug = debug
|
13
|
-
@a = s.strip.lines
|
26
|
+
@a = s.strip.gsub(/^\n/,'').lines
|
27
|
+
@a.shift if @a.first =~ /<\?mindwords\?>/
|
14
28
|
|
15
29
|
lines = @a.map do |line|
|
16
30
|
|
17
31
|
word = line.split(/ (?=#)/,2)
|
18
32
|
|
19
33
|
end
|
20
|
-
|
34
|
+
|
21
35
|
h = {}
|
36
|
+
@hashtags = {}
|
22
37
|
|
23
|
-
lines.each do |
|
38
|
+
lines.each do |title, rawtags|
|
24
39
|
|
25
|
-
|
40
|
+
rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
|
26
41
|
tag = rawtag.gsub(/ +/, '_')
|
27
42
|
h[tag] ||= []
|
28
|
-
h[tag] <<
|
43
|
+
h[tag] << title
|
29
44
|
end
|
30
45
|
|
31
46
|
end
|
47
|
+
|
48
|
+
@hashtags = h.deep_clone.sort.map {|tag, fields| [tag, fields.sort]}.to_h
|
32
49
|
|
33
|
-
# does the key exist as a field?
|
34
|
-
|
35
|
-
h.keys.each do |key|
|
36
|
-
|
37
|
-
r = h.detect {|_, value| value.include? key}
|
38
|
-
next unless r
|
39
|
-
h[r.first].delete key
|
40
|
-
h[r.first] << {key => h[key]}
|
41
|
-
#puts r.inspect
|
42
|
-
h.delete key
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
@h = h
|
47
50
|
|
48
51
|
a = rexlize(h)
|
49
52
|
doc = Rexle.new(['root', {}, '', *a])
|
50
53
|
|
54
|
+
# apply node nesting
|
55
|
+
|
56
|
+
doc.root.elements.each do |e|
|
57
|
+
|
58
|
+
doc.root.xpath('//' + e.name).each do |e2|
|
59
|
+
|
60
|
+
next if e2 === e
|
61
|
+
|
62
|
+
e2.parent.add e
|
63
|
+
e2.delete
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
51
69
|
|
52
70
|
# remove duplicates which appear in the same branch above the nested node
|
53
71
|
rm_duplicates(doc)
|
@@ -66,17 +84,50 @@ class MindWords
|
|
66
84
|
end
|
67
85
|
|
68
86
|
redundants.compact.each {|x| doc.element(x).delete }
|
69
|
-
|
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
|
70
95
|
|
71
|
-
@
|
72
|
-
|
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
|
73
114
|
|
74
115
|
end
|
75
116
|
|
117
|
+
def element(id)
|
118
|
+
|
119
|
+
doc = Rexle.new(@xml)
|
120
|
+
e = doc.root.element("//*[@id='#{id}']")
|
121
|
+
#e.attributes[:breadcrumb].to_s if e
|
122
|
+
|
123
|
+
end
|
124
|
+
|
76
125
|
def search(keyword)
|
77
126
|
|
78
127
|
a = @a.grep(/#{keyword}/i).map do |line|
|
79
128
|
|
129
|
+
puts 'line: ' + line.inspect if @debug
|
130
|
+
|
80
131
|
words = line.split
|
81
132
|
r = words.grep /#{keyword}/i
|
82
133
|
i = words.index r[0]
|
@@ -89,7 +140,8 @@ class MindWords
|
|
89
140
|
#return a[0][0] if a.length < 2
|
90
141
|
|
91
142
|
a2 = a.sort_by(&:last).map(&:first)
|
92
|
-
|
143
|
+
puts 'a2: ' + a2.inspect if @debug
|
144
|
+
MindWords.new(a2.join, parent: keyword, debug: @debug)
|
93
145
|
|
94
146
|
end
|
95
147
|
|
@@ -135,6 +187,10 @@ class MindWords
|
|
135
187
|
def to_h()
|
136
188
|
@h
|
137
189
|
end
|
190
|
+
|
191
|
+
def to_hashtags()
|
192
|
+
@hashtags
|
193
|
+
end
|
138
194
|
|
139
195
|
def to_outline(sort: true)
|
140
196
|
sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
|
@@ -142,12 +198,20 @@ class MindWords
|
|
142
198
|
|
143
199
|
def to_s(colour: false)
|
144
200
|
|
145
|
-
|
201
|
+
header = "<?mindwords?>\n\n"
|
202
|
+
return header + @a.join unless colour
|
146
203
|
|
147
|
-
@a.map do |x|
|
204
|
+
body = @a.map do |x|
|
148
205
|
title, hashtags = x.split(/(?=#)/,2)
|
149
206
|
title + hashtags.chomp.brown
|
150
207
|
end.join("\n")
|
208
|
+
|
209
|
+
header + body
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
def to_words()
|
214
|
+
to_outline.lines.map {|x| x[/\w[\w ]+/] }
|
151
215
|
end
|
152
216
|
|
153
217
|
def to_xml()
|
@@ -164,11 +228,19 @@ class MindWords
|
|
164
228
|
|
165
229
|
case x
|
166
230
|
when String
|
167
|
-
[x.gsub(/ +/,'
|
231
|
+
[x.downcase.gsub(/ +/,''), {title: x}, x]
|
168
232
|
when Hash
|
169
|
-
[
|
233
|
+
[
|
234
|
+
x.keys.first.downcase.gsub(/_/,' '),
|
235
|
+
{title: x.keys.first},
|
236
|
+
x.keys.first,
|
237
|
+
*rexlize(x.values.first)
|
238
|
+
]
|
170
239
|
when Array
|
171
|
-
[
|
240
|
+
[
|
241
|
+
x.first.downcase.gsub(/_/,' '),
|
242
|
+
{title: x.first}, x.first, *rexlize(x.last)
|
243
|
+
]
|
172
244
|
end
|
173
245
|
end
|
174
246
|
|
@@ -177,23 +249,22 @@ class MindWords
|
|
177
249
|
def rm_duplicates(doc)
|
178
250
|
|
179
251
|
duplicates = []
|
252
|
+
|
180
253
|
doc.root.each_recursive do |e|
|
181
254
|
|
182
|
-
puts 'e: ' + e.name.inspect if @debug
|
183
255
|
rows = e.parent.xpath('//' + e.name)
|
184
256
|
next if rows.length < 2
|
185
257
|
|
186
|
-
rows[
|
187
|
-
|
188
|
-
duplicates << [e.backtrack.to_s, e2.backtrack.to_s]
|
189
|
-
end
|
258
|
+
rows[0..-2].each {|e2| duplicates << e.backtrack.to_s }
|
259
|
+
|
190
260
|
end
|
191
261
|
|
192
|
-
duplicates.each do |path
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
262
|
+
duplicates.each do |path|
|
263
|
+
|
264
|
+
puts 'path: ' + path.inspect if @debug
|
265
|
+
e = doc.element(path)
|
266
|
+
e.delete if e
|
267
|
+
|
197
268
|
end
|
198
269
|
|
199
270
|
end
|
@@ -235,3 +306,4 @@ class MindWords
|
|
235
306
|
end
|
236
307
|
|
237
308
|
end
|
309
|
+
|
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.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ 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-22 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: line-tree
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '0.9'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 0.9.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '0.9'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 0.9.1
|
60
60
|
description:
|
61
61
|
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
@@ -83,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.10
|
87
88
|
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: Helps get what's in your mind into a structure using words and hashtags.
|
metadata.gz.sig
CHANGED
Binary file
|