sportdb-parser 0.7.1 → 0.7.2
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 +17 -4
- data/lib/sportdb/parser/lexer-on_goal.rb +172 -0
- data/lib/sportdb/parser/lexer-on_group_def.rb +31 -0
- data/lib/sportdb/parser/lexer-on_prop_lineup.rb +79 -0
- data/lib/sportdb/parser/lexer-on_prop_misc.rb +110 -0
- data/lib/sportdb/parser/lexer-on_prop_penalties.rb +40 -0
- data/lib/sportdb/parser/lexer-on_round_def.rb +37 -0
- data/lib/sportdb/parser/lexer-on_top.rb +125 -0
- data/lib/sportdb/parser/lexer-prep_doc.rb +131 -0
- data/lib/sportdb/parser/lexer-prep_line.rb +63 -0
- data/lib/sportdb/parser/lexer-tokenize.rb +449 -0
- data/lib/sportdb/parser/lexer.rb +133 -1363
- data/lib/sportdb/parser/lexer_buffer.rb +8 -37
- data/lib/sportdb/parser/lexer_token.rb +126 -0
- data/lib/sportdb/parser/parser.rb +1104 -1403
- data/lib/sportdb/parser/racc_parser.rb +36 -32
- data/lib/sportdb/parser/racc_tree.rb +65 -98
- data/lib/sportdb/parser/token-date--helpers.rb +130 -0
- data/lib/sportdb/parser/token-date--names.rb +108 -0
- data/lib/sportdb/parser/token-date.rb +20 -192
- data/lib/sportdb/parser/token-date_duration.rb +8 -27
- data/lib/sportdb/parser/token-geo.rb +16 -16
- data/lib/sportdb/parser/token-goals--helpers.rb +114 -0
- data/lib/sportdb/parser/token-goals.rb +103 -249
- data/lib/sportdb/parser/token-group.rb +8 -22
- data/lib/sportdb/parser/token-prop.rb +138 -124
- data/lib/sportdb/parser/token-prop_name.rb +48 -39
- data/lib/sportdb/parser/token-round.rb +21 -35
- data/lib/sportdb/parser/token-score--helpers.rb +189 -0
- data/lib/sportdb/parser/token-score.rb +9 -393
- data/lib/sportdb/parser/token-score_full.rb +331 -0
- data/lib/sportdb/parser/token-status.rb +44 -46
- data/lib/sportdb/parser/token-status_inline.rb +112 -0
- data/lib/sportdb/parser/token-text.rb +41 -31
- data/lib/sportdb/parser/token-time.rb +29 -26
- data/lib/sportdb/parser/token.rb +58 -159
- data/lib/sportdb/parser/version.rb +1 -1
- data/lib/sportdb/parser.rb +45 -17
- metadata +19 -6
- data/lib/sportdb/parser/blocktxt.rb +0 -99
- data/lib/sportdb/parser/lexer_tty.rb +0 -111
- data/lib/sportdb/parser/token-table.rb +0 -149
- data/lib/sportdb/parser/token_helpers.rb +0 -92
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
module SportDb
|
|
2
|
+
class Lexer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def self._build_score( m )
|
|
6
|
+
## note - score is "generic"
|
|
7
|
+
## might be full-time (ft) or
|
|
8
|
+
## after extra-time (aet) or such
|
|
9
|
+
## or even undecided/unknown
|
|
10
|
+
## thus, use score1/score2 and NOT ft1/ft2
|
|
11
|
+
## thus, use (simply an) array e.g. [1,2]
|
|
12
|
+
## and NOT hash (table) e.g. { ft: [1,2] } !!!
|
|
13
|
+
|
|
14
|
+
score = [m[:score1].to_i(10),
|
|
15
|
+
m[:score2].to_i(10)]
|
|
16
|
+
|
|
17
|
+
score
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self._build_score_awd( m ) # score awarded (awd/awd.)
|
|
21
|
+
### note - use "generic" score for now
|
|
22
|
+
## to match A 3-0 B [awarded] etc.
|
|
23
|
+
score = [m[:score1].to_i(10),
|
|
24
|
+
m[:score2].to_i(10)]
|
|
25
|
+
## add score[:awarded] = true ???
|
|
26
|
+
## note - for now uses its own token e.g SCORE_AWD
|
|
27
|
+
score
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self._build_score_abd( m ) # score abandonded (abd/abd.)
|
|
31
|
+
### note - use "generic" score for now
|
|
32
|
+
score = [m[:score1].to_i(10),
|
|
33
|
+
m[:score2].to_i(10)]
|
|
34
|
+
## add score[:abd] = true ???
|
|
35
|
+
## note - for now uses its own token e.g SCORE_ABD
|
|
36
|
+
score
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def self._build_score_full( m )
|
|
41
|
+
score = {}
|
|
42
|
+
score[:p] = [m[:p1].to_i(10),
|
|
43
|
+
m[:p2].to_i(10)] if m[:p1] && m[:p2]
|
|
44
|
+
score[:et] = [m[:et1].to_i(10),
|
|
45
|
+
m[:et2].to_i(10)] if m[:et1] && m[:et2]
|
|
46
|
+
score[:ft] = [m[:ft1].to_i(10),
|
|
47
|
+
m[:ft2].to_i(10)] if m[:ft1] && m[:ft2]
|
|
48
|
+
score[:ht] = [m[:ht1].to_i(10),
|
|
49
|
+
m[:ht2].to_i(10)] if m[:ht1] && m[:ht2]
|
|
50
|
+
|
|
51
|
+
## add golden/silver flags
|
|
52
|
+
score[:golden] = true if m[:aetgg] ## golden goal (gg)/sudden death (sd)
|
|
53
|
+
score[:silver] = true if m[:aetsg] ## silver goal (sg)
|
|
54
|
+
|
|
55
|
+
score
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self._build_score_fuller( m )
|
|
59
|
+
score = {}
|
|
60
|
+
score[:p] = [m[:p1].to_i(10),
|
|
61
|
+
m[:p2].to_i(10)] if m[:p1] && m[:p2]
|
|
62
|
+
score[:et] = [m[:et1].to_i(10),
|
|
63
|
+
m[:et2].to_i(10)] if m[:et1] && m[:et2]
|
|
64
|
+
score[:ft] = [m[:ft1].to_i(10),
|
|
65
|
+
m[:ft2].to_i(10)] if m[:ft1] && m[:ft2]
|
|
66
|
+
score[:ht] = [m[:ht1].to_i(10),
|
|
67
|
+
m[:ht2].to_i(10)] if m[:ht1] && m[:ht2]
|
|
68
|
+
score[:agg] = [m[:agg1].to_i(10),
|
|
69
|
+
m[:agg2].to_i(10)] if m[:agg1] && m[:agg2]
|
|
70
|
+
|
|
71
|
+
if m[:away1] && m[:away2]
|
|
72
|
+
score[:away] = [m[:away1].to_i(10),
|
|
73
|
+
m[:away2].to_i(10)]
|
|
74
|
+
elsif m[:away] ## fallback if no away score; check away flag
|
|
75
|
+
score[:away] = true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
## add golden/silver flags
|
|
79
|
+
score[:golden] = true if m[:aetgg] ## golden goal (gg)/sudden death (sd)
|
|
80
|
+
score[:silver] = true if m[:aetsg] ## silver goal (sg)
|
|
81
|
+
|
|
82
|
+
score
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def self._build_score_fuller_more( m )
|
|
87
|
+
## SCORE + SCORE_FULLER_MORE
|
|
88
|
+
## note - after extra-time (aet) or full-time (ft)
|
|
89
|
+
## score may be present in SCORE!!!
|
|
90
|
+
score = {}
|
|
91
|
+
score[:p] = [m[:p1].to_i(10),
|
|
92
|
+
m[:p2].to_i(10)] if m[:p1] && m[:p2]
|
|
93
|
+
score[:et] = [m[:et1].to_i(10),
|
|
94
|
+
m[:et2].to_i(10)] if m[:et1] && m[:et2]
|
|
95
|
+
score[:ft] = [m[:ft1].to_i(10),
|
|
96
|
+
m[:ft2].to_i(10)] if m[:ft1] && m[:ft2]
|
|
97
|
+
score[:ht] = [m[:ht1].to_i(10),
|
|
98
|
+
m[:ht2].to_i(10)] if m[:ht1] && m[:ht2]
|
|
99
|
+
score[:agg] = [m[:agg1].to_i(10),
|
|
100
|
+
m[:agg2].to_i(10)] if m[:agg1] && m[:agg2]
|
|
101
|
+
|
|
102
|
+
if m[:away1] && m[:away2]
|
|
103
|
+
score[:away] = [m[:away1].to_i(10),
|
|
104
|
+
m[:away2].to_i(10)]
|
|
105
|
+
elsif m[:away] ## fallback if no away score; check away flag
|
|
106
|
+
score[:away] = true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
## add golden/silver flags
|
|
110
|
+
score[:golden] = true if m[:aetgg] ## golden goal (gg)/sudden death (sd)
|
|
111
|
+
score[:silver] = true if m[:aetsg] ## silver goal (sg)
|
|
112
|
+
|
|
113
|
+
## add flag in score for et/ft/ht
|
|
114
|
+
## used for "dangling" (generic) score
|
|
115
|
+
score[:score] = 'et' if m[:aet] || m[:aetgg] || m[:aetsg]
|
|
116
|
+
score[:score] = 'ft' if m[:ft]
|
|
117
|
+
score[:score] = 'ht' if m[:ht]
|
|
118
|
+
|
|
119
|
+
score
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def self._build_score_legs( m )
|
|
124
|
+
legs = {}
|
|
125
|
+
|
|
126
|
+
############
|
|
127
|
+
### build leg1 (score)
|
|
128
|
+
score = {}
|
|
129
|
+
score[:ft] = [m[:leg1_ft1].to_i(10),
|
|
130
|
+
m[:leg1_ft2].to_i(10)]
|
|
131
|
+
legs['leg1'] = score
|
|
132
|
+
|
|
133
|
+
##################
|
|
134
|
+
### build leg2 (score)
|
|
135
|
+
score = {}
|
|
136
|
+
score[:ft] = [m[:leg2_ft1].to_i(10),
|
|
137
|
+
m[:leg2_ft2].to_i(10)] if m[:leg2_ft1] && m[:leg2_ft2]
|
|
138
|
+
score[:et] = [m[:leg2_et1].to_i(10),
|
|
139
|
+
m[:leg2_et2].to_i(10)] if m[:leg2_et1] && m[:leg2_et2]
|
|
140
|
+
score[:p] = [m[:leg2_p1].to_i(10),
|
|
141
|
+
m[:leg2_p2].to_i(10)] if m[:leg2_p1] && m[:leg2_p2]
|
|
142
|
+
legs['leg2'] = score
|
|
143
|
+
|
|
144
|
+
## check for (opt) aggregate - keep on "top-level"
|
|
145
|
+
legs[:agg] = [m[:agg1].to_i(10),
|
|
146
|
+
m[:agg2].to_i(10)] if m[:agg1] && m[:agg2]
|
|
147
|
+
legs[:away] = true if m[:away]
|
|
148
|
+
|
|
149
|
+
legs
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _build_score( m ) self.class._build_score( m ); end
|
|
154
|
+
def _build_score_awd( m ) self.class._build_score_awd( m ); end
|
|
155
|
+
def _build_score_abd( m ) self.class._build_score_abd( m ); end
|
|
156
|
+
def _build_score_full( m ) self.class._build_score_full( m ); end
|
|
157
|
+
def _build_score_fuller( m ) self.class._build_score_fuller( m ); end
|
|
158
|
+
def _build_score_fuller_more( m ) self.class._build_score_fuller_more( m ); end
|
|
159
|
+
def _build_score_legs( m ) self.class._build_score_legs( m ); end
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
###
|
|
165
|
+
## add parser helpers
|
|
166
|
+
|
|
167
|
+
def self._parse_score_full( str )
|
|
168
|
+
## note - strip - leading/trailing spaces automatic - why? why not?
|
|
169
|
+
|
|
170
|
+
m = Regexp.union(
|
|
171
|
+
SCORE_FULL_1ST_RE,
|
|
172
|
+
SCORE_FULL_RE ).match( str.strip )
|
|
173
|
+
|
|
174
|
+
if m && m.pre_match == '' && m.post_match == ''
|
|
175
|
+
pp m
|
|
176
|
+
_build_score_full( m )
|
|
177
|
+
elsif m
|
|
178
|
+
## note - match BUT not anchored to start and end-of-string!!!
|
|
179
|
+
## report, error somehow??
|
|
180
|
+
nil
|
|
181
|
+
else
|
|
182
|
+
nil ## no match - return nil
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
end # class Lexer
|
|
189
|
+
end # module SportDb
|
|
@@ -2,318 +2,10 @@ module SportDb
|
|
|
2
2
|
class Lexer
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## todo/check: use ‹› (unicode chars) to mark optional parts in regex constant name - why? why not?
|
|
8
|
-
|
|
9
|
-
#####
|
|
10
|
-
# english helpers (penalty, extra time, ...)
|
|
11
|
-
## note - p must go last (shortest match)
|
|
12
|
-
# pso = penalty shootout
|
|
13
|
-
### - note - remove PSO for now (may add later back) - why? why not?
|
|
14
|
-
#
|
|
15
|
-
# todo/fix/clean-up - keep it simple - remove optional trailing dot (.)
|
|
16
|
-
# from pen., p., agg. etc. - why? why not?
|
|
17
|
-
# always use (simply) pen, p, agg
|
|
18
|
-
# (also) remove a.e.t. / a.e.t option - why? why not?
|
|
19
|
-
#
|
|
20
|
-
## UPDATE mar/2026: addd pens too - keep - why? why not?
|
|
21
|
-
## (4-3 pens)
|
|
22
|
-
## (4-3 Pens) -- keep mixed Pens/Pen. too - why? why not?
|
|
23
|
-
## (4-3 Pen.)
|
|
24
|
-
P_EN = '(?-i: PEN | P |' +
|
|
25
|
-
'[Pp]ens | [Pp]en\.? | p\.? )' # e.g. p., p, pen, pen., etc.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## fix - change ET_EN to AET_EN!!! - why? why not?
|
|
29
|
-
## check - allow Aet too - why? why not?
|
|
30
|
-
## or A.e.t ??
|
|
31
|
-
ET_EN = '(?-i: AET | ' +
|
|
32
|
-
'aet | a\.e\.t\.? )' # note: make last . optional (e.g a.e.t) allowed too
|
|
33
|
-
# AET_EN = ET_EN
|
|
34
|
-
|
|
35
|
-
####
|
|
36
|
-
## after (golden goal/sudden death) extra time - add more options/styles - why? why not?
|
|
37
|
-
AETGG_EN = '(?-i: AET/GG | AGGET | ASDET | ' +
|
|
38
|
-
'aet/gg | a\.e\.t\.?/g\.g\.? | agget | asdet )'
|
|
39
|
-
## after (silver goal) extra time
|
|
40
|
-
AETSG_EN = '(?-i: AET/SG | ASGET | ' +
|
|
41
|
-
'aet/sg | a\.e\.t\.?/s\.g\.? | asget )'
|
|
42
|
-
|
|
43
|
-
## agg/agg. or AGG
|
|
44
|
-
AGG_EN = '(?-i: AGG | agg\.? )' ## aggregate e..g 4-4 agg etc.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## regex score helpers
|
|
49
|
-
## note - MUST double escape \d e.g. \\d!!! if not "simple" string (e.g. '' but %Q<>)
|
|
50
|
-
|
|
51
|
-
##
|
|
52
|
-
## fix - change SCORE_P to SCORE_FULL_P
|
|
53
|
-
## SCORE_ET to SCORE_FULL_ET
|
|
54
|
-
##
|
|
55
|
-
## (re)use SCORE_P, SCORE_ET for score only part!!!
|
|
56
|
-
|
|
57
|
-
SCORE_P = %Q< (?<p1>\\d{1,2}) - (?<p2>\\d{1,2})
|
|
58
|
-
[ ]? #{P_EN}
|
|
59
|
-
>
|
|
60
|
-
SCORE_ET = %Q< (?<et1>\\d{1,2}) - (?<et2>\\d{1,2})
|
|
61
|
-
[ ]? #{ET_EN}
|
|
62
|
-
>
|
|
63
|
-
SCORE_LOOKAHEAD = '(?= [ ,\]] | $)'
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
####
|
|
67
|
-
## after extra-time with golden goal/sudden death & silver goal rule
|
|
68
|
-
## note - golden goal & silver goal EXCLUDE penalties!!!
|
|
69
|
-
##
|
|
70
|
-
## 4-3 a.e.t/g.g.
|
|
71
|
-
## 4-3 aet/gg
|
|
72
|
-
## 4-3agget -or- 4-3 asdet
|
|
73
|
-
## 2-1 aet/sg
|
|
74
|
-
## -or-
|
|
75
|
-
## 4-3 aet/gg (3-3, 2-1)
|
|
76
|
-
SCORE__ET_GG_SG__RE = %r{
|
|
77
|
-
(?<score_full>
|
|
78
|
-
\b
|
|
79
|
-
(?<et1>\d{1,2}) - (?<et2>\d{1,2})
|
|
80
|
-
[ ]? (?:
|
|
81
|
-
(?<aetgg> #{AETGG_EN})
|
|
82
|
-
|
|
|
83
|
-
(?<aetsg> #{AETSG_EN})
|
|
84
|
-
)
|
|
85
|
-
### note:
|
|
86
|
-
## add optional full-time, half-time score
|
|
87
|
-
(?:
|
|
88
|
-
[ ]+
|
|
89
|
-
\(
|
|
90
|
-
[ ]*
|
|
91
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
92
|
-
[ ]*
|
|
93
|
-
(?:
|
|
94
|
-
, [ ]*
|
|
95
|
-
(?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
96
|
-
[ ]*
|
|
97
|
-
)?
|
|
98
|
-
)? # note: make half time (HT) score optional for now
|
|
99
|
-
\)
|
|
100
|
-
)?
|
|
101
|
-
#{SCORE_LOOKAHEAD}
|
|
102
|
-
)}ix
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## note: allow SPECIAL cases WITHOUT full time scores (just a.e.t or pen. + a.e.t.)
|
|
106
|
-
## 3-4 pen. 2-2 a.e.t.
|
|
107
|
-
## 3-4 pen. 2-2 a.e.t.
|
|
108
|
-
## 2-2 a.e.t.
|
|
109
|
-
SCORE__P_ET__RE = %r{
|
|
110
|
-
(?<score_full>
|
|
111
|
-
\b
|
|
112
|
-
(?: #{SCORE_P} [ ]+
|
|
113
|
-
)? ## note: make penalty (P) score optional for now
|
|
114
|
-
#{SCORE_ET}
|
|
115
|
-
#{SCORE_LOOKAHEAD}
|
|
116
|
-
)}ix
|
|
117
|
-
## todo/check: remove loakahead assertion here - why require space?
|
|
118
|
-
## note: \b works only after non-alphanum e.g. )
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## note: allow SPECIAL cases WITHOUT full time scores
|
|
122
|
-
## AND with pen in last position!
|
|
123
|
-
## 2-2 a.e.t., 3-4 pen.
|
|
124
|
-
## 2-2 a.e.t. 3-4 pen. ## or without comma separator - why? why not?
|
|
125
|
-
SCORE__ET_P__RE = %r{
|
|
126
|
-
(?<score_full>
|
|
127
|
-
\b
|
|
128
|
-
#{SCORE_ET}
|
|
129
|
-
(?: [ ]*,[ ]* | [ ]+ )
|
|
130
|
-
#{SCORE_P}
|
|
131
|
-
#{SCORE_LOOKAHEAD}
|
|
132
|
-
)}ix
|
|
133
|
-
## todo/check: remove loakahead assertion here - why require space?
|
|
134
|
-
## note: \b works only after non-alphanum e.g. )
|
|
135
|
-
|
|
136
|
-
### special case (i) - full time with penalties
|
|
137
|
-
## 2-2, 3-4 pen.
|
|
138
|
-
SCORE__FT_P__RE = %r{
|
|
139
|
-
(?<score_full>
|
|
140
|
-
\b
|
|
141
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
142
|
-
[ ]*,[ ]* ## note - comma required!!!
|
|
143
|
-
#{SCORE_P}
|
|
144
|
-
#{SCORE_LOOKAHEAD}
|
|
145
|
-
)}ix
|
|
146
|
-
|
|
147
|
-
### special case (ii) - full time & half-time with penalties
|
|
148
|
-
## 2-2 (1-1), 3-4 pen.
|
|
149
|
-
SCORE__FT_HT_P__RE = %r{
|
|
150
|
-
(?<score_full>
|
|
151
|
-
\b
|
|
152
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
153
|
-
[ ]*
|
|
154
|
-
\(
|
|
155
|
-
(?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
156
|
-
\)
|
|
157
|
-
[ ]*,[ ]* ## note - comma required!!!
|
|
158
|
-
#{SCORE_P}
|
|
159
|
-
#{SCORE_LOOKAHEAD}
|
|
160
|
-
)}ix
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
## note: allow SPECIAL with penalty only
|
|
166
|
-
## 3-4 pen. or 3-4p etc.
|
|
167
|
-
SCORE__P__RE = %r{
|
|
168
|
-
(?<score_full>
|
|
169
|
-
\b
|
|
170
|
-
#{SCORE_P}
|
|
171
|
-
#{SCORE_LOOKAHEAD}
|
|
172
|
-
)}ix
|
|
173
|
-
## todo/check: remove loakahead assertion here - why require space?
|
|
174
|
-
## note: \b works only after non-alphanum e.g. )
|
|
175
|
-
|
|
176
|
-
####
|
|
177
|
-
## support short all-in-one e.g.
|
|
178
|
-
## e.g. 3-4 pen. 2-2 a.e.t. ( 1-1, 1-1 ) becomes
|
|
179
|
-
## 3-4 pen. (2-2, 1-1, 1-1)
|
|
180
|
-
|
|
181
|
-
SCORE__P_ET_FT_HT_V2__RE = %r{
|
|
182
|
-
(?<score_full>
|
|
183
|
-
\b
|
|
184
|
-
#{SCORE_P} [ ]+
|
|
185
|
-
\(
|
|
186
|
-
[ ]*
|
|
187
|
-
(?<et1>\d{1,2}) - (?<et2>\d{1,2})
|
|
188
|
-
[ ]*, [ ]*
|
|
189
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
190
|
-
[ ]*, [ ]*
|
|
191
|
-
(?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
192
|
-
[ ]*
|
|
193
|
-
\)
|
|
194
|
-
#{SCORE_LOOKAHEAD}
|
|
195
|
-
)}ix ## todo/check: remove loakahead assertion here - why require space?
|
|
196
|
-
## note: \b works only after non-alphanum e.g. )
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# e.g. 2-2 a.e.t. (1-1, 1-0), 5-1 pen.
|
|
200
|
-
SCORE__ET_FT_HT_P__RE = %r{
|
|
201
|
-
(?<score_full>
|
|
202
|
-
\b
|
|
203
|
-
#{SCORE_ET} [ ]+
|
|
204
|
-
\(
|
|
205
|
-
[ ]*
|
|
206
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
207
|
-
[ ]*
|
|
208
|
-
(?:
|
|
209
|
-
, [ ]*
|
|
210
|
-
(?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
211
|
-
[ ]*
|
|
212
|
-
)?
|
|
213
|
-
)? # note: make half time (HT) score optional for now
|
|
214
|
-
\)
|
|
215
|
-
(?: [ ]*,[ ]* | [ ]+)
|
|
216
|
-
#{SCORE_P}
|
|
217
|
-
#{SCORE_LOOKAHEAD}
|
|
218
|
-
)}ix ## todo/check: remove loakahead assertion here - why require space?
|
|
219
|
-
## note: \b works only after non-alphanum e.g. )
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
## e.g. 3-4 pen. 2-2 a.e.t. (1-1, 1-1) or
|
|
224
|
-
## 3-4p 2-2aet (1-1, ) or
|
|
225
|
-
## 3-4 pen. 2-2 a.e.t. (1-1) or
|
|
226
|
-
## 2-2 a.e.t. (1-1, 1-1) or
|
|
227
|
-
## 2-2 a.e.t. (1-1, ) or
|
|
228
|
-
## 2-2 a.e.t. (1-1)
|
|
229
|
-
|
|
230
|
-
SCORE__P_ET_FT_HT__RE = %r{
|
|
231
|
-
(?<score_full>
|
|
232
|
-
\b
|
|
233
|
-
(?:
|
|
234
|
-
#{SCORE_P} [ ]+
|
|
235
|
-
)? ## note - make penalty (P) score optional for now
|
|
236
|
-
#{SCORE_ET} [ ]+
|
|
237
|
-
\(
|
|
238
|
-
[ ]*
|
|
239
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
240
|
-
[ ]*
|
|
241
|
-
(?:
|
|
242
|
-
, [ ]*
|
|
243
|
-
(?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
244
|
-
[ ]*
|
|
245
|
-
)?
|
|
246
|
-
)? # note: make half time (HT) score optional for now
|
|
247
|
-
\)
|
|
248
|
-
#{SCORE_LOOKAHEAD}
|
|
249
|
-
)}ix ## todo/check: remove loakahead assertion here - why require space?
|
|
250
|
-
## note: \b works only after non-alphanum e.g. )
|
|
251
|
-
|
|
252
|
-
###
|
|
253
|
-
## special case for case WITHOUT extra time!!
|
|
254
|
-
## same as above (but WITHOUT extra time and pen required)
|
|
255
|
-
SCORE__P_FT_HT__RE = %r{
|
|
256
|
-
(?<score_full>
|
|
257
|
-
\b
|
|
258
|
-
#{SCORE_P} [ ]+
|
|
259
|
-
\(
|
|
260
|
-
[ ]*
|
|
261
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
262
|
-
[ ]*
|
|
263
|
-
(?:
|
|
264
|
-
, [ ]*
|
|
265
|
-
(?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
266
|
-
[ ]*
|
|
267
|
-
)?
|
|
268
|
-
)? # note: make half time (HT) score optional for now
|
|
269
|
-
\)
|
|
270
|
-
#{SCORE_LOOKAHEAD}
|
|
271
|
-
)}ix ## todo/check: remove loakahead assertion here - why require space?
|
|
272
|
-
## note: \b works only after non-alphanum e.g. )
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
##########
|
|
276
|
-
## e.g. 2-1 (1-1)
|
|
277
|
-
SCORE__FT_HT__RE = %r{
|
|
278
|
-
(?<score_full>
|
|
279
|
-
\b
|
|
280
|
-
(?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
281
|
-
[ ]+ \( [ ]*
|
|
282
|
-
(?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
|
|
283
|
-
[ ]* \)
|
|
284
|
-
#{SCORE_LOOKAHEAD}
|
|
285
|
-
)}ix ## todo/check: remove loakahead assertion here - why require space?
|
|
286
|
-
## note: \b works only after non-alphanum e.g. )
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
#############################################
|
|
292
|
-
# map tables
|
|
293
|
-
# note: order matters; first come-first matched/served
|
|
294
|
-
|
|
295
|
-
SCORE_FULL_RE = Regexp.union(
|
|
296
|
-
SCORE__ET_GG_SG__RE, # e.g. 3-1 aet/gg
|
|
297
|
-
SCORE__P_ET_FT_HT_V2__RE, # e.g. 5-1 pen. (2-2, 1-1, 1-0)
|
|
298
|
-
SCORE__ET_FT_HT_P__RE, # e.g. 2-2 a.e.t. (1-1, 1-0), 5-1 pen.
|
|
299
|
-
SCORE__P_ET_FT_HT__RE, # e.g. 5-1 pen. 2-2 a.e.t. (1-1, 1-0)
|
|
300
|
-
SCORE__P_FT_HT__RE, # e.g. 5-1 pen. (1-1)
|
|
301
|
-
SCORE__ET_P__RE, # e.g. 2-2 a.e.t., 5-1 pen.
|
|
302
|
-
SCORE__FT_P__RE, # e.g. 2-2, 5-1 pen.
|
|
303
|
-
SCORE__FT_HT_P__RE, # e.g. 2-2 (1-1), 5-1 pen.
|
|
304
|
-
SCORE__P_ET__RE, # e.g. 5-1 pen. 2-2 a.e.t. or 2-2 a.e.t. (w/o pen)
|
|
305
|
-
SCORE__P__RE, # e.g. 5-1 pen.
|
|
306
|
-
SCORE__FT_HT__RE, # e.g. 1-1 (1-0)
|
|
307
|
-
## note - keep basic score as its own token!!!!
|
|
308
|
-
## that is, SCORE & SCORE_MORE
|
|
309
|
-
### SCORE__FT__RE, # e.g. 1-1 -- note - must go last!!!
|
|
310
|
-
)
|
|
311
|
-
|
|
312
|
-
|
|
313
5
|
###
|
|
314
6
|
##
|
|
315
7
|
## add support for score awarded (inline style)
|
|
316
|
-
## 3-0 awd 3-0 awd. 3-0awd
|
|
8
|
+
## 3-0 awd 3-0 awd. 3-0awd
|
|
317
9
|
## 0-1 awd or 0-1 AWD etc.
|
|
318
10
|
|
|
319
11
|
##
|
|
@@ -327,7 +19,7 @@ SCORE_AWD_RE = %r{
|
|
|
327
19
|
(?-i: awd\.? | AWD )
|
|
328
20
|
## POSITIVE lookahead - requires space
|
|
329
21
|
(?= [ ])
|
|
330
|
-
)}ix
|
|
22
|
+
)}ix
|
|
331
23
|
|
|
332
24
|
###
|
|
333
25
|
##
|
|
@@ -341,7 +33,7 @@ SCORE_ABD_RE = %r{
|
|
|
341
33
|
(?-i: abd\.? | ABD )
|
|
342
34
|
## POSITIVE lookahead - requires space
|
|
343
35
|
(?= [ ])
|
|
344
|
-
)}ix
|
|
36
|
+
)}ix
|
|
345
37
|
|
|
346
38
|
#####
|
|
347
39
|
## 2-1
|
|
@@ -349,10 +41,10 @@ SCORE_ABD_RE = %r{
|
|
|
349
41
|
### note - was SCORE__FT__RE
|
|
350
42
|
### changed to "generic" SCORE_RE
|
|
351
43
|
### and
|
|
352
|
-
## (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
44
|
+
## (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
|
|
353
45
|
## changed
|
|
354
|
-
## (?<score1>\d{1,2}) - (?<score2>\d{1,2})
|
|
355
|
-
## to
|
|
46
|
+
## (?<score1>\d{1,2}) - (?<score2>\d{1,2})
|
|
47
|
+
## to
|
|
356
48
|
## pattern match not necessarily the full-time (ft) scoreline!!!
|
|
357
49
|
## - pattern also used for goal seq(uence) e.g. 1-0 Kane, 1-1 Johnson
|
|
358
50
|
SCORE_RE = %r{
|
|
@@ -360,85 +52,9 @@ SCORE_RE = %r{
|
|
|
360
52
|
\b
|
|
361
53
|
(?<score1>\d{1,2}) - (?<score2>\d{1,2})
|
|
362
54
|
\b
|
|
363
|
-
)}ix
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
######
|
|
367
|
-
# add support for "split" score
|
|
368
|
-
# note - for now (2) 1 is REQUIRED
|
|
369
|
-
|
|
370
|
-
SCORE_TEAM_RE = %r{
|
|
371
|
-
(?<score_team>
|
|
372
|
-
\(
|
|
373
|
-
(?<score_i> \d{1,2})
|
|
374
|
-
\)
|
|
375
|
-
[ ]* ## note - space optional- why? why not?
|
|
376
|
-
(?<score_ii> \d{1,2})
|
|
377
|
-
\b
|
|
378
|
-
)
|
|
379
|
-
}ix
|
|
380
|
-
|
|
381
|
-
# "penalty"-style (4) is assumed penalty score
|
|
382
|
-
# note - for now 1 (4) is REQUIRED
|
|
383
|
-
|
|
384
|
-
SCORE_TEAM_PEN_RE = %r{
|
|
385
|
-
(?<score_team_pen>
|
|
386
|
-
\b
|
|
387
|
-
(?<score_i> \d{1,2})
|
|
388
|
-
\b
|
|
389
|
-
[ ]* ## note - space optional- why? why not?
|
|
390
|
-
\(
|
|
391
|
-
(?<score_pen> \d{1,2})
|
|
392
|
-
\)
|
|
393
|
-
)
|
|
394
|
-
}ix
|
|
395
|
-
|
|
396
|
-
########
|
|
397
|
-
## note - score_team_num (<100) e.g. 0, 1, .., 10, 11, .. 99
|
|
398
|
-
## use a different name - why? why not?
|
|
399
|
-
## note - must be surrouned by space
|
|
400
|
-
SCORE_TEAM_NUM_RE = %r{
|
|
401
|
-
## positive lookbehind
|
|
402
|
-
(?<= [ ])
|
|
403
|
-
|
|
404
|
-
(?<score_team_num> \d{1,2} )
|
|
405
|
-
|
|
406
|
-
## positive lookahead
|
|
407
|
-
(?= [ ]|\z)
|
|
408
|
-
}x
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
def self._build_score_team( m )
|
|
413
|
-
score = {}
|
|
414
|
-
## note - score team is "generic"
|
|
415
|
-
## might be full-time (ft) or
|
|
416
|
-
## after extra-time (aet) or such
|
|
417
|
-
## or even undecided/unknown
|
|
418
|
-
## thus, use score_i/score_ii
|
|
419
|
-
score[:score] = [m[:score_i].to_i(10),
|
|
420
|
-
m[:score_ii].to_i(10)]
|
|
421
|
-
score
|
|
422
|
-
end
|
|
423
|
-
def _build_score_team( m ) self.class._build_score_team( m ); end
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
def self._build_score_team_pen( m )
|
|
427
|
-
score = {}
|
|
428
|
-
score[:score] = [m[:score_i].to_i(10),
|
|
429
|
-
m[:score_pen].to_i(10)]
|
|
430
|
-
score
|
|
431
|
-
end
|
|
432
|
-
def _build_score_team_pen( m ) self.class._build_score_team_pen( m ); end
|
|
433
|
-
|
|
55
|
+
)}ix
|
|
434
56
|
|
|
435
|
-
def self._build_score_team_num( m )
|
|
436
|
-
score = {}
|
|
437
|
-
score[:score] = m[:score_team_num].to_i(10)
|
|
438
|
-
score
|
|
439
|
-
end
|
|
440
|
-
def _build_score_team_num( m ) self.class._build_score_team_num( m ); end
|
|
441
57
|
|
|
442
58
|
|
|
443
|
-
end
|
|
444
|
-
end
|
|
59
|
+
end # class Lexer
|
|
60
|
+
end # module SportDb
|