Skip to content

Commit

Permalink
Annotate Rush Duel cards missing Japanese names with OCG counterpart
Browse files Browse the repository at this point in the history
Closes #66
  • Loading branch information
kevinlul committed Jun 14, 2024
1 parent 37446a3 commit f5deb47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
../../../yaml-yugipedia/wikitext/Rush_Duel_cards \
--ko-override ../../../yaml-yugi-ko/rush-override.csv \
--ko-prerelease ../../../yaml-yugi-ko/rush-prerelease.csv \
--ocg-aggregate ../../../aggregate/cards.json \
--aggregate ../../../aggregate/rush.json
- name: Transform (TCG Speed Duel Skills)
working-directory: yaml-yugi/data/tcg-speed-skill
Expand Down
23 changes: 22 additions & 1 deletion src/job_rush.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: © 2022–2023 Kevin Lu
# SPDX-FileCopyrightText: © 2022–2024 Kevin Lu
# SPDX-Licence-Identifier: AGPL-3.0-or-later
import json
import logging
import os
import sys
Expand Down Expand Up @@ -111,6 +112,17 @@ def merge_ko(
flags.setdefault("text", {})["ko"] = True


# On Yugipedia, Rush Duel cards inherit their Japanese name from their OCG counterpart
def annotate_ocg_ja_name(
logger: logging.Logger, document: Dict[str, Any], ocg_cards: Dict[str, Any]
) -> None:
name = document["name"]["en"]
ocg_card = ocg_cards.get(name)
if ocg_card and not document["name"]["ja"]:
logger.info(f"Annotating [{name}] with Japanese OCG card name")
document["name"]["ja"] = ocg_card["name"]["ja"]


def write_output(yaml: YAML, logger: logging.Logger, document: Dict[str, Any]) -> None:
if document["konami_id"] is not None:
basename = document["konami_id"]
Expand All @@ -125,13 +137,20 @@ def job(
ko_official_csv: Optional[str] = None,
ko_override_csv: Optional[str] = None,
ko_prerelease_csv: Optional[str] = None,
ocg_aggregate: Optional[str] = None,
return_results=False,
) -> Optional[List[Dict[str, Any]]]:
yaml = YAML()
yaml.width = sys.maxsize
ko_official = load_ko_csv("konami_id", ko_official_csv) # noqa: F841
ko_override = load_ko_csv("konami_id", ko_override_csv)
ko_prerelease = load_ko_csv("yugipedia_page_id", ko_prerelease_csv)
if ocg_aggregate:
with open(ocg_aggregate) as f:
raw = json.load(f)
ocg_cards = {card["name"]["en"]: card for card in raw}
else:
ocg_cards = None
results = []
for i, filename in enumerate(filenames):
filepath = os.path.join(wikitext_dir, filename)
Expand Down Expand Up @@ -159,6 +178,8 @@ def job(
properties["yugipedia_page_id"] = page_id
document = transform_structure(properties)
merge_ko(logger, document, ko_override, ko_prerelease)
if ocg_cards:
annotate_ocg_ja_name(logger, document, ocg_cards)
write_output(yaml, logger, document)
if return_results:
results.append(document)
Expand Down
4 changes: 3 additions & 1 deletion src/main_rush.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: © 2022 Kevin Lu
# SPDX-FileCopyrightText: © 2022–2024 Kevin Lu
# SPDX-Licence-Identifier: AGPL-3.0-or-later
from argparse import ArgumentParser
import json
Expand All @@ -14,6 +14,7 @@
parser.add_argument("--ko-official", help="yaml-yugi-ko official database CSV")
parser.add_argument("--ko-override", help="yaml-yugi-ko rush-override.csv")
parser.add_argument("--ko-prerelease", help="yaml-yugi-ko rush-prerelease.csv")
parser.add_argument("--ocg-aggregate", help="cards.json")
parser.add_argument(
"--generate-schema", action="store_true", help="output generated JSON schema file"
)
Expand Down Expand Up @@ -43,6 +44,7 @@ def main() -> None:
args.ko_official,
args.ko_override,
args.ko_prerelease,
args.ocg_aggregate,
args.aggregate is not None,
)
if processes == 1:
Expand Down

0 comments on commit f5deb47

Please sign in to comment.