xml_row_finder 0.1.0 → 0.3.2
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/lib/xml_row_finder.rb +69 -42
- data.tar.gz.sig +0 -0
- metadata +13 -12
- 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: 1407d0f852c5a904600ef49f43c93b7a8e5cc4a459bb88d9d2e0bc4c26928887
|
4
|
+
data.tar.gz: 3867560288f6ed062b2c59e78bea3e30b7ddaf5217d3a181f864b4fbf28a202f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19790d1e1c125b0be88831e1a1ab870662b03ad35859fc68b2431390854c0f4e507a8629198fefb1bfd03ed460e75ceb78e278f5de4be43e9dd9a1ab4c03734
|
7
|
+
data.tar.gz: d9d5321b0f639868aeca083728f7ebaa6da2e1d101d609aa05076e9e96c0c7e33e2545db0e803e5efd53808514c028b2190a425e08267e36e42cd6b6118adb3a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/xml_row_finder.rb
CHANGED
@@ -2,19 +2,20 @@
|
|
2
2
|
|
3
3
|
# file: xml_row_finder.rb
|
4
4
|
|
5
|
-
require '
|
6
|
-
require 'rexml'
|
7
|
-
include REXML
|
5
|
+
require 'nokorexi'
|
8
6
|
|
9
7
|
|
10
8
|
class XMLRowFinder
|
11
9
|
|
12
10
|
attr_reader :to_a
|
13
11
|
|
14
|
-
def initialize(
|
12
|
+
def initialize(raws, debug: false)
|
15
13
|
|
16
14
|
@debug = debug
|
17
|
-
|
15
|
+
|
16
|
+
doc = Nokorexi.new(raws, filter: true).to_doc
|
17
|
+
|
18
|
+
@doc = Rexle.new(doc.root.xml)
|
18
19
|
|
19
20
|
a = []
|
20
21
|
|
@@ -23,51 +24,77 @@ class XMLRowFinder
|
|
23
24
|
a << e.backtrack.to_xpath
|
24
25
|
end
|
25
26
|
|
26
|
-
a2 = a.
|
27
|
+
@to_a = a2 = a.map {|e| [a.count(e), e] }.uniq
|
28
|
+
xpath = a2.max_by(&:first).last
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
next if i == a2.length-1
|
32
|
-
x == a2[i+1][0..-2]
|
33
|
-
end
|
30
|
+
a3 = xpath.split('/')
|
31
|
+
a4 = [xpath]
|
32
|
+
p1 = []
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
a3 = a2.map do |row|
|
38
|
-
row.reject do |x|
|
39
|
-
found = doc.root.xpath('//' + x)
|
40
|
-
found.length < 2
|
41
|
-
end
|
34
|
+
until (a3.length < 1) do
|
35
|
+
p1 << a3.pop; a4 << a3.join('/') + "[%s]" % p1.reverse.join('/')
|
42
36
|
end
|
43
37
|
|
44
|
-
#
|
38
|
+
# using Nokogiri since Rexle has a bug with xpath predicates
|
45
39
|
#
|
46
|
-
|
47
|
-
|
40
|
+
@doc2 = Nokogiri::XML(doc.root.xml)
|
41
|
+
|
42
|
+
a5 = a4[0..-2].map do |xpath2|
|
43
|
+
[@doc2.xpath(xpath2).length, xpath2]
|
48
44
|
end
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
puts 'a5: ' + a5.inspect if @debug
|
47
|
+
rows_xpath = a5.reverse.detect {|num, xpath2| num > 1}.last
|
48
|
+
doc3 = Document.new @doc.root.xml
|
49
|
+
@rows = XPath.match(doc3, rows_xpath)
|
50
|
+
@xpath = rows_xpath
|
51
|
+
#@xpath = BacktrackXPath.new(@rows.first).to_xpath.gsub("[@class='']",'')
|
52
|
+
|
53
|
+
last_row = XPath.match(doc3, @xpath).last
|
54
|
+
puts '@xpath: ' + @xpath.inspect
|
55
|
+
|
56
|
+
# find the container element
|
57
|
+
xpath = @xpath[/^[^\[]+/]
|
58
|
+
axpath = xpath.split('/')
|
59
|
+
|
60
|
+
e = XPath.first(doc3, xpath)
|
61
|
+
puts 'e: ' + e.to_s
|
62
|
+
|
63
|
+
until (e.nil? or e.to_s.include?(last_row.to_s)) do
|
64
|
+
axpath.pop
|
65
|
+
e = XPath.first(doc3, axpath.join('/'))
|
68
66
|
end
|
69
|
-
|
67
|
+
|
68
|
+
@cont_xpath = axpath.join('/')
|
69
|
+
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
# returns the container element for all rows
|
73
|
+
#
|
74
|
+
def body()
|
75
|
+
Rexle.new(@doc.element(@cont_xpath).xml)
|
76
|
+
end
|
77
|
+
|
78
|
+
# returns the xpath pointing to the container element for all rows
|
79
|
+
#
|
80
|
+
def body_xpath()
|
81
|
+
@cont_xpath
|
82
|
+
end
|
83
|
+
|
84
|
+
# returns rows
|
85
|
+
# object returned: An array of Nokogiri XML Element object
|
86
|
+
#
|
87
|
+
def rows()
|
88
|
+
@rows
|
89
|
+
end
|
90
|
+
|
91
|
+
# returns the xpath pointing to the rows
|
92
|
+
#
|
93
|
+
def to_xpath()
|
94
|
+
@xpath
|
95
|
+
end
|
73
96
|
|
97
|
+
alias rows_xpath to_xpath
|
98
|
+
|
99
|
+
|
100
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_row_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
a/pAsvo0jT6QTnSB7xzsx8LSFDT5tfHKR9Dcn1Y3R06fsh02JvwxaSAMgDBM2aFb
|
36
36
|
2A7/BQ1hD7SU82VTxB1gFIHl
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-01-
|
38
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: nokorexi
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '1.5'
|
47
44
|
- - ">="
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
46
|
+
version: 0.6.0
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.6'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '1.5'
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
56
|
+
version: 0.6.0
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.6'
|
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: Attempts to find repeating rows in XHTML and returns the associated xpath.
|
metadata.gz.sig
CHANGED
Binary file
|