mindwords 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4d617b7606074c5392810716b83f5ea18a45bd2f9bcbc3cbd3c8264c4efda15
4
- data.tar.gz: 77459002b1868120333d8d173ef7012db25e29b977a265dd60f85405825a377b
3
+ metadata.gz: 7e0812d6fb0ec5d2b09105de96160ed832007144ac15f036418e1e9207234b60
4
+ data.tar.gz: 1c121aae9d22bc87535fb0c8df0c41333530dfa180970bd9685488b49b209f9e
5
5
  SHA512:
6
- metadata.gz: f9bafe174e81786a07e60e1665116f5c9fd0c966642322bddf5f9898f95ce5474d1a3ec80573ed6a0056751e63cbf1e13210610459db5d8b85d77865db0daa39
7
- data.tar.gz: 6aedd18fb09a55aa78b3cc2c7c59db08edca77a2ed5e47c1049bb5bd069d34f1d4b5438fb36367d35a4ae9c91c5ec4970eb975eebfe3b0c286982f322b2b16b9
6
+ metadata.gz: 706128a061c541504d6214d0a0cd1bdf23aecb3794761c43d842c9cd24b34d704ae7c1fa70b9ddba67cb8a785b88a72e37f462fe4f6eb5f5c9bfb38c81471f57
7
+ data.tar.gz: ad5dce9ac225ba26711d6ab92c16d7fe7a2dcf906173ea52318fe7452437da685227340d3cdaf8061842f3ab5704cf7494a47f5fea9ec122f09cac930b3cd0a7
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -44,27 +44,11 @@ class MindWords
44
44
  a = rexlize(h)
45
45
  doc = Rexle.new(['root', {}, '', *a])
46
46
 
47
- duplicates = []
48
- doc.root.each_recursive do |e|
49
-
50
- puts 'e: ' + e.name.inspect if @debug
51
- rows = e.parent.xpath('//' + e.name)
52
- next if rows.length < 2
53
-
54
- rows[1..-1].each do |e2|
55
- puts 'e2: ' + e2.name.inspect if @debug
56
- duplicates << [e.backtrack.to_s, e2.backtrack.to_s] #unless e2.has_elements?
57
- end
58
- end
59
-
60
- duplicates.each do |path, oldpath|
61
- e = doc.element(path);
62
- e2 = doc.element(oldpath);
63
- e2.parent.add e
64
- e2.delete
65
- end
66
-
67
- # remove redundant nodes
47
+
48
+ # remove duplicates which appear in the same branch above the nested node
49
+ rm_duplicates(doc)
50
+
51
+ # remove redundant nodes (outsiders)
68
52
  # a redundant node is where all children exist in existing nested nodes
69
53
 
70
54
  redundants = doc.root.elements.map do |e|
@@ -78,7 +62,8 @@ class MindWords
78
62
  end
79
63
 
80
64
  redundants.compact.each {|x| doc.element(x).delete }
81
-
65
+ rm_duplicates(doc)
66
+
82
67
  @outline = treeize doc.root
83
68
 
84
69
  end
@@ -106,6 +91,30 @@ class MindWords
106
91
  end
107
92
 
108
93
  end
94
+
95
+ def rm_duplicates(doc)
96
+
97
+ duplicates = []
98
+ doc.root.each_recursive do |e|
99
+
100
+ puts 'e: ' + e.name.inspect if @debug
101
+ rows = e.parent.xpath('//' + e.name)
102
+ next if rows.length < 2
103
+
104
+ rows[1..-1].each do |e2|
105
+ puts 'e2: ' + e2.name.inspect if @debug
106
+ duplicates << [e.backtrack.to_s, e2.backtrack.to_s]
107
+ end
108
+ end
109
+
110
+ duplicates.each do |path, oldpath|
111
+ e = doc.element(path);
112
+ e2 = doc.element(oldpath);
113
+ e2.parent.add e
114
+ e2.delete
115
+ end
116
+
117
+ end
109
118
 
110
119
  def treeize(node, indent=0)
111
120
 
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file