sportdb-catalogs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +17 -0
- data/NOTES.md +5 -0
- data/README.md +141 -0
- data/Rakefile +34 -0
- data/lib/sportdb/catalogs.rb +20 -0
- data/lib/sportdb/catalogs/catalog.rb +105 -0
- data/lib/sportdb/catalogs/config.rb +25 -0
- data/lib/sportdb/catalogs/version.rb +27 -0
- data/lib/sportdb/catalogs/wiki_index.rb +81 -0
- data/test/helper.rb +13 -0
- data/test/test_clubs.rb +100 -0
- data/test/test_clubs_history.rb +47 -0
- data/test/test_countries.rb +33 -0
- data/test/test_leagues.rb +38 -0
- data/test/test_national_teams.rb +38 -0
- data/test/test_wiki_index.rb +42 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e5965c765923646871f9c4b5544ea651c476614
|
4
|
+
data.tar.gz: 6387ea829d97c82a6aafada09f3caf7fa193a530
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d36f04f85b69b4163c7262b50e690679a8133f409b3712e550e4cb4aaad74c7dbba9760e3d23718ff3e13274fb7d9a9bdaa2e2c1e5c052a43e9d461fb8db94b9
|
7
|
+
data.tar.gz: aa7666f61f3ed5964e1eb29cba7cf956510d98f63e9ea3c5192a9e7321a79ee5f185e2768208adfe05784b55d2e300a8bd82433ba8142678937652016f60ae42
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
CHANGELOG.md
|
2
|
+
Manifest.txt
|
3
|
+
NOTES.md
|
4
|
+
README.md
|
5
|
+
Rakefile
|
6
|
+
lib/sportdb/catalogs.rb
|
7
|
+
lib/sportdb/catalogs/catalog.rb
|
8
|
+
lib/sportdb/catalogs/config.rb
|
9
|
+
lib/sportdb/catalogs/version.rb
|
10
|
+
lib/sportdb/catalogs/wiki_index.rb
|
11
|
+
test/helper.rb
|
12
|
+
test/test_clubs.rb
|
13
|
+
test/test_clubs_history.rb
|
14
|
+
test/test_countries.rb
|
15
|
+
test/test_leagues.rb
|
16
|
+
test/test_national_teams.rb
|
17
|
+
test/test_wiki_index.rb
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# sportdb-catalogs - sport.db (search & find) catalogs for countries, leagues, clubs, national teams, and more
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
5
|
+
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
|
+
* gem :: [rubygems.org/gems/sportdb-catalogs](https://rubygems.org/gems/sportdb-catalogs)
|
7
|
+
* rdoc :: [rubydoc.info/gems/sportdb-catalogs](http://rubydoc.info/gems/sportdb-catalogs)
|
8
|
+
* forum :: [opensport](http://groups.google.com/group/opensport)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Let's use the [/clubs datasets](https://github.com/openfootball/clubs)
|
16
|
+
(1500+ football clubs from around the world)
|
17
|
+
to match name "variants" e.g. `Arsenal` to canonical global unique
|
18
|
+
names e.g. `Arsenal FC, London, England`:
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
require 'sportdb/catalogs'
|
22
|
+
|
23
|
+
## note: requires a local copy of the football.db clubs datasets
|
24
|
+
## see https://github.com/openfootball/clubs
|
25
|
+
SportDb::Import.config.clubs_dir = './clubs'
|
26
|
+
|
27
|
+
CLUBS = SportDb::Import.catalog.clubs
|
28
|
+
|
29
|
+
m = CLUBS.match( 'Arsenal' )
|
30
|
+
m.size # 3 club matches found
|
31
|
+
#=> 3
|
32
|
+
m[0].name; m[0].city; m[0].country
|
33
|
+
#=> "Arsenal FC", "London", "England"
|
34
|
+
m[1].name; m[1].city; m[1].country
|
35
|
+
#=> "Arsenal Tula", "Tula", "Russia"
|
36
|
+
m[2].name; m[2].city; m[2].country
|
37
|
+
#=> "Arsenal de Sarandí", "Sarandí", "Argentina"
|
38
|
+
|
39
|
+
|
40
|
+
m = CLUBS.match_by( name: 'Arsenal', country: 'eng' )
|
41
|
+
# -or- try alternative names (and auto-generated spelling variants)
|
42
|
+
m = CLUBS.match_by( name: 'Arsenal FC', country: 'eng' )
|
43
|
+
m = CLUBS.match_by( name: 'Arsenal F.C.', country: 'eng' )
|
44
|
+
m = CLUBS.match_by( name: '...A.r.s.e.n.a.l... F.C...', country: 'eng' )
|
45
|
+
m.size # 1 club match found
|
46
|
+
#=> 1
|
47
|
+
m[0].name; m[0].city; m[0].country
|
48
|
+
#=> "Arsenal FC", "London", "England"
|
49
|
+
|
50
|
+
m = CLUBS.match_by( name: 'Arsenal', country: 'ar' )
|
51
|
+
# -or- try alternative names (and auto-generated spelling variants)
|
52
|
+
m = CLUBS.match_by( name: 'Arsenal Sarandí', country: 'ar' )
|
53
|
+
m = CLUBS.match_by( name: 'Arsenal Sarandi', country: 'ar' )
|
54
|
+
m.size # 1 club match found
|
55
|
+
#=> 1
|
56
|
+
m[0].name; m[0].city; m[0].country
|
57
|
+
#=> "Arsenal de Sarandí", "Sarandí", "Argentina"
|
58
|
+
|
59
|
+
|
60
|
+
# try some more
|
61
|
+
m = CLUBS.match( 'AZ' )
|
62
|
+
m[0].name; m[0].city; m[0].country
|
63
|
+
#=> "AZ Alkmaar", "Alkmaar", "Netherlands"
|
64
|
+
|
65
|
+
m = CLUBS.match( 'Bayern' )
|
66
|
+
# -or- try alternative names (and auto-generated spelling variants)
|
67
|
+
m = CLUBS.match( 'Bayern München' )
|
68
|
+
m = CLUBS.match( 'Bayern Munchen' )
|
69
|
+
m = CLUBS.match( 'Bayern Muenchen' )
|
70
|
+
m[0].name; m[0].city; m[0].country
|
71
|
+
#=> "Bayern München", "München", "Germany"
|
72
|
+
|
73
|
+
# and so on
|
74
|
+
# ...
|
75
|
+
```
|
76
|
+
|
77
|
+
Let's print all names that have duplicate (more than one) matching club:
|
78
|
+
|
79
|
+
``` ruby
|
80
|
+
CLUBS.mappings.each do |name, clubs|
|
81
|
+
if clubs.size > 1
|
82
|
+
puts "#{clubs.size} matching clubs for `#{name}`:"
|
83
|
+
clubs.each do |club|
|
84
|
+
puts " - #{club.name}, #{club.city}, #{club.country.name} (#{club.country.key})"
|
85
|
+
end
|
86
|
+
puts
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
resulting in:
|
92
|
+
|
93
|
+
```
|
94
|
+
2 matching clubs for `valencia`:
|
95
|
+
- Valencia FC, Léogâne, Haiti (ht)
|
96
|
+
- Valencia CF, Valencia, Spain (es)
|
97
|
+
|
98
|
+
2 matching clubs for `apollon`:
|
99
|
+
- Apollon Limassol FC, , Cyprus (cy)
|
100
|
+
- Apollon Smyrnis FC, Athens, Greece (gr)
|
101
|
+
|
102
|
+
3 matching clubs for `arsenal`:
|
103
|
+
- Arsenal FC, London, England (eng)
|
104
|
+
- Arsenal Tula, Tula, Russia (ru)
|
105
|
+
- Arsenal de Sarandí, Sarandí, Argentina (ar)
|
106
|
+
|
107
|
+
2 matching clubs for `liverpool`:
|
108
|
+
- Liverpool FC, Liverpool, England (eng)
|
109
|
+
- Liverpool Montevideo, Montevideo, Uruguay (uy)
|
110
|
+
|
111
|
+
2 matching clubs for `barcelona`:
|
112
|
+
- FC Barcelona, Barcelona, Spain (es)
|
113
|
+
- Barcelona Guayaquil, Guayaquil, Ecuador (ec)
|
114
|
+
|
115
|
+
3 matching clubs for `nacional`:
|
116
|
+
- CD Nacional Madeira, Funchal, Portugal (pt)
|
117
|
+
- Club Nacional, Asunción, Paraguay (py)
|
118
|
+
- Nacional de Montevideo, Montevideo, Uruguay (uy)
|
119
|
+
|
120
|
+
2 matching clubs for `sanjose`:
|
121
|
+
- San Jose Earthquakes, San Jose, United States (us)
|
122
|
+
- Club Deportivo San José, Oruro, Bolivia (bo)
|
123
|
+
|
124
|
+
...
|
125
|
+
```
|
126
|
+
|
127
|
+
That's it.
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
The `sportdb-catalogs` scripts are dedicated to the public domain.
|
134
|
+
Use it as you please with no restrictions whatsoever.
|
135
|
+
|
136
|
+
|
137
|
+
## Questions? Comments?
|
138
|
+
|
139
|
+
Send them along to the
|
140
|
+
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
141
|
+
Thanks!
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/sportdb/catalogs/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'sportdb-catalogs' do
|
5
|
+
|
6
|
+
self.version = SportDb::Module::Catalogs::VERSION
|
7
|
+
|
8
|
+
self.summary = "sportdb-catalogs - sport.db (search 'n' find) catalogs for countries, leagues, clubs, national teams, and more"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['https://github.com/sportdb/sport.db']
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'opensport@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.licenses = ['Public Domain']
|
21
|
+
|
22
|
+
self.extra_deps = [
|
23
|
+
['sportdb-formats', '>= 1.1.3'],
|
24
|
+
## dataset libs / gems
|
25
|
+
['fifa', '>= 2020.5.18'], ## for (builtin/default) countries
|
26
|
+
['footballdb-leagues', '>= 2020.7.7'], ## for (builtin/default) leagues & cups
|
27
|
+
['footballdb-clubs', '>= 2020.7.7'], ## for (builtin/default) clubs
|
28
|
+
]
|
29
|
+
|
30
|
+
self.spec_extras = {
|
31
|
+
required_ruby_version: '>= 2.2.2'
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
### our own sportdb libs / gems
|
4
|
+
require 'sportdb/formats'
|
5
|
+
|
6
|
+
### "built-in" default dataset libs / gems
|
7
|
+
require 'fifa' ## get a list of all fifa countries with (three letter) codes
|
8
|
+
require 'footballdb/leagues'
|
9
|
+
require 'footballdb/clubs'
|
10
|
+
|
11
|
+
|
12
|
+
###
|
13
|
+
# our own code
|
14
|
+
require 'sportdb/catalogs/version' # let version always go first
|
15
|
+
require 'sportdb/catalogs/wiki_index'
|
16
|
+
require 'sportdb/catalogs/catalog'
|
17
|
+
require 'sportdb/catalogs/config'
|
18
|
+
|
19
|
+
|
20
|
+
puts SportDb::Module::Catalogs.banner # say hello
|
@@ -0,0 +1,105 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module Import
|
4
|
+
|
5
|
+
|
6
|
+
class Catalog
|
7
|
+
def config() Import.config; end
|
8
|
+
|
9
|
+
|
10
|
+
## todo/check: rename to country_mappings/index - why? why not?
|
11
|
+
## or countries_by_code or countries_by_key
|
12
|
+
def countries() @countries ||= build_country_index; end
|
13
|
+
def national_teams() @national_teams ||= build_national_team_index; end
|
14
|
+
def clubs() @clubs ||= build_club_index; end
|
15
|
+
def clubs_history() @clubs_history ||= build_club_history_index; end ## note: used for now (only) lookups by season for now
|
16
|
+
def teams() @teams ||= build_team_index; end
|
17
|
+
def leagues() @leagues ||= build_league_index; end
|
18
|
+
|
19
|
+
def events() @events ||= build_event_index; end
|
20
|
+
def seasons() @seasons ||= build_season_index; end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
def build_team_index() TeamIndex.new; end
|
25
|
+
|
26
|
+
def build_country_index ## todo/check: rename to setup_country_index or read_country_index - why? why not?
|
27
|
+
CountryIndex.new( Fifa.countries )
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_national_team_index
|
31
|
+
## auto-build national teams from Fifa.countries for now
|
32
|
+
teams = []
|
33
|
+
Fifa.countries.each do |country|
|
34
|
+
team = NationalTeam.new( key: country.code.downcase, ## note: use country code (fifa)
|
35
|
+
name: country.name,
|
36
|
+
code: country.code, ## note: use country code (fifa)
|
37
|
+
alt_names: country.alt_names )
|
38
|
+
team.country = country
|
39
|
+
|
40
|
+
teams << team
|
41
|
+
end
|
42
|
+
|
43
|
+
NationalTeamIndex.new( teams )
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_club_index
|
47
|
+
## unify team names; team (builtin/known/shared) name mappings
|
48
|
+
## cleanup team names - use local ("native") name with umlaut etc.
|
49
|
+
## todo/fix: add to teamreader
|
50
|
+
## check that name and alt_names for a club are all unique (not duplicates)
|
51
|
+
|
52
|
+
clubs = if config.clubs_dir ## check if clubs_dir is defined / set (otherwise it's nil)
|
53
|
+
ClubIndex.build( config.clubs_dir )
|
54
|
+
else ## no clubs_dir set - try using builtin from footballdb-clubs
|
55
|
+
FootballDb::Import::build_club_index
|
56
|
+
end
|
57
|
+
|
58
|
+
if clubs.errors?
|
59
|
+
puts ""
|
60
|
+
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
61
|
+
puts " #{clubs.errors.size} errors:"
|
62
|
+
pp clubs.errors
|
63
|
+
## exit 1
|
64
|
+
end
|
65
|
+
|
66
|
+
clubs
|
67
|
+
end # method build_club_index
|
68
|
+
|
69
|
+
def build_club_history_index
|
70
|
+
if config.clubs_dir ## (re)use clubs dir for now - why? why not?
|
71
|
+
ClubHistoryIndex.build( config.clubs_dir )
|
72
|
+
else
|
73
|
+
puts "!! WARN - no clubs_dir set; for now NO built-in club histories in catalog; sorry - fix!!!!"
|
74
|
+
ClubHistoryIndex.new ## return empty history index
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def build_league_index
|
80
|
+
leagues = if config.leagues_dir ## check if clubs_dir is defined / set (otherwise it's nil)
|
81
|
+
LeagueIndex.build( config.leagues_dir )
|
82
|
+
else ## no leagues_dir set - try using builtin from footballdb-leagues
|
83
|
+
FootballDb::Import.build_league_index
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def build_event_index
|
89
|
+
if config.leagues_dir ## (re)use leagues dir for now - add separate seasons_dir - why? why not?
|
90
|
+
EventIndex.build( config.leagues_dir )
|
91
|
+
else
|
92
|
+
puts "!! WARN - no leagues_dir set; for now NO built-in events in catalog; sorry - fix!!!!"
|
93
|
+
EventIndex.new ## return empty event index
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_season_index
|
98
|
+
# note: for now always (re)use the events from the event (info) index
|
99
|
+
SeasonIndex.new( events )
|
100
|
+
end
|
101
|
+
|
102
|
+
end # class Catalog
|
103
|
+
|
104
|
+
end # module Import
|
105
|
+
end # module SportDb
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Import
|
5
|
+
|
6
|
+
class Configuration
|
7
|
+
## note: add more configs (open class), see sportdb-formats for original config!!!
|
8
|
+
|
9
|
+
##
|
10
|
+
## todo: allow configure of countries_dir like clubs_dir
|
11
|
+
## "fallback" and use a default built-in world/countries.txt
|
12
|
+
|
13
|
+
####
|
14
|
+
# todo/check: find a better way to configure club / team datasets - why? why not?
|
15
|
+
attr_accessor :clubs_dir
|
16
|
+
## def clubs_dir() @clubs_dir; end ### note: return nil if NOT set on purpose for now - why? why not?
|
17
|
+
|
18
|
+
attr_accessor :leagues_dir
|
19
|
+
## def leagues_dir() @leagues_dir; end
|
20
|
+
|
21
|
+
def catalog() @catalog ||= Catalog.new; end
|
22
|
+
end # class Configuration
|
23
|
+
|
24
|
+
end # module Import
|
25
|
+
end # module SportDb
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module SportDb
|
5
|
+
module Module
|
6
|
+
module Catalogs
|
7
|
+
|
8
|
+
MAJOR = 1 ## todo: namespace inside version or something - why? why not??
|
9
|
+
MINOR = 0
|
10
|
+
PATCH = 0
|
11
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
12
|
+
|
13
|
+
def self.version
|
14
|
+
VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.banner
|
18
|
+
"sportdb-catalogs/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.root
|
22
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Catalogs
|
26
|
+
end # module Module
|
27
|
+
end # module SportDb
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Import
|
5
|
+
|
6
|
+
|
7
|
+
class WikiIndex
|
8
|
+
|
9
|
+
def self.build( path )
|
10
|
+
pack = Package.new( path )
|
11
|
+
recs = []
|
12
|
+
pack.each_clubs_wiki do |entry|
|
13
|
+
recs += WikiReader.parse( entry.read )
|
14
|
+
end
|
15
|
+
recs
|
16
|
+
|
17
|
+
new( recs )
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
include NameHelper
|
22
|
+
## e.g. strip_lang, strip_year, normalize
|
23
|
+
|
24
|
+
## fix/todo:
|
25
|
+
## also used / duplicated in ClubIndex#add_wiki !!!
|
26
|
+
def strip_wiki( name ) # todo/check: rename to strip_wikipedia_en - why? why not?
|
27
|
+
## note: strip disambiguationn qualifier from wikipedia page name if present
|
28
|
+
## note: only remove year and foot... for now
|
29
|
+
## e.g. FC Wacker Innsbruck (2002) => FC Wacker Innsbruck
|
30
|
+
## Willem II (football club) => Willem II
|
31
|
+
##
|
32
|
+
## e.g. do NOT strip others !! e.g.
|
33
|
+
## América Futebol Clube (MG)
|
34
|
+
## only add more "special" cases on demand (that, is) if we find more
|
35
|
+
name = name.gsub( /\([12][^\)]+?\)/, '' ).strip ## starting with a digit 1 or 2 (assuming year)
|
36
|
+
name = name.gsub( /\(foot[^\)]+?\)/, '' ).strip ## starting with foot (assuming football ...)
|
37
|
+
name
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def initialize( recs )
|
42
|
+
@pages_by_country = {}
|
43
|
+
|
44
|
+
## todo/fix:
|
45
|
+
## check for duplicate recs - report and exit on dupliate!!!!!!
|
46
|
+
recs.each do |rec|
|
47
|
+
h = @pages_by_country[ rec.country.key ] ||= {}
|
48
|
+
h[ normalize( strip_wiki( rec.name )) ] = rec
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def find_by( club: ) ## todo/check: use find_by_club - why? why not?
|
54
|
+
find_by_club( club )
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_by_club( club )
|
58
|
+
rec = nil
|
59
|
+
|
60
|
+
## get query params from club
|
61
|
+
names = [club.name]+club.alt_names
|
62
|
+
country_key = club.country.key
|
63
|
+
|
64
|
+
h = @pages_by_country[ country_key ]
|
65
|
+
if h
|
66
|
+
## todo/check: sort names ?
|
67
|
+
## sort by longest first (for best match)
|
68
|
+
names.each do |name|
|
69
|
+
## note: normalize AND sanitize (e.g. remove/string year and lang e.g. (1946-2001), [en] too)
|
70
|
+
rec = h[ normalize( strip_year( strip_lang( name ))) ]
|
71
|
+
break if rec ## bingo!! found - break on first match
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
rec ## note: return nil if nothing found
|
76
|
+
end
|
77
|
+
end # class WikiIndex
|
78
|
+
|
79
|
+
|
80
|
+
end # module Import
|
81
|
+
end # module SportDb
|
data/test/helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## note: use the local version of sportdb gems
|
2
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-formats/lib' ))
|
3
|
+
|
4
|
+
## minitest setup
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
|
8
|
+
## our own code
|
9
|
+
require 'sportdb/catalogs'
|
10
|
+
|
11
|
+
|
12
|
+
SportDb::Import.config.clubs_dir = '../../../openfootball/clubs'
|
13
|
+
SportDb::Import.config.leagues_dir = '../../../openfootball/leagues'
|
data/test/test_clubs.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_clubs.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestClubs < MiniTest::Test
|
9
|
+
|
10
|
+
CLUBS = SportDb::Import.catalog.clubs
|
11
|
+
|
12
|
+
|
13
|
+
def test_match
|
14
|
+
pp CLUBS.errors
|
15
|
+
|
16
|
+
CLUBS.dump_duplicates
|
17
|
+
|
18
|
+
m = CLUBS.match( 'Rapid Wien' )
|
19
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
20
|
+
assert_equal 'Austria', m[0].country.name
|
21
|
+
assert_equal 'Wien', m[0].city
|
22
|
+
|
23
|
+
m = CLUBS.match( 'rapid wien' )
|
24
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
25
|
+
assert_equal 'Austria', m[0].country.name
|
26
|
+
assert_equal 'Wien', m[0].city
|
27
|
+
|
28
|
+
## note: all dots (.) get always removed
|
29
|
+
m = CLUBS.match( '...r.a.p.i.d w.i.e.n...' )
|
30
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
31
|
+
assert_equal 'Austria', m[0].country.name
|
32
|
+
assert_equal 'Wien', m[0].city
|
33
|
+
|
34
|
+
## note: all spaces and dashes (-) get always removed
|
35
|
+
m = CLUBS.match( '--- r a p i d w i e n ---' )
|
36
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
37
|
+
assert_equal 'Austria', m[0].country.name
|
38
|
+
assert_equal 'Wien', m[0].city
|
39
|
+
|
40
|
+
m = CLUBS.match( 'RAPID WIEN' )
|
41
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
42
|
+
assert_equal 'Austria', m[0].country.name
|
43
|
+
assert_equal 'Wien', m[0].city
|
44
|
+
|
45
|
+
|
46
|
+
c = CLUBS[ 'SK Rapid Wien' ] ## check canoncial name match (only)
|
47
|
+
assert_equal 'SK Rapid Wien', c.name
|
48
|
+
assert_equal 'Austria', c.country.name
|
49
|
+
assert_equal 'Wien', c.city
|
50
|
+
|
51
|
+
|
52
|
+
m = CLUBS.match( 'Arsenal' )
|
53
|
+
assert_equal 3, m.size
|
54
|
+
|
55
|
+
m = CLUBS.match( 'ARSENAL' )
|
56
|
+
assert_equal 3, m.size
|
57
|
+
|
58
|
+
m = CLUBS.match_by( name: 'Arsenal', country: 'eng' )
|
59
|
+
assert_equal 1, m.size
|
60
|
+
assert_equal 'Arsenal FC', m[0].name
|
61
|
+
assert_equal 'England', m[0].country.name
|
62
|
+
assert_equal 'London', m[0].city
|
63
|
+
|
64
|
+
m = CLUBS.match_by( name: 'Arsenal', country: 'ar' )
|
65
|
+
assert_equal 1, m.size
|
66
|
+
assert_equal 'Arsenal de Sarandí', m[0].name
|
67
|
+
assert_equal 'Argentina', m[0].country.name
|
68
|
+
assert_equal 'Sarandí', m[0].city
|
69
|
+
|
70
|
+
m = CLUBS.match_by( name: 'Arsenal', country: 'ru' )
|
71
|
+
assert_equal 1, m.size
|
72
|
+
assert_equal 'Arsenal Tula', m[0].name
|
73
|
+
assert_equal 'Russia', m[0].country.name
|
74
|
+
assert_equal 'Tula', m[0].city
|
75
|
+
|
76
|
+
|
77
|
+
m = CLUBS.match( 'Arsenal FC' )
|
78
|
+
assert_equal 2, m.size
|
79
|
+
|
80
|
+
m = CLUBS.match( 'Arsenal F.C.' )
|
81
|
+
assert_equal 2, m.size
|
82
|
+
|
83
|
+
m = CLUBS.match( '...A.r.s.e.n.a.l... F.C...' )
|
84
|
+
assert_equal 2, m.size
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def test_wikipedia ## test wikipedia names and links/urls
|
89
|
+
m = CLUBS.match( 'Club Brugge KV' )
|
90
|
+
assert_equal 1, m.size
|
91
|
+
assert_equal 'Club Brugge KV', m[0].wikipedia
|
92
|
+
assert_equal 'https://en.wikipedia.org/wiki/Club_Brugge_KV', m[0].wikipedia_url
|
93
|
+
|
94
|
+
m = CLUBS.match( 'RSC Anderlecht' )
|
95
|
+
assert_equal 1, m.size
|
96
|
+
assert_equal 'R.S.C. Anderlecht', m[0].wikipedia
|
97
|
+
assert_equal 'https://en.wikipedia.org/wiki/R.S.C._Anderlecht', m[0].wikipedia_url
|
98
|
+
end
|
99
|
+
|
100
|
+
end # class TestClubs
|
@@ -0,0 +1,47 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_clubs_history.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestClubsHistory < MiniTest::Test
|
9
|
+
|
10
|
+
CLUBS = SportDb::Import.catalog.clubs
|
11
|
+
CLUBS_HISTORY = SportDb::Import.catalog.clubs_history
|
12
|
+
|
13
|
+
|
14
|
+
def test_at
|
15
|
+
pp CLUBS_HISTORY.mappings
|
16
|
+
|
17
|
+
puts CLUBS_HISTORY.find_name_by( name: 'WSG Tirol', season: '2019/20' )
|
18
|
+
puts CLUBS_HISTORY.find_name_by( name: 'WSG Tirol', season: '2018/9' )
|
19
|
+
puts CLUBS_HISTORY.find_name_by( name: 'WSG Tirol', season: '2017/8' )
|
20
|
+
|
21
|
+
club = CLUBS.find( 'WSG Wattens' )
|
22
|
+
pp club
|
23
|
+
|
24
|
+
assert_equal 'WSG Tirol', club.name_by_season( '2019/20' )
|
25
|
+
assert_equal 'WSG Wattens', club.name_by_season( '2018/9' )
|
26
|
+
assert_equal 'WSG Wattens', club.name_by_season( '2017/8' )
|
27
|
+
|
28
|
+
|
29
|
+
club = CLUBS.find( 'Rapid Wien' )
|
30
|
+
pp club
|
31
|
+
|
32
|
+
assert_equal 'SK Rapid Wien', club.name_by_season( '2000/1' )
|
33
|
+
assert_equal 'SK Rapid Wien', club.name_by_season( '1891/2' )
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_eng
|
37
|
+
club = CLUBS.find_by( name: 'Arsenal', country: 'ENG' )
|
38
|
+
pp club
|
39
|
+
|
40
|
+
assert_equal 'Arsenal FC', club.name_by_season( '2000/1' )
|
41
|
+
assert_equal 'Arsenal FC', club.name_by_season( '1927/8' )
|
42
|
+
assert_equal 'The Arsenal FC', club.name_by_season( '1926/7' )
|
43
|
+
assert_equal 'Woolwich Arsenal FC', club.name_by_season( '1913/4' )
|
44
|
+
assert_equal 'Royal Arsenal FC', club.name_by_season( '1891/2' )
|
45
|
+
end
|
46
|
+
|
47
|
+
end # class TestClubsHistory
|
@@ -0,0 +1,33 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_countries.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestCountries < MiniTest::Test
|
9
|
+
|
10
|
+
COUNTRIES = SportDb::Import.catalog.countries
|
11
|
+
|
12
|
+
|
13
|
+
def test_countries
|
14
|
+
## pp COUNTRIES
|
15
|
+
|
16
|
+
eng = COUNTRIES.find( :eng )
|
17
|
+
assert_equal 'eng', eng.key
|
18
|
+
assert_equal 'England', eng.name
|
19
|
+
assert_equal 'ENG', eng.code
|
20
|
+
|
21
|
+
at = COUNTRIES.find( :at )
|
22
|
+
assert_equal 'at', at.key
|
23
|
+
assert_equal 'Austria', at.name
|
24
|
+
assert_equal 'AUT', at.code
|
25
|
+
|
26
|
+
assert at == COUNTRIES.find( 'AT' )
|
27
|
+
assert at == COUNTRIES.find( 'at' )
|
28
|
+
assert at == COUNTRIES.find( 'AUT' )
|
29
|
+
assert at == COUNTRIES.find( 'aut' )
|
30
|
+
assert at == COUNTRIES.find( :aut )
|
31
|
+
end
|
32
|
+
|
33
|
+
end # class TestCountries
|
@@ -0,0 +1,38 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_leagues.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestLeagues < MiniTest::Test
|
9
|
+
|
10
|
+
LEAGUES = SportDb::Import.catalog.leagues
|
11
|
+
|
12
|
+
|
13
|
+
def test_match
|
14
|
+
pp LEAGUES.errors
|
15
|
+
|
16
|
+
LEAGUES.dump_duplicates
|
17
|
+
|
18
|
+
m = LEAGUES.match( 'English Premier League' )
|
19
|
+
pp m
|
20
|
+
assert_equal 'Premier League', m[0].name
|
21
|
+
assert_equal 'eng.1', m[0].key
|
22
|
+
assert_equal 'England', m[0].country.name
|
23
|
+
assert_equal 'eng', m[0].country.key
|
24
|
+
assert m[0].clubs?
|
25
|
+
assert m[0].domestic?
|
26
|
+
assert_equal false, m[0].intl?
|
27
|
+
assert_equal false, m[0].national_teams?
|
28
|
+
|
29
|
+
m = LEAGUES.match( 'Euro' )
|
30
|
+
pp m
|
31
|
+
assert_equal 'Euro', m[0].name
|
32
|
+
assert_equal 'euro', m[0].key
|
33
|
+
assert m[0].national_teams?
|
34
|
+
assert m[0].intl?
|
35
|
+
assert_equal false, m[0].clubs?
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class TestLeagues
|
@@ -0,0 +1,38 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_national_teams.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestNationalTeams < MiniTest::Test
|
9
|
+
|
10
|
+
NATIONAL_TEAMS = SportDb::Import.catalog.national_teams
|
11
|
+
|
12
|
+
|
13
|
+
def test_find
|
14
|
+
t = NATIONAL_TEAMS.find( 'AUT' )
|
15
|
+
assert_equal 'Austria', t.name
|
16
|
+
assert_equal 'aut', t.key
|
17
|
+
assert_equal 'AUT', t.code
|
18
|
+
|
19
|
+
|
20
|
+
t = NATIONAL_TEAMS.find( 'England' )
|
21
|
+
assert_equal 'England', t.name
|
22
|
+
assert_equal 'eng', t.key
|
23
|
+
assert_equal 'ENG', t.code
|
24
|
+
|
25
|
+
## note: all dots (.) get always removed
|
26
|
+
t = NATIONAL_TEAMS.find( '...e.n.g.l.a.n.d...' )
|
27
|
+
assert_equal 'England', t.name
|
28
|
+
assert_equal 'eng', t.key
|
29
|
+
assert_equal 'ENG', t.code
|
30
|
+
|
31
|
+
## note: all spaces and dashes (-) get always removed
|
32
|
+
t = NATIONAL_TEAMS.find( '--- e n g l a n d ---' )
|
33
|
+
assert_equal 'England', t.name
|
34
|
+
assert_equal 'eng', t.key
|
35
|
+
assert_equal 'ENG', t.code
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class TestNationalTeams
|
@@ -0,0 +1,42 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_wiki_index.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestWikiIndex < MiniTest::Test
|
9
|
+
|
10
|
+
Club = SportDb::Import::Club
|
11
|
+
|
12
|
+
COUNTRIES = SportDb::Import.catalog.countries
|
13
|
+
|
14
|
+
|
15
|
+
def test_clubs
|
16
|
+
## note: CANNOT run if no "custom" clubs_dir set
|
17
|
+
return if SportDb::Import.config.clubs_dir.nil?
|
18
|
+
|
19
|
+
wiki = SportDb::Import::WikiIndex.build( SportDb::Import.config.clubs_dir )
|
20
|
+
## pp wiki
|
21
|
+
|
22
|
+
##############################################
|
23
|
+
## test wikipedia names and links/urls
|
24
|
+
be = COUNTRIES.find( 'be' )
|
25
|
+
|
26
|
+
club = Club.new
|
27
|
+
club.name = 'Club Brugge KV'
|
28
|
+
club.country = be
|
29
|
+
|
30
|
+
rec = wiki.find_by( club: club )
|
31
|
+
assert_equal 'Club Brugge KV', rec.name
|
32
|
+
|
33
|
+
|
34
|
+
club = Club.new
|
35
|
+
club.name = 'RSC Anderlecht'
|
36
|
+
club.country = be
|
37
|
+
|
38
|
+
rec = wiki.find_by( club: club )
|
39
|
+
assert_equal 'R.S.C. Anderlecht', rec.name
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class TestWikiIndex
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sportdb-catalogs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sportdb-formats
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fifa
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2020.5.18
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2020.5.18
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: footballdb-leagues
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2020.7.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2020.7.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: footballdb-clubs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2020.7.7
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2020.7.7
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hoe
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.16'
|
97
|
+
description: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries,
|
98
|
+
leagues, clubs, national teams, and more
|
99
|
+
email: opensport@googlegroups.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- CHANGELOG.md
|
104
|
+
- Manifest.txt
|
105
|
+
- NOTES.md
|
106
|
+
- README.md
|
107
|
+
files:
|
108
|
+
- CHANGELOG.md
|
109
|
+
- Manifest.txt
|
110
|
+
- NOTES.md
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- lib/sportdb/catalogs.rb
|
114
|
+
- lib/sportdb/catalogs/catalog.rb
|
115
|
+
- lib/sportdb/catalogs/config.rb
|
116
|
+
- lib/sportdb/catalogs/version.rb
|
117
|
+
- lib/sportdb/catalogs/wiki_index.rb
|
118
|
+
- test/helper.rb
|
119
|
+
- test/test_clubs.rb
|
120
|
+
- test/test_clubs_history.rb
|
121
|
+
- test/test_countries.rb
|
122
|
+
- test/test_leagues.rb
|
123
|
+
- test/test_national_teams.rb
|
124
|
+
- test/test_wiki_index.rb
|
125
|
+
homepage: https://github.com/sportdb/sport.db
|
126
|
+
licenses:
|
127
|
+
- Public Domain
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options:
|
131
|
+
- "--main"
|
132
|
+
- README.md
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 2.2.2
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.5.2
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries, leagues,
|
151
|
+
clubs, national teams, and more
|
152
|
+
test_files: []
|