sportdb-parser 0.5.4 → 0.5.5
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 +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +0 -1
- data/Rakefile +1 -2
- data/lib/sportdb/parser/version.rb +1 -1
- data/lib/sportdb/parser.rb +0 -9
- metadata +2 -17
- data/lib/sportdb/parser/outline_reader.rb +0 -155
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c262398deab4e59ae7f57655a5ab67b03e4ad6290c66aa1b68f082448619c9c
|
4
|
+
data.tar.gz: 4c9b0c700f3bc472b27975cd1c4e7698eabf2e3965e0c1dbbed6feb4271103d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbfeb90c1e8499e67c653bc313696cdafd18c8f56af2b752aa6466e3ea76515d45ac91433741ba106b0ced8a55178aff54b348bf37463a86ec81127b87bec58d
|
7
|
+
data.tar.gz: f98cb825168e198601b43a70e8e19173ddbec39a93f04f4d277d632dc5d8f45577190e3f780b88fe48c9d6c194e7e59c1caf67897aebcdaa8c9a6527e1bbc2c1
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/lib/sportdb/parser.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
## pulls in
|
2
2
|
require 'cocos'
|
3
|
-
require 'season/formats' # e.g. Season() support machinery
|
4
|
-
|
5
|
-
|
6
3
|
|
7
4
|
|
8
5
|
####
|
@@ -30,12 +27,6 @@ require_relative 'parser/tokenizer'
|
|
30
27
|
require_relative 'parser/parser'
|
31
28
|
|
32
29
|
|
33
|
-
####
|
34
|
-
## todo/check - move outline reader upstream to cocos - why? why not?
|
35
|
-
## use read_outline(), parse_outline() - why? why not?
|
36
|
-
require_relative 'parser/outline_reader'
|
37
|
-
|
38
|
-
|
39
30
|
|
40
31
|
###
|
41
32
|
# make parser api (easily) available - why? why not?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocos
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.4.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: season-formats
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: racc
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +97,6 @@ files:
|
|
111
97
|
- config/rounds_pt.txt
|
112
98
|
- lib/sportdb/parser.rb
|
113
99
|
- lib/sportdb/parser/lang.rb
|
114
|
-
- lib/sportdb/parser/outline_reader.rb
|
115
100
|
- lib/sportdb/parser/parser.rb
|
116
101
|
- lib/sportdb/parser/token-date.rb
|
117
102
|
- lib/sportdb/parser/token-score.rb
|
@@ -1,155 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
###
|
6
|
-
# add a simple Outline convenience class
|
7
|
-
# for processing OUtlines with OUtlineReader
|
8
|
-
|
9
|
-
class QuickMatchOutline
|
10
|
-
def self.read( path )
|
11
|
-
nodes = OutlineReader.read( path )
|
12
|
-
new( nodes )
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize( nodes )
|
16
|
-
@nodes = nodes
|
17
|
-
end
|
18
|
-
|
19
|
-
def each_para( &blk )
|
20
|
-
## note: every (new) read call - resets errors list to empty
|
21
|
-
### @errors = []
|
22
|
-
|
23
|
-
## process nodes
|
24
|
-
h1 = nil
|
25
|
-
h2 = nil
|
26
|
-
orphans = 0 ## track paragraphs's with no heading
|
27
|
-
|
28
|
-
@nodes.each do |node|
|
29
|
-
type = node[0]
|
30
|
-
|
31
|
-
if type == :h1
|
32
|
-
h1 = node[1] ## get heading text
|
33
|
-
puts " = Heading 1 >#{node[1]}<"
|
34
|
-
elsif type == :h2
|
35
|
-
if h1.nil?
|
36
|
-
puts "!! WARN - no heading for subheading; skipping processing"
|
37
|
-
next
|
38
|
-
end
|
39
|
-
h2 = node[1] ## get heading text
|
40
|
-
puts " == Heading 2 >#{node[1]}<"
|
41
|
-
elsif type == :p
|
42
|
-
if h1.nil?
|
43
|
-
orphans += 1 ## only warn once
|
44
|
-
puts "!! WARN - no heading for #{orphans} text paragraph(s); skipping parse"
|
45
|
-
next
|
46
|
-
end
|
47
|
-
|
48
|
-
lines = node[1]
|
49
|
-
blk.call( lines )
|
50
|
-
else
|
51
|
-
pp node
|
52
|
-
raise ArgumentError, "unsupported (node) type >#{type}<"
|
53
|
-
end
|
54
|
-
end # each node
|
55
|
-
end # each_para
|
56
|
-
alias_method :each_paragraph, :each_para
|
57
|
-
alias_method :each_p, :each_para
|
58
|
-
end # class QuickMatchOutline
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
class OutlineReader
|
64
|
-
|
65
|
-
def self.debug=(value) @@debug = value; end
|
66
|
-
def self.debug?() @@debug ||= false; end
|
67
|
-
def debug?() self.class.debug?; end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
|
72
|
-
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
73
|
-
parse( txt )
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.parse( txt )
|
77
|
-
new( txt ).parse
|
78
|
-
end
|
79
|
-
|
80
|
-
def initialize( txt )
|
81
|
-
@txt = txt
|
82
|
-
end
|
83
|
-
|
84
|
-
## note: skip "decorative" only heading e.g. ========
|
85
|
-
## todo/check: find a better name e.g. HEADING_EMPTY_RE or HEADING_LINE_RE or ???
|
86
|
-
HEADING_BLANK_RE = %r{\A
|
87
|
-
={1,}
|
88
|
-
\z}x
|
89
|
-
|
90
|
-
## note: like in wikimedia markup (and markdown) all optional trailing ==== too
|
91
|
-
HEADING_RE = %r{\A
|
92
|
-
(?<marker>={1,}) ## 1. leading ======
|
93
|
-
[ ]*
|
94
|
-
(?<text>[^=]+) ## 2. text (note: for now no "inline" = allowed)
|
95
|
-
[ ]*
|
96
|
-
=* ## 3. (optional) trailing ====
|
97
|
-
\z}x
|
98
|
-
|
99
|
-
def parse
|
100
|
-
outline=[] ## outline structure
|
101
|
-
start_para = true ## start new para(graph) on new text line?
|
102
|
-
|
103
|
-
@txt.each_line do |line|
|
104
|
-
line = line.strip ## todo/fix: keep leading and trailing spaces - why? why not?
|
105
|
-
|
106
|
-
if line.empty? ## todo/fix: keep blank line nodes?? and just remove comments and process headings?! - why? why not?
|
107
|
-
start_para = true
|
108
|
-
next
|
109
|
-
end
|
110
|
-
|
111
|
-
break if line == '__END__'
|
112
|
-
|
113
|
-
next if line.start_with?( '#' ) ## skip comments too
|
114
|
-
## strip inline (until end-of-line) comments too
|
115
|
-
## e.g Eupen | KAS Eupen ## [de]
|
116
|
-
## => Eupen | KAS Eupen
|
117
|
-
## e.g bq Bonaire, BOE # CONCACAF
|
118
|
-
## => bq Bonaire, BOE
|
119
|
-
line = line.sub( /#.*/, '' ).strip
|
120
|
-
pp line if debug?
|
121
|
-
|
122
|
-
## todo/check: also use heading blank as paragraph "breaker" or treat it like a comment ?? - why? why not?
|
123
|
-
next if HEADING_BLANK_RE.match( line ) # skip "decorative" only heading e.g. ========
|
124
|
-
|
125
|
-
## note: like in wikimedia markup (and markdown) all optional trailing ==== too
|
126
|
-
if m=HEADING_RE.match( line )
|
127
|
-
start_para = true
|
128
|
-
|
129
|
-
heading_marker = m[:marker]
|
130
|
-
heading_level = heading_marker.length ## count number of = for heading level
|
131
|
-
heading = m[:text].strip
|
132
|
-
|
133
|
-
puts "heading #{heading_level} >#{heading}<" if debug?
|
134
|
-
outline << [:"h#{heading_level}", heading]
|
135
|
-
else ## assume it's a (plain/regular) text line
|
136
|
-
if start_para
|
137
|
-
outline << [:p, [line]]
|
138
|
-
start_para = false
|
139
|
-
else
|
140
|
-
node = outline[-1] ## get last entry
|
141
|
-
if node[0] == :p ## assert it's a p(aragraph) node!!!
|
142
|
-
node[1] << line ## add line to p(aragraph)
|
143
|
-
else
|
144
|
-
puts "!! ERROR - invalid outline state / format - expected p(aragraph) node; got:"
|
145
|
-
pp node
|
146
|
-
exit 1
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
outline
|
152
|
-
end # method read
|
153
|
-
end # class OutlineReader
|
154
|
-
|
155
|
-
end # module SportDb
|