pxindex 0.2.0 → 0.3.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/pxindex.rb +155 -61
- data.tar.gz.sig +0 -0
- metadata +54 -30
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1668eb3de6636f0cf6ee89fd247de311c2a5564c48de17a46049663a7748e2cf
|
4
|
+
data.tar.gz: '018283918b471eb3ec25193a1fc5e07b523caedacb5dc633f34ba8974c8f3b13'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 646bed272d796dc7fbcde32f82b7326ff896bea9bbeb095befe83d71bdad634ef953534072aa26c1f30078f43dfd6fb4c025288206ed5f6d20076838626c03fa
|
7
|
+
data.tar.gz: 26666a0d64048cbbf39616581a009ade96f9101d197398bf2f5cded6c14aee8aa3f3a09860aaf81b40d98070a2d0a915feb204edefb0a88035cdf11e41d13c0d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/pxindex.rb
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
# file: pxindex.rb
|
4
4
|
|
5
|
+
require 'nokogiri'
|
5
6
|
require 'pxindex-builder'
|
6
7
|
require 'polyrex-headings'
|
7
|
-
|
8
|
+
require 'rxfreader'
|
8
9
|
|
9
10
|
|
10
11
|
class PxIndex
|
@@ -12,8 +13,8 @@ class PxIndex
|
|
12
13
|
def initialize(raw_s=nil, debug: false, allsorted: false, indexsorted: false)
|
13
14
|
|
14
15
|
@allsorted, @indexsorted = allsorted, indexsorted
|
15
|
-
@debug = debug
|
16
|
-
|
16
|
+
@debug = debug
|
17
|
+
|
17
18
|
read raw_s if raw_s
|
18
19
|
|
19
20
|
end
|
@@ -21,97 +22,140 @@ class PxIndex
|
|
21
22
|
# Returns a PxIndexBuilder object which can build from am index or phrases
|
22
23
|
#
|
23
24
|
def import(s)
|
24
|
-
|
25
|
+
|
25
26
|
read(PxIndexBuilder.new(s, debug: @debug).to_s)
|
26
|
-
|
27
|
+
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
def parent()
|
30
31
|
@rs.first
|
31
32
|
end
|
32
33
|
|
33
34
|
def q?(s)
|
34
|
-
|
35
|
+
|
35
36
|
return @a.last if s == @s
|
36
37
|
puts '@s : ' + @s.inspect if @debug
|
37
38
|
puts 's: ' + s.inspect if @debug
|
38
|
-
|
39
|
-
# @s is used to store the previous string input to compare it with
|
39
|
+
|
40
|
+
# @s is used to store the previous string input to compare it with
|
40
41
|
# the new string input
|
41
|
-
|
42
|
+
|
42
43
|
if (s.length - @s.length).abs >= 1 or s[0..-2] != @s then
|
43
|
-
|
44
|
-
@s = s
|
44
|
+
|
45
|
+
@s = s
|
45
46
|
|
46
47
|
@rs = @px.records.flat_map(&:records)
|
47
|
-
|
48
|
+
|
48
49
|
s2 = ''
|
49
|
-
|
50
|
+
|
50
51
|
@a = s.chars.map do |x|
|
51
52
|
|
52
53
|
s2 += x
|
53
54
|
found = search_records(s2, @rs)
|
54
|
-
|
55
|
+
|
55
56
|
break if not found
|
56
57
|
found
|
57
|
-
|
58
|
+
|
58
59
|
end
|
59
60
|
|
60
61
|
return @a ? @a.last : nil
|
61
|
-
|
62
|
+
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
return []
|
65
|
-
|
66
|
+
|
66
67
|
end
|
67
68
|
|
68
69
|
alias query q?
|
69
|
-
|
70
|
+
|
71
|
+
def build_html()
|
72
|
+
|
73
|
+
@px.each_recursive do |x, parent|
|
74
|
+
|
75
|
+
if x.is_a? Entry then
|
76
|
+
|
77
|
+
trail = parent.attributes[:trail]
|
78
|
+
s = x.title.gsub(/ +/,'-')
|
79
|
+
x.attributes[:trail] = trail.nil? ? s : trail + '/' + s
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
doc = Nokogiri::XML(@px.to_xml)
|
86
|
+
xsl = Nokogiri::XSLT(xslt())
|
87
|
+
|
88
|
+
html_doc = Rexle.new(xsl.transform(doc).to_s)
|
89
|
+
|
90
|
+
html_doc.root.css('.atopic').each do |e|
|
91
|
+
|
92
|
+
puts 'e: ' + e.parent.parent.xml.inspect if @debug
|
93
|
+
|
94
|
+
href = e.attributes[:href]
|
95
|
+
if href.empty? or href[0] == '!' then
|
96
|
+
|
97
|
+
if block_given? then
|
98
|
+
|
99
|
+
yield(e)
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
e.attributes[:href] = '#' + e.attributes[:trail].split('/')\
|
104
|
+
.last.downcase
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
html_doc.xml(pretty: true, declaration: false)
|
111
|
+
|
112
|
+
end
|
113
|
+
|
70
114
|
def to_px()
|
71
115
|
@px
|
72
116
|
end
|
73
|
-
|
117
|
+
|
74
118
|
def to_s()
|
75
119
|
@raw_px
|
76
120
|
end
|
77
121
|
|
78
122
|
private
|
79
|
-
|
123
|
+
|
80
124
|
def read(raw_s)
|
81
|
-
|
82
|
-
s, _ =
|
83
|
-
|
125
|
+
|
126
|
+
s, _ = RXFReader.read raw_s
|
127
|
+
|
84
128
|
lines = s.lines
|
85
129
|
|
86
130
|
header = []
|
87
131
|
header << lines.shift until lines[0].strip.empty?
|
88
|
-
|
132
|
+
|
89
133
|
a = LineTree.new(lines.join.gsub(/^# [a-z]\n/,'')).to_a
|
90
134
|
a2 = a.group_by {|x| x.first[0] }.sort.to_a
|
91
|
-
|
92
|
-
s2 = a2.map do |x|
|
135
|
+
|
136
|
+
s2 = a2.map do |x|
|
93
137
|
'# ' + x[0] + "\n\n" + \
|
94
138
|
treeize(@allsorted || @indexsorted ? sort(x[-1]) : x[-1])
|
95
139
|
end.join("\n\n")
|
96
|
-
|
140
|
+
|
97
141
|
puts 's2: ' + s2.inspect if @debug
|
98
142
|
@raw_px = header.join + "\n" + s2
|
99
143
|
|
100
|
-
@px = PolyrexHeadings.new(@raw_px).to_polyrex
|
144
|
+
@px = PolyrexHeadings.new(@raw_px).to_polyrex
|
101
145
|
@rs = @px.records.flat_map()
|
102
146
|
|
103
147
|
@s = ''
|
104
|
-
@a = []
|
148
|
+
@a = []
|
105
149
|
end
|
106
150
|
|
107
151
|
def search_records(raw_s, rs=@rs)
|
108
|
-
|
152
|
+
|
109
153
|
puts 'raw_s : ' + raw_s.inspect if @debug
|
110
|
-
|
154
|
+
|
111
155
|
if raw_s[-1] == ' ' then
|
112
156
|
|
113
157
|
child_records = rs.flat_map(&:records)
|
114
|
-
|
158
|
+
|
115
159
|
if child_records.length > 0 then
|
116
160
|
@rs = child_records
|
117
161
|
return child_records
|
@@ -121,67 +165,67 @@ class PxIndex
|
|
121
165
|
end
|
122
166
|
|
123
167
|
keywords = raw_s.split(/ /)
|
124
|
-
|
168
|
+
|
125
169
|
s = keywords.length > 1 ? keywords.last : raw_s
|
126
|
-
|
127
|
-
a = rs.select {|x| x.title[0..s.length-1] == s}
|
128
|
-
|
170
|
+
|
171
|
+
a = rs.select {|x| x.title[0..s.length-1] == s}
|
172
|
+
|
129
173
|
if @debug then
|
130
|
-
puts 'a: ' + a.inspect
|
174
|
+
puts 'a: ' + a.inspect
|
131
175
|
if a.any? then
|
132
176
|
puts 'a.map ' + a.map(&:title).inspect
|
133
177
|
end
|
134
178
|
end
|
135
|
-
|
136
|
-
if s.length == 1 and a.any? and keywords.length < 2 then
|
137
|
-
#a = a.first.records
|
138
|
-
end
|
139
|
-
|
179
|
+
|
140
180
|
if a.any? then
|
141
|
-
|
181
|
+
|
142
182
|
@rs = a
|
143
|
-
|
183
|
+
|
144
184
|
else
|
145
185
|
|
146
186
|
return nil unless keywords.length > 1
|
147
|
-
|
148
|
-
r = rs
|
187
|
+
|
188
|
+
r = rs
|
149
189
|
|
150
190
|
if r.any? then
|
151
|
-
|
152
|
-
@rs = r
|
191
|
+
|
192
|
+
@rs = r
|
153
193
|
search_records(s, rs)
|
154
|
-
|
194
|
+
|
155
195
|
else
|
156
|
-
|
196
|
+
|
157
197
|
return nil
|
158
|
-
|
198
|
+
|
159
199
|
end
|
160
|
-
|
200
|
+
|
161
201
|
end
|
162
202
|
|
163
203
|
end
|
164
|
-
|
204
|
+
|
165
205
|
def sort(a)
|
206
|
+
|
166
207
|
puts 'sorting ... a: ' + a.inspect if @debug
|
167
208
|
return sort_children(a) if a.first.is_a? String
|
168
|
-
|
169
|
-
r = a.sort_by do |x|
|
209
|
+
|
210
|
+
r = a.sort_by do |x|
|
170
211
|
next unless x[0].is_a? String
|
171
212
|
x[0]
|
172
213
|
end
|
214
|
+
|
173
215
|
puts 'after sort: ' + r.inspect if @debug
|
216
|
+
|
174
217
|
r
|
218
|
+
|
175
219
|
end
|
176
|
-
|
220
|
+
|
177
221
|
def sort_children(a)
|
178
222
|
[a[0]] + a[1..-1].sort_by {|x| x[0]}
|
179
223
|
end
|
180
|
-
|
224
|
+
|
181
225
|
def treeize(obj, indent=-2)
|
182
226
|
|
183
227
|
if obj.is_a? Array then
|
184
|
-
|
228
|
+
|
185
229
|
r = (@allsorted ? sort(obj) : obj).map {|x| treeize(x, indent+1)}.join("\n")
|
186
230
|
puts 'r: ' + r.inspect if @debug
|
187
231
|
r
|
@@ -191,6 +235,56 @@ class PxIndex
|
|
191
235
|
' ' * indent + obj
|
192
236
|
|
193
237
|
end
|
194
|
-
end
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
def xslt()
|
242
|
+
<<EOF
|
243
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
244
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
245
|
+
<xsl:output method="xml" indent="yes" />
|
246
|
+
|
247
|
+
<xsl:template match='entries'>
|
248
|
+
<ul>
|
249
|
+
<xsl:apply-templates select='summary'/>
|
250
|
+
<xsl:apply-templates select='records'/>
|
251
|
+
</ul>
|
252
|
+
</xsl:template>
|
253
|
+
|
254
|
+
<xsl:template match='entries/summary'>
|
255
|
+
</xsl:template>
|
256
|
+
|
257
|
+
<xsl:template match='records/section'>
|
258
|
+
<li><h1><xsl:value-of select="summary/heading"/></h1><xsl:text>
|
259
|
+
</xsl:text>
|
260
|
+
|
261
|
+
<xsl:apply-templates select='records'/>
|
262
|
+
|
263
|
+
<xsl:text>
|
264
|
+
</xsl:text>
|
265
|
+
</li>
|
266
|
+
</xsl:template>
|
267
|
+
|
268
|
+
|
269
|
+
<xsl:template match='records/entry'>
|
270
|
+
<ul id="{summary/title}">
|
271
|
+
<li><xsl:text>
|
272
|
+
</xsl:text>
|
273
|
+
<a href="{summary/url}" class='atopic' id='{@id}' trail='{@trail}'>
|
274
|
+
<xsl:value-of select="summary/title"/></a><xsl:text>
|
275
|
+
</xsl:text>
|
276
|
+
|
277
|
+
<xsl:apply-templates select='records'/>
|
278
|
+
|
279
|
+
<xsl:text>
|
280
|
+
</xsl:text>
|
281
|
+
</li>
|
282
|
+
</ul>
|
283
|
+
</xsl:template>
|
284
|
+
|
285
|
+
|
286
|
+
</xsl:stylesheet>
|
287
|
+
EOF
|
288
|
+
end
|
195
289
|
|
196
290
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pxindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,53 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-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HQ4EFgQUZ3pWGV05
|
26
|
+
7oGraWfSUYyZHLGZH1swJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEABVd3ECVIm82hELIIyaVOsQ8ZdxVmCI5isFhjalJo
|
29
|
+
upTEFiZsS/KOTaycNi5U0K72E540R/MB6opipy58heaVh/ie+aPhrI5ct5aOu/RG
|
30
|
+
fIh2wiyDTshvCcGWjwWevePD/VaeFEBoSaim8ockSx5TISpIFrodxErcqvKySntb
|
31
|
+
4mOS6YHEQsAC0/C7Ub9s7HY6ArJtuOqL4gmX4OrxwbSZATqz2LVtckKWweCnyo7m
|
32
|
+
4sVS12iJ0rgRvnnhyehZu6ByXw8MVb3kWWG6jknwaWRj5B2fZffle9kZwIuZMd/R
|
33
|
+
cReZ9fcYojHfZw/h5kYBkCLA0pHhob+WtF1zY2TUfi6g6NTVRPaCyMZcxY+EAiGY
|
34
|
+
2zF4H0zwaFRpQPz7UD7JUDgbXZaVGEMWULk6GFFC+sQ3k7OwsnaBUiFc0YI/i6eI
|
35
|
+
tOVtEJTcR/mCCj9KJXJqr+WfYnPrHMAUTU1yY/yIYUC3PRK4iCVNABYrrx1/knM5
|
36
|
+
P80D+02gWIUT41dw6mBHO32N
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
34
39
|
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: nokogiri
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.13'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.13.3
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.13'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.13.3
|
35
60
|
- !ruby/object:Gem::Dependency
|
36
61
|
name: pxindex-builder
|
37
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +66,7 @@ dependencies:
|
|
41
66
|
version: '0.2'
|
42
67
|
- - ">="
|
43
68
|
- !ruby/object:Gem::Version
|
44
|
-
version: 0.2.
|
69
|
+
version: 0.2.1
|
45
70
|
type: :runtime
|
46
71
|
prerelease: false
|
47
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,29 +76,29 @@ dependencies:
|
|
51
76
|
version: '0.2'
|
52
77
|
- - ">="
|
53
78
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.
|
79
|
+
version: 0.2.1
|
55
80
|
- !ruby/object:Gem::Dependency
|
56
81
|
name: polyrex-headings
|
57
82
|
requirement: !ruby/object:Gem::Requirement
|
58
83
|
requirements:
|
59
84
|
- - "~>"
|
60
85
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
86
|
+
version: '0.3'
|
62
87
|
- - ">="
|
63
88
|
- !ruby/object:Gem::Version
|
64
|
-
version: 0.
|
89
|
+
version: 0.3.0
|
65
90
|
type: :runtime
|
66
91
|
prerelease: false
|
67
92
|
version_requirements: !ruby/object:Gem::Requirement
|
68
93
|
requirements:
|
69
94
|
- - "~>"
|
70
95
|
- !ruby/object:Gem::Version
|
71
|
-
version: '0.
|
96
|
+
version: '0.3'
|
72
97
|
- - ">="
|
73
98
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
99
|
+
version: 0.3.0
|
75
100
|
description:
|
76
|
-
email:
|
101
|
+
email: digital.robertson@gmail.com
|
77
102
|
executables: []
|
78
103
|
extensions: []
|
79
104
|
extra_rdoc_files: []
|
@@ -98,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
123
|
- !ruby/object:Gem::Version
|
99
124
|
version: '0'
|
100
125
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.6.13
|
126
|
+
rubygems_version: 3.2.22
|
103
127
|
signing_key:
|
104
128
|
specification_version: 4
|
105
129
|
summary: Experimental gem to facilitate a keyword search, by querying a Polyrex document
|
metadata.gz.sig
CHANGED
Binary file
|