fbtok 0.2.1 → 0.2.3
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/Rakefile +2 -2
- data/bin/fbchk +1 -0
- data/bin/fbtok +15 -8
- data/bin/fbtree +35 -8
- data/bin/fbx +19 -14
- data/lib/fbtok/linter.rb +23 -68
- data/lib/fbtok/opts.rb +9 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cf5b4c14ed4e4466a769b2389e9aaf2add0fe631034010778cfc9a7671d088
|
4
|
+
data.tar.gz: 311e35505a4ec9b729784e4adf415888e64a855fda4a2bed3ab971a51c8ebb40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d1a0b0b736368613f2cae07c69ecc9fec2ca41e3b40a77471e3790ce585a4a4fb5a4559c8005deb59dee2e56fa3f489c2025033b8281910ffec8e77ad94356
|
7
|
+
data.tar.gz: 692715563a64d828eea4bbef1528721773dea1b7c7f4a2103079a804991fcc683ae6afff9aa76dfbf116b5050a77771c85c2ae11f5c950b402391f2eec077d5b
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
|
|
2
2
|
|
3
3
|
|
4
4
|
Hoe.spec 'fbtok' do
|
5
|
-
self.version = '0.2.
|
5
|
+
self.version = '0.2.3'
|
6
6
|
|
7
7
|
self.summary = "fbtok - football.txt lint tools incl. tokenizer, parser & more"
|
8
8
|
self.description = summary
|
@@ -21,7 +21,7 @@ Hoe.spec 'fbtok' do
|
|
21
21
|
self.extra_deps = [
|
22
22
|
# ['sportdb-structs', '>= 0.5.0'],
|
23
23
|
# ['logutils', '>= 0.6.1'],
|
24
|
-
['sportdb-parser', '>= 0.5.
|
24
|
+
['sportdb-parser', '>= 0.5.4'],
|
25
25
|
['sportdb-formats', '>= 2.1.2'],
|
26
26
|
]
|
27
27
|
|
data/bin/fbchk
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-structs/lib' ))
|
10
10
|
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-catalogs/lib' ))
|
11
11
|
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-search/lib' ))
|
12
|
+
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-formats/lib' ))
|
12
13
|
|
13
14
|
|
14
15
|
## our own code
|
data/bin/fbtok
CHANGED
@@ -44,10 +44,17 @@ parser = OptionParser.new do |parser|
|
|
44
44
|
end
|
45
45
|
parser.parse!( args )
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
|
48
|
+
|
49
|
+
if opts[:debug]
|
50
|
+
puts "OPTS:"
|
51
|
+
p opts
|
52
|
+
puts "ARGV:"
|
53
|
+
p args
|
54
|
+
|
55
|
+
SportDb::Parser::Linter.debug = true
|
56
|
+
SportDb::Parser::Opts.debug = true
|
57
|
+
end
|
51
58
|
|
52
59
|
|
53
60
|
## todo/check - use packs or projects or such
|
@@ -55,7 +62,8 @@ p args
|
|
55
62
|
specs = []
|
56
63
|
if opts[:file]
|
57
64
|
recs = read_csv( opts[:file] )
|
58
|
-
pp recs
|
65
|
+
pp recs if opts[:debug]
|
66
|
+
|
59
67
|
## note - make pathspecs relative to passed in file arg!!!
|
60
68
|
basedir = File.dirname( opts[:file] )
|
61
69
|
recs.each do |rec|
|
@@ -65,8 +73,8 @@ if opts[:file]
|
|
65
73
|
else
|
66
74
|
paths = if args.empty?
|
67
75
|
[
|
68
|
-
'
|
69
|
-
'
|
76
|
+
'/sports/openfootball/euro/2021--europe/euro.txt',
|
77
|
+
'/sports/openfootball/euro/2024--germany/euro.txt',
|
70
78
|
]
|
71
79
|
else
|
72
80
|
## check for directories
|
@@ -77,7 +85,6 @@ else
|
|
77
85
|
end
|
78
86
|
|
79
87
|
|
80
|
-
SportDb::Parser::Linter.debug = true if opts[:debug]
|
81
88
|
|
82
89
|
linter = SportDb::Parser::Linter.new
|
83
90
|
|
data/bin/fbtree
CHANGED
@@ -27,18 +27,27 @@ parser = OptionParser.new do |parser|
|
|
27
27
|
end
|
28
28
|
parser.parse!( args )
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
puts "
|
33
|
-
p
|
30
|
+
|
31
|
+
if opts[:debug]
|
32
|
+
puts "OPTS:"
|
33
|
+
p opts
|
34
|
+
puts "ARGV:"
|
35
|
+
p args
|
36
|
+
|
37
|
+
SportDb::Parser::Linter.debug = true
|
38
|
+
SportDb::Parser::Opts.debug = true
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
34
43
|
|
35
44
|
|
36
45
|
## todo/check - use packs or projects or such
|
37
46
|
## instead of specs - why? why not?
|
38
47
|
paths = if args.empty?
|
39
48
|
[
|
40
|
-
'
|
41
|
-
'
|
49
|
+
'/sports/openfootball/euro/2021--europe/euro.txt',
|
50
|
+
'/sports/openfootball/euro/2024--germany/euro.txt',
|
42
51
|
]
|
43
52
|
else
|
44
53
|
## check for directories
|
@@ -48,7 +57,23 @@ p args
|
|
48
57
|
|
49
58
|
|
50
59
|
|
51
|
-
|
60
|
+
def dump_tree_stats( tree )
|
61
|
+
stats = Hash.new(0) ## track counts only for now
|
62
|
+
tree.each do |node|
|
63
|
+
stats[ node.class ] += 1
|
64
|
+
end
|
65
|
+
|
66
|
+
match_count = stats[ RaccMatchParser::MatchLine ]
|
67
|
+
goal_count = stats[ RaccMatchParser::GoalLine ]
|
68
|
+
lineup_count = stats[ RaccMatchParser::LineupLine ]
|
69
|
+
|
70
|
+
puts " #{match_count} MatchLine(s)" if match_count > 0
|
71
|
+
puts " #{goal_count} GoalLine(s)" if goal_count > 0
|
72
|
+
puts " #{lineup_count} LineupLine(s)" if lineup_count > 0
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
52
77
|
|
53
78
|
linter = SportDb::Parser::Linter.new
|
54
79
|
|
@@ -57,7 +82,9 @@ paths.each_with_index do |path,i|
|
|
57
82
|
|
58
83
|
puts "==> [#{i+1}/#{paths.size}] reading >#{path}<..."
|
59
84
|
|
60
|
-
linter.read( path, parse: true )
|
85
|
+
tree = linter.read( path, parse: true )
|
86
|
+
|
87
|
+
dump_tree_stats( tree )
|
61
88
|
end
|
62
89
|
|
63
90
|
|
data/bin/fbx
CHANGED
@@ -70,12 +70,12 @@ paths = if args.empty?
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
if opts[:debug]
|
74
|
+
SportDb::MatchParser.debug = true
|
75
|
+
else
|
76
|
+
SportDb::MatchParser.debug = false
|
77
|
+
LogUtils::Logger.root.level = :info
|
78
|
+
end
|
79
79
|
|
80
80
|
## errors = []
|
81
81
|
|
@@ -84,16 +84,19 @@ paths.each_with_index do |path,i|
|
|
84
84
|
puts "==> [#{i+1}/#{paths.size}] reading >#{path}<..."
|
85
85
|
|
86
86
|
txt = read_text( path )
|
87
|
-
|
88
|
-
## pp secs
|
87
|
+
outline = SportDb::QuickLeagueOutline.parse( txt )
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
## todo/fix - add each_sec_with_index upstream
|
90
|
+
## add outline.secs.size - why? why not?
|
91
|
+
j = 0
|
92
|
+
secs_count = '?'
|
93
|
+
outline.each_sec do |sec| ## sec(tion)s
|
94
|
+
season = Season.parse( sec.season ) ## convert (str) to season obj!!!
|
95
|
+
league = sec.league
|
96
|
+
stage = sec.stage
|
97
|
+
lines = sec.lines
|
95
98
|
|
96
|
-
puts " section #{j+1}/#{
|
99
|
+
puts " section #{j+1}/#{secs_count} - #{league} #{season}, #{stage} - #{lines.size} line(s)"
|
97
100
|
|
98
101
|
next if opts[:outline]
|
99
102
|
|
@@ -130,6 +133,8 @@ paths.each_with_index do |path,i|
|
|
130
133
|
pp rounds
|
131
134
|
puts ">>> #{groups.size} groups:"
|
132
135
|
pp groups
|
136
|
+
|
137
|
+
j += 1
|
133
138
|
end # each secs
|
134
139
|
end # each paths
|
135
140
|
|
data/lib/fbtok/linter.rb
CHANGED
@@ -30,48 +30,19 @@ def read( path, parse: true )
|
|
30
30
|
## note: every (new) read call - resets errors list to empty
|
31
31
|
@errors = []
|
32
32
|
|
33
|
-
|
33
|
+
@tree = []
|
34
34
|
|
35
|
-
|
36
|
-
h1 = nil
|
37
|
-
h2 = nil
|
38
|
-
orphans = 0 ## track paragraphs's with no heading
|
35
|
+
outline = QuickMatchOutline.read( path )
|
39
36
|
|
40
|
-
|
41
|
-
nodes.each do |node|
|
42
|
-
type = node[0]
|
43
|
-
|
44
|
-
if type == :h1
|
45
|
-
h1 = node[1] ## get heading text
|
46
|
-
puts " = Heading 1 >#{node[1]}<"
|
47
|
-
elsif type == :h2
|
48
|
-
if h1.nil?
|
49
|
-
puts "!! WARN - no heading for subheading; skipping parse"
|
50
|
-
next
|
51
|
-
end
|
52
|
-
h2 = node[1] ## get heading text
|
53
|
-
puts " == Heading 2 >#{node[1]}<"
|
54
|
-
elsif type == :p
|
55
|
-
|
56
|
-
if h1.nil?
|
57
|
-
orphans += 1 ## only warn once
|
58
|
-
puts "!! WARN - no heading for #{orphans} text paragraph(s); skipping parse"
|
59
|
-
next
|
60
|
-
end
|
61
|
-
|
62
|
-
lines = node[1]
|
63
|
-
|
64
|
-
|
65
|
-
tree = []
|
37
|
+
outline.each_para do |lines|
|
66
38
|
|
67
39
|
if parse
|
68
|
-
## flatten lines
|
69
|
-
txt =
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
txt = txt.join
|
40
|
+
## flatten lines (array of strings) into all-in-one string
|
41
|
+
txt = lines.reduce( String.new ) do |mem, line|
|
42
|
+
mem << line
|
43
|
+
mem << "\n"
|
44
|
+
mem
|
45
|
+
end
|
75
46
|
|
76
47
|
if debug?
|
77
48
|
puts "lines:"
|
@@ -79,9 +50,16 @@ def read( path, parse: true )
|
|
79
50
|
end
|
80
51
|
|
81
52
|
## todo/fix - add/track parse errors!!!!!!
|
53
|
+
## pass along debug flag to parser (& tokenizer)?
|
82
54
|
parser = RaccMatchParser.new( txt ) ## use own parser instance (not shared) - why? why not?
|
83
55
|
tree = parser.parse
|
84
|
-
|
56
|
+
|
57
|
+
if debug?
|
58
|
+
puts "parse tree:"
|
59
|
+
pp tree
|
60
|
+
end
|
61
|
+
|
62
|
+
@tree += tree ## add nodes
|
85
63
|
|
86
64
|
else ## process for tokenize only
|
87
65
|
lines.each_with_index do |line,i|
|
@@ -104,37 +82,14 @@ def read( path, parse: true )
|
|
104
82
|
end
|
105
83
|
end
|
106
84
|
|
107
|
-
## post-process tokens
|
108
|
-
## - check for round, group, etc.
|
109
|
-
t = t.map do |tok|
|
110
|
-
#############
|
111
|
-
## pass 1
|
112
|
-
## replace all texts with keyword matches (e.g. group, round, leg, etc.)
|
113
|
-
if tok[0] == :TEXT
|
114
|
-
text = tok[1]
|
115
|
-
if @parser.is_group?( text )
|
116
|
-
[:GROUP, text]
|
117
|
-
elsif @parser.is_round?( text ) || @parser.is_leg?( text )
|
118
|
-
[:ROUND, text]
|
119
|
-
else
|
120
|
-
tok ## pass through as-is (1:1)
|
121
|
-
end
|
122
|
-
else
|
123
|
-
tok
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
85
|
pp t if debug?
|
86
|
+
end # each line
|
87
|
+
end # parse? (or tokenize?)
|
88
|
+
end # each para (node)
|
128
89
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
else
|
133
|
-
pp node
|
134
|
-
raise ArgumentError, "unsupported (node) type >#{type}<"
|
135
|
-
end
|
136
|
-
end # each node
|
137
|
-
end # read
|
90
|
+
## note - only returns pare tree for now; no tokens (on parse=false)
|
91
|
+
@tree ## return parse tree
|
92
|
+
end # method read
|
138
93
|
end # class Linter
|
139
94
|
|
140
95
|
|
data/lib/fbtok/opts.rb
CHANGED
@@ -7,6 +7,10 @@ class Parser
|
|
7
7
|
## note - Opts Helpers for now nested inside Parser - keep here? why? why not?
|
8
8
|
class Opts
|
9
9
|
|
10
|
+
def self.debug=(value) @@debug = value; end
|
11
|
+
def self.debug?() @@debug ||= false; end ## note: default is FALSE
|
12
|
+
|
13
|
+
|
10
14
|
SEASON_RE = %r{ (?:
|
11
15
|
\d{4}-\d{2}
|
12
16
|
| \d{4}(--[a-z0-9_-]+)?
|
@@ -63,9 +67,11 @@ def self.expand_args( args )
|
|
63
67
|
## check if directory
|
64
68
|
if Dir.exist?( arg )
|
65
69
|
datafiles = find( arg )
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
if debug?
|
71
|
+
puts
|
72
|
+
puts " found #{datafiles.size} match txt datafiles in #{arg}"
|
73
|
+
pp datafiles
|
74
|
+
end
|
69
75
|
paths += datafiles
|
70
76
|
else
|
71
77
|
## assume it's a file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbtok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5.
|
19
|
+
version: 0.5.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5.
|
26
|
+
version: 0.5.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sportdb-formats
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|