File size: 7,661 Bytes
41bdb13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f101223
 
 
41bdb13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d7970d
 
e5250f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

import re
import unicodedata

jp_pos_to_en_pos = {
    '投': 'P',
    '捕': 'C',
    '一': '1B',
    '二': '2B',
    '三': '3B',
    '遊': 'SS',
    '左': 'LF',
    '中': 'CF',
    '右': 'RF',
    '右中': 'RCF',
    '左中': 'LCF'
}

def translate_pa_outcome(outcome):

  partial_outcomes = {
      'ファウルフライ': 'FF',
      'ファウルライナー': 'FL',
      'ゴロ': 'GB',
      'フライ': 'FB',
      'ライナー': 'LD',
      '安打': '1B',
      '2塁打': '2B',
      '3塁打': '3B',
      'ランニング本塁打': 'IHR', # inside-the-park home run
      '本塁打': 'HR',
      '犠打': 'SH',
      '犠飛': 'SF',
      '併殺打': 'DP', # what about triple plays?
      'エラー': 'E',
      '犠打野選': 'SH FC',
      '野選': 'FC'
  }

  if outcome.endswith('三振'):
    if outcome.startswith('空振り'):
      return 'K'
    elif outcome.startswith('見逃し'):
      return 'inv_K'
  elif outcome == '四球':
    return 'BB'
  elif outcome == '死球':
    return 'HBP'
  elif outcome == '敬遠(申告敬遠)':
    return 'IBB'
  elif outcome == 'スリーバント失敗':
    return 'bunt_K' # have to confirm
  elif outcome == '犠打失':
    return 'failed_SH' # have to confirm
  elif outcome == '犠飛失':
    return 'failed_SF' #have to confirm
  elif outcome.endswith('走塁妨害'):
    return 'obstruction'
  elif outcome.endswith('走塁妨害'):
    return 'dropped_K_safe'
  elif outcome == '振り逃げ' or '暴投' in outcome:
    return 'WP' # reached base on WP; on another search, 振り逃げ is an uncaught third strike
  elif outcome.endswith('塁けん制 アウト'):
    return outcome.replace('塁けん制 アウト', 'B PK')
  elif 'けん制アウト' in outcome:
    return 'XB PK' # pickoff at unknown base
  elif outcome == '守備妨害':
    return 'defensive_interference'
  elif '盗塁失敗' in outcome:
    return 'CS'
  elif tag_search:= re.search(r'[123本](・[123本])*塁(間|上)タッチアウト', outcome):
    outcome = unicodedata.normalize('NFKC', tag_search.group(0))
    outcome = outcome.replace('本', 'H')
    bases = re.findall(r'\d|H', outcome)
    return ' '.join(bases) + 'TO' # tag out
  elif '捕逸' in outcome:
    return 'PB' # reached base on passed ball

  for _outcome in partial_outcomes.keys():
    if outcome.endswith(_outcome):
      return f'{jp_pos_to_en_pos[outcome.removesuffix(_outcome)]} {partial_outcomes[_outcome]}'

  return outcome

jp_pitch_to_en_pitch = {
    # fastballs
    'ストレート': '4-Seam Fastball',
    'ツーシーム': '2-Seam Fastball',
    'カットボール': 'Cutter',
    'ワンシーム': '1-Seam Fastball',
    'シンカー': 'Sinker',
    'シュート': 'Shootball',

    # breaking balls
    'スライダー': 'Slider',
    '縦スライダー': 'Vertical Slider',
    '高速スライダー': 'Hard Slider',
    'スラーブ': 'Slurve',
    'カーブ': 'Curveball',
    'ナックルカーブ': 'Knuckle Curve',
    'スローカーブ': 'Slow Curve',
    'パワーカーブ': 'Power Curve',
    'スクリュー': 'Screwball',

    # off speed
    'チェンジアップ': 'Changeup',
    'スプリット': 'Splitter',
    'フォーク': 'Forkball',
    'パーム': 'Palmball',

    # other
    'スローボール': 'Eephus',
}

jp_pitch_to_pitch_code = {
    # fastballs
    'ストレート': 'FF',
    'ツーシーム': 'FT',
    'カットボール': 'FC',
    'ワンシーム': 'FE',
    'シンカー': 'SI',
    'シュート': 'SH',

    # breaking balls
    'スライダー': 'SL',
    '縦スライダー': 'VS',
    '高速スライダー': 'HS',
    'スラーブ': 'SV',
    'カーブ': 'CU',
    'ナックルカーブ': 'KC',
    'スローカーブ': 'CS',
    'パワーカーブ': 'PC',
    'スクリュー': 'SC',

    # off speed
    'チェンジアップ': 'CH',
    'スプリット': 'FS',
    'フォーク': 'FO',
    'パーム': 'PA',

    # other
    'スローボール': 'EP',
}

def translate_pitch_outcome(outcome):

  partial_outcomes = {
      '失': 'E',
      '犠打': 'SH',
      '犠飛': 'SF',
      '邪直': 'FLD', # foul line drive
      '邪飛': 'FF',
      'ゴロ': 'GB',
      '飛': 'FB',
      '直': 'LD',
      '安': '1B',
      '2': '2B',
      '3': '3B',
      '走本': 'IHR', # inside-the-park home run, should confirm
      '本': 'HR',
      '併打': 'DP',
      '犠野': 'SH FC',
      '野選': 'FC'

  }

  if outcome == 'ボール':
    return 'B'
  elif outcome == 'ファウル':
    return 'F'
  elif outcome == '空振り':
    return 'SS' # swinging strike
  elif outcome == '見逃し':
    return 'LS' # swinging strike
  elif outcome == '空三振':
    return 'K'
  elif outcome == '見三振':
    return 'inv_K'
  elif outcome == 'バ三振':
    return 'bunt_K'
  elif outcome == '四球':
    return 'BB'
  elif outcome == '死球':
    return 'HBP'
  elif outcome == '犠打失':
    return 'SH_E' # or SBE? sac hit error
  elif outcome == '犠飛失':
    return 'SF_E' # sac fly error
  elif outcome == '走妨':
    return 'obstruction'
  elif outcome == '反則投球':
    return 'illegal_pitch'
  elif outcome == '守妨':
    return 'defensive_interference'
  elif outcome == '暴振逃':
    return 'WP_S'
  elif outcome == '逸振逃':
    return 'PB_S'

  for _outcome in partial_outcomes.keys():
    if outcome.endswith(_outcome):
      return f'{jp_pos_to_en_pos[outcome.removesuffix(_outcome)]} {partial_outcomes[_outcome]}'

  return outcome

max_pitch_types = len(jp_pitch_to_en_pitch)

jp_team_to_en_team = {
    '阪神': 'Hanshin',
    '楽天': 'Rakuten',
    'オリックス': 'Orix',
    'ソフトバンク': 'SoftBank',
    'ヤクルト': 'Yakult',
    'ロッテ': 'Lotte',
    '巨人': 'Giants',
    '日本ハム': 'Nippon-Ham',
    '西武': 'Seibu',
    '中日': 'Chunichi',
    'DeNA': 'DeNA',
    '広島': 'Hiroshima',
    'オリックス・バファローズ': 'Orix',
    '北海道日本ハムファイターズ': 'Nippon-Ham',
    '埼玉西武ライオンズ': 'Seibu',
    '東京ヤクルトスワローズ': 'Yakult',
    '横浜DeNAベイスターズ': 'DeNA',
    '読売ジャイアンツ': 'Giants',
    '千葉ロッテマリーンズ': 'Lotte',
    '広島東洋カープ': 'Hiroshima',
    '東北楽天ゴールデンイーグルス': 'Rakuten',
    '中日ドラゴンズ': 'Chunichi',
    '福岡ソフトバンクホークス': 'SoftBank',
    '阪神タイガース': 'Hanshin'
}

jp_team_to_en_full_team = {
    '阪神': 'Hanshin Tigers',
    '楽天': 'Rakuten Eagles',
    'オリックス': 'Orix Buffaloes',
    'ソフトバンク': 'Softbank Hawks',
    'ヤクルト': 'Yakult Swallows',
    'ロッテ': 'Lotte Marines',
    '巨人': 'Tokyo Giants',
    '日本ハム': 'Nippon-Ham Fighters',
    '西武': 'Seibu Lions',
    '中日': 'Chunichi Dragons',
    'DeNA': 'DeNA BayStars',
    '広島': 'Hiroshima Carp',
    'オリックス・バファローズ': 'Orix Buffaloes',
    '北海道日本ハムファイターズ': 'Nippon-Ham Fighters',
    '埼玉西武ライオンズ': 'Seibu Lions',
    '東京ヤクルトスワローズ': 'Yakult Swallows',
    '横浜DeNAベイスターズ': 'DeNA BayStars',
    '読売ジャイアンツ': 'Yomiuri Giants',
    '千葉ロッテマリーンズ': 'Lotte Marines',
    '広島東洋カープ': 'Hiroshima Caro',
    '東北楽天ゴールデンイーグルス': 'Rakuten Eagles',
    '中日ドラゴンズ': 'Chunichi Dragons',
    '福岡ソフトバンクホークス': 'SoftBank Hawks',
    '阪神タイガース': 'Hanshin Tigers'
}