mindwords 0.5.5 → 0.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dce3985e118c20bf9564d5d5d80b471cfb1422387d02a9b2faedaa29ee6b847
4
- data.tar.gz: c74d01bae140212eb3e3d8f6a65fed89a1fde92920fd4924f4f32b15cc8fd901
3
+ metadata.gz: 18ab26d7ab5ff288172a06294982093e97db2b22998cb627ce5f7201dac62a6f
4
+ data.tar.gz: b717eb9f9b9c99d88ed27b33913834f361ceb5715fd9e4e7bdff3bcf7abf9089
5
5
  SHA512:
6
- metadata.gz: 7867fb1ac1224ec7d5f4515b450182d01344fe95cd4002409fe45eeb59a6cedaa7ba07074c1f22030d332fe3a09e4290c1aa0243e5033575898b098328aa160c
7
- data.tar.gz: 0c10f58552946d28c0a81fca5e1ce078575ec8c7402e2b64bc8c56e1b24c0979053356898af377f036d7bdabfd9e4957bc87e970eded50a7ee3d94703ab75b88
6
+ metadata.gz: ab92bd3423e50ad635cfd986d817a874db78b2fb7d57db01300400ce4dd5d267d706e1e642442c6bf4d9b5a84448d8be0fe0c13684cf3cfb160523e67da251d0
7
+ data.tar.gz: b7b6e3e7971d76f3cd42989a2b69fb6e1d5a933c80f5bcfa61fc65542819ecc2d9b711f7d4af8d77ad8a9d3f4cf7e8a310cd1ce68574d511fbfa2e73af020c13
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/mindwords.rb CHANGED
@@ -29,18 +29,46 @@ 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.uniq
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
 
37
- def add(line)
38
- @lines << line
59
+ def add(s)
60
+
61
+ @lines.concat s.strip.lines
62
+
39
63
  end
40
64
 
41
65
  def breadcrumb()
42
66
  @parent.attributes[:breadcrumb].split(/ +\/ +/) if @parent
43
67
  end
68
+
69
+ def headings()
70
+ breadcrumb[0..-2]
71
+ end
44
72
 
45
73
 
46
74
  def element(id)
@@ -54,17 +82,75 @@ class MindWords
54
82
  def hashtags()
55
83
  @parent.attributes[:hashtags].split if @parent
56
84
  end
85
+
86
+ # helpful when searching for a word itself using autosuggest
87
+ #
88
+ def lookup(s)
89
+ self.to_words.keys.sort.grep /^#{s}/i
90
+ end
91
+
92
+ # same as #lines but inludes the breadcrumb path; Helpful to identify
93
+ # which words don't have a breadcrumb path.
94
+ #
95
+ def linesplus()
96
+
97
+ to_a.map do |word, _|
98
+ r = search word
99
+ r ? [word, r.breadcrumb] : [r, nil]
100
+ end
101
+
102
+ end
57
103
 
58
104
  def save(file=@filepath)
59
105
 
60
106
  return if @lines.empty?
61
107
 
62
108
  puts 'before save' if @debug
63
- File.write file, to_s()
109
+
110
+ if File.exists? file then
111
+ File.write file, to_s()
112
+ else
113
+ raise 'Filepath not given'
114
+ end
115
+
116
+ end
117
+
118
+ # Accepts a list of words with the aim of returning a MindWords document
119
+ # using matched words with hashtags from the existing MindWords document.
120
+ #
121
+ def reflect(raws)
122
+
123
+ h = to_h
124
+
125
+ missing_words = []
126
+
127
+ # add the tags from the main list
128
+ a = raws.strip.lines.map do |x|
129
+ if h[x.chomp] then
130
+ [x.chomp, h[x.chomp]]
131
+ else
132
+ missing_words << x
133
+ nil
134
+ end
135
+ end.compact
136
+
137
+ # add any linkage words from the tags
138
+ #
139
+ a.map(&:last).flatten(1).each do |s|
140
+
141
+ a << [s, h[s]] if h[s]
142
+
143
+ end
144
+
145
+ # remove suplicates lines and transform it into a raw mindwords format
146
+ #
147
+ raws3 = a.uniq.map {|s,tags| [s, tags.map {|x| '#' + x }.join(' ')].join(' ') }.join("\n")
148
+
149
+ [MindWords.new(raws3), missing_words]
64
150
 
65
151
  end
66
152
 
67
- def search(keyword)
153
+ def search(keyword, succinct: true)
68
154
 
69
155
  a = @lines.grep(/#{keyword}/i).map do |line|
70
156
 
@@ -85,9 +171,32 @@ class MindWords
85
171
  puts 'a2: ' + a2.inspect if @debug
86
172
  e = element(keyword.downcase.gsub(/ +/,'-'))
87
173
 
88
- return nil if e.nil?
174
+ return MindWords.new(a2.uniq.join, debug: @debug) if e.nil?
175
+
176
+ # find and add any linkage support lines
177
+ #
178
+
179
+ a3 = []
180
+
181
+ a2.each do |line|
182
+
183
+ line.chomp.scan(/#[^ ]+/).each do |hashtag|
184
+
185
+ puts 'hashtag: ' + hashtag.inspect if @debug
186
+ r2 = @lines.grep(/^#{hashtag[1..-1]} #/)
187
+ a3 << r2.first if r2
188
+
189
+ end
190
+ end
191
+
192
+ puts 'a2: ' + a2.inspect if @debug
193
+ a2.concat a3
89
194
 
90
- MindWords.new(a2.join, parent: e, debug: @debug)
195
+ if succinct then
196
+ MindWords.new(a2.uniq.join, parent: e, debug: @debug)
197
+ else
198
+ MindWords.new(a2.uniq.join, debug: @debug)
199
+ end
91
200
 
92
201
  end
93
202
 
@@ -129,16 +238,40 @@ class MindWords
129
238
  @lines = tag_sort().lines
130
239
  self
131
240
  end
241
+
242
+ def to_a()
243
+
244
+ @lines.map do |x|
245
+ s, rawtags = x.split(/(?= #)/,2)
246
+ [s, rawtags.scan(/(?<=#)\w+/)]
247
+ end
248
+
249
+ end
250
+
251
+ def to_h()
252
+ to_a.to_h
253
+ end
132
254
 
133
255
  def to_hashtags()
134
256
  @hashtags
135
257
  end
136
258
 
137
259
  def to_outline(sort: true)
260
+
138
261
  build()
139
- sort ? a2tree(tree_sort(LineTree.new(@outline).to_a)) : @outline
262
+
263
+ if sort then
264
+ a = LineTree.new(@outline).to_a
265
+ puts ('a: ' + a.inspect).debug if @debug
266
+ a2tree(tree_sort(a))
267
+ else
268
+ @outline
269
+ end
270
+
140
271
  end
141
272
 
273
+ alias to_tree to_outline
274
+
142
275
  def to_s(colour: false)
143
276
 
144
277
  header = "<?mindwords?>\n\n"
@@ -183,12 +316,12 @@ class MindWords
183
316
 
184
317
  @lines.each do |line|
185
318
 
186
- title, rawtags = line.split(/ (?=#)/,2)
319
+ title, rawtags = line.split(/(?= #)/,2)
187
320
 
188
321
  rawtags.scan(/#(\w+)/).flatten(1).each do |rawtag|
189
322
  tag = rawtag.gsub(/ +/, '_')
190
323
  h[tag] ||= []
191
- h[tag] << title
324
+ h[tag] << title.strip
192
325
  end
193
326
 
194
327
  end
@@ -230,17 +363,35 @@ class MindWords
230
363
  e.backtrack.to_s if dups
231
364
 
232
365
  end
366
+
367
+ puts 'redundants: ' + redundants.inspect if @debug
233
368
 
234
369
  redundants.compact.each {|x| doc.element(x).delete }
235
370
 
236
-
237
371
  node = if @parent then
238
372
  found = doc.root.element('//' + @parent.name)
239
- found ? found : doc.root
373
+ found ? found.parent : doc.root
240
374
  else
241
375
  doc.root
242
376
  end
243
377
 
378
+ # the following removes any undescore prefix from words which were the
379
+ # same as the hashtag
380
+
381
+ node.root.each_recursive do |e|
382
+
383
+ next unless e
384
+ puts 'e: ' + e.inspect if @debug
385
+
386
+ e.attributes[:id] = e.attributes[:id].sub(/^_/,'') if e.attributes[:id]
387
+ e.attributes[:title] = e.attributes[:title].sub(/^_/,'') if e.attributes[:title]
388
+ e.value = e.value.sub(/^_/,'')
389
+ e.name = e.name.sub(/^_/,'')
390
+
391
+ end
392
+
393
+ # ----
394
+
244
395
  @outline = treeize node
245
396
 
246
397
  node.root.each_recursive do |e|
@@ -303,7 +454,7 @@ class MindWords
303
454
 
304
455
  duplicates.each do |path|
305
456
 
306
- puts 'path: ' + path.inspect if @debug
457
+ puts 'pathx: ' + path.inspect if @debug
307
458
  e = doc.element(path)
308
459
  e.delete if e
309
460
 
@@ -349,3 +500,25 @@ class MindWords
349
500
 
350
501
  end
351
502
 
503
+ class MindWordsWidget
504
+
505
+ def initialize()
506
+
507
+ end
508
+
509
+
510
+ # can be used for main entries or a words list
511
+ #
512
+ def input(content: '', action: 'mwupdate', target: 'icontent')
513
+
514
+ <<EOF
515
+ <form action='#{action}' method='post' target='#{target}'>
516
+ <textarea name='content' cols='30' rows='19'>
517
+ #{content}
518
+ </textarea>
519
+ <input type='submit' value='Submit'/>
520
+ </form>
521
+ EOF
522
+ end
523
+
524
+ 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.5
4
+ version: 0.6.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-31 00:00:00.000000000 Z
38
+ date: 2021-05-24 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