mindwords 0.5.4 → 0.6.1

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: 14ea1cb6b906664113ef2137b3cad143b365d37c9eb0612df38a0b9e2cfdfeac
4
- data.tar.gz: 8d4a298c78f32c500a941699791b1f6b952075c15b67fb088392c8860fb01fa7
3
+ metadata.gz: 1513378395921df0332fa183e9f1bbbb4de0effebaa125ac9cbdaaf5c2043a53
4
+ data.tar.gz: 0fdbe75ed727876a2ba3e62c4d67cf9f21bcd64b61cb252cb795b5ae260d0859
5
5
  SHA512:
6
- metadata.gz: 87afa7b5bd0b7f2cf225177259df456021e90155f57d40712042b13a37105bf879fcea494ce0b05f2b53911717dbf3cebaf6a6b9cfff6d7f3fb1056b6d59e945
7
- data.tar.gz: a1c42b7e6b6de6c12e25b0de57d0ca980b8f9cc6ec1cefd71e1851f4426795285106802e6ae22c9f95539573f72abaf8b1f0432ce9b706cac86962725b73dbc7
6
+ metadata.gz: 85b57f0e300b6859f4c98a2263920eb5a65014c74711e021f1c52144d6c32c224df4691d8bef4b90b9a69e7f6a95d67e043ccc1100255ac96c6dfe746a592adb
7
+ data.tar.gz: dd2ea283e94912e221dfcc463c1f5270ad751b0e7fc968abb6bb19b7dedfe91d29b93fbe3312c96d3726b6d3067b5a7a4d73ee469bf74fc0311423668755edef
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/mindwords.rb CHANGED
@@ -29,8 +29,30 @@ class MindWords
29
29
  s, type = RXFHelper.read raws
30
30
 
31
31
  @filepath = raws if type == :file or type == :dfs
32
- @lines = s.strip.gsub(/^\n/,'').lines
33
- @lines.shift if @lines.first =~ /<\?mindwords\?>/
32
+ lines = s.strip.gsub(/^\n/,'').lines
33
+ lines.shift if lines.first =~ /<\?mindwords\?>/
34
+
35
+ @lines = lines.inject([]) do |r,line|
36
+
37
+ # the following does 2 things:
38
+ # 1. splits words separated by a bar (|) onto their own line
39
+ # 2. prefixes a word with an underscore if the word is the
40
+ # same as the hashtag. That way it's not removed by the
41
+ # redundancy checker
42
+
43
+ raw_words, raw_hashtags = line.split(/(?= #)/,2)
44
+ words = raw_words.split(/ *\| */)
45
+ hashtags = raw_hashtags.scan(/(?<=#)\w+/)
46
+
47
+ words.each do |word|
48
+
49
+ linex = (word + raw_hashtags)
50
+ r << (hashtags.include?(word) ? linex.sub!(/\b#{word}\b/, '_\0') \
51
+ : linex)
52
+ end
53
+
54
+ r
55
+ end
34
56
 
35
57
  end
36
58
 
@@ -41,6 +63,10 @@ class MindWords
41
63
  def breadcrumb()
42
64
  @parent.attributes[:breadcrumb].split(/ +\/ +/) if @parent
43
65
  end
66
+
67
+ def headings()
68
+ breadcrumb[0..-2]
69
+ end
44
70
 
45
71
 
46
72
  def element(id)
@@ -63,8 +89,43 @@ class MindWords
63
89
  File.write file, to_s()
64
90
 
65
91
  end
92
+
93
+ # Accepts a list of words with the aim of returning a MindWords document
94
+ # using matched words with hashtags from the existing MindWords document.
95
+ #
96
+ def reflect(raws)
97
+
98
+ h = to_h
99
+
100
+ missing_words = []
101
+
102
+ # add the tags from the main list
103
+ a = raws.strip.lines.map do |x|
104
+ if h[x.chomp] then
105
+ [x.chomp, h[x.chomp]]
106
+ else
107
+ missing_words << x
108
+ nil
109
+ end
110
+ end.compact
111
+
112
+ # add any linkage words from the tags
113
+ #
114
+ a.map(&:last).flatten(1).each do |s|
115
+
116
+ a << [s, h[s]] if h[s]
117
+
118
+ end
119
+
120
+ # remove suplicates lines and transform it into a raw mindwords format
121
+ #
122
+ raws3 = a.uniq.map {|s,tags| [s, tags.map {|x| '#' + x }.join(' ')].join(' ') }.join("\n")
123
+
124
+ [MindWords.new(raws3), missing_words]
125
+
126
+ end
66
127
 
67
- def search(keyword)
128
+ def search(keyword, succinct: true)
68
129
 
69
130
  a = @lines.grep(/#{keyword}/i).map do |line|
70
131
 
@@ -85,9 +146,32 @@ class MindWords
85
146
  puts 'a2: ' + a2.inspect if @debug
86
147
  e = element(keyword.downcase.gsub(/ +/,'-'))
87
148
 
88
- return nil if e.nil?
149
+ return MindWords.new(a2.uniq.join, debug: @debug) if e.nil?
150
+
151
+ # find and add any linkage support lines
152
+ #
153
+
154
+ a3 = []
155
+
156
+ a2.each do |line|
157
+
158
+ line.chomp.scan(/#[^ ]+/).each do |hashtag|
159
+
160
+ puts 'hashtag: ' + hashtag.inspect if @debug
161
+ r2 = @lines.grep(/^#{hashtag[1..-1]} #/)
162
+ a3 << r2.first if r2
163
+
164
+ end
165
+ end
166
+
167
+ puts 'a2: ' + a2.inspect if @debug
168
+ a2.concat a3
89
169
 
90
- MindWords.new(a2.join, parent: e, debug: @debug)
170
+ if succinct then
171
+ MindWords.new(a2.uniq.join, parent: e, debug: @debug)
172
+ else
173
+ MindWords.new(a2.uniq.join, debug: @debug)
174
+ end
91
175
 
92
176
  end
93
177
 
@@ -129,11 +213,20 @@ class MindWords
129
213
  @lines = tag_sort().lines
130
214
  self
131
215
  end
216
+
217
+ def to_a()
218
+
219
+ @lines.map do |x|
220
+ s, rawtags = x.split(/(?= #)/,2)
221
+ [s, rawtags.scan(/(?<=#)\w+/)]
222
+ end
223
+
224
+ end
132
225
 
133
226
  def to_h()
134
- @h
227
+ to_a.to_h
135
228
  end
136
-
229
+
137
230
  def to_hashtags()
138
231
  @hashtags
139
232
  end
@@ -143,6 +236,8 @@ class MindWords
143
236
  sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
144
237
  end
145
238
 
239
+ alias to_tree to_outline
240
+
146
241
  def to_s(colour: false)
147
242
 
148
243
  header = "<?mindwords?>\n\n"
@@ -155,11 +250,24 @@ class MindWords
155
250
 
156
251
  header + body
157
252
 
158
- end
253
+ end
159
254
 
160
255
  def to_words()
161
- to_outline.lines.map {|x| x[/\w[\w ]+/] }.uniq
162
- end
256
+
257
+ h = {}
258
+
259
+ Rexle.new(to_xml).root.each_recursive do |e|
260
+
261
+ h[e.attributes[:title]] = {
262
+ breadcrumb: e.attributes[:breadcrumb],
263
+ hashtags: e.attributes[:hashtags]
264
+ }
265
+
266
+ end
267
+
268
+ h
269
+
270
+ end
163
271
 
164
272
  def to_xml()
165
273
  build() unless @xml
@@ -174,12 +282,12 @@ class MindWords
174
282
 
175
283
  @lines.each do |line|
176
284
 
177
- title, rawtags = line.split(/ (?=#)/,2)
285
+ title, rawtags = line.split(/(?= #)/,2)
178
286
 
179
287
  rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
180
288
  tag = rawtag.gsub(/ +/, '_')
181
289
  h[tag] ||= []
182
- h[tag] << title
290
+ h[tag] << title.strip
183
291
  end
184
292
 
185
293
  end
@@ -224,14 +332,30 @@ class MindWords
224
332
 
225
333
  redundants.compact.each {|x| doc.element(x).delete }
226
334
 
227
-
228
335
  node = if @parent then
229
336
  found = doc.root.element('//' + @parent.name)
230
- found ? found : doc.root
337
+ found ? found.parent : doc.root
231
338
  else
232
339
  doc.root
233
340
  end
234
341
 
342
+ # the following removes any undescore prefix from words which were the
343
+ # same as the hashtag
344
+
345
+ node.root.each_recursive do |e|
346
+
347
+ next unless e
348
+ puts 'e: ' + e.inspect if @debug
349
+
350
+ e.attributes[:id] = e.attributes[:id].sub(/^_/,'') if e.attributes[:id]
351
+ e.attributes[:title] = e.attributes[:title].sub(/^_/,'') if e.attributes[:title]
352
+ e.value = e.value.sub(/^_/,'')
353
+ e.name = e.name.sub(/^_/,'')
354
+
355
+ end
356
+
357
+ # ----
358
+
235
359
  @outline = treeize node
236
360
 
237
361
  node.root.each_recursive do |e|
@@ -294,7 +418,7 @@ class MindWords
294
418
 
295
419
  duplicates.each do |path|
296
420
 
297
- puts 'path: ' + path.inspect if @debug
421
+ puts 'pathx: ' + path.inspect if @debug
298
422
  e = doc.element(path)
299
423
  e.delete if e
300
424
 
@@ -340,3 +464,25 @@ class MindWords
340
464
 
341
465
  end
342
466
 
467
+ class MindWordsWidget
468
+
469
+ def initialize()
470
+
471
+ end
472
+
473
+
474
+ # can be used for main entries or a words list
475
+ #
476
+ def input(content: '', action: 'mwupdate', target: 'icontent')
477
+
478
+ <<EOF
479
+ <form action='#{action}' method='post' target='#{target}'>
480
+ <textarea name='content' cols='30' rows='19'>
481
+ #{content}
482
+ </textarea>
483
+ <input type='submit' value='Submit'/>
484
+ </form>
485
+ EOF
486
+ end
487
+
488
+ end
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.5.4
4
+ version: 0.6.1
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-29 00:00:00.000000000 Z
38
+ date: 2021-04-09 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: line-tree
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '0.9'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.9.1
49
+ version: 0.9.2
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '0.9'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.9.1
59
+ version: 0.9.2
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rxfhelper
62
62
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file