#!/usr/bin/env -S uv run --script # # /// script # requires-python = ">=3.12" # dependencies = [ # "ud-hf-parquet-tools", # "python-dotenv", # ] # /// """ Generate Parquet files from Universal Dependencies CoNLL-U data. This script is a wrapper around the ud-hf-parquet-tools library. For the actual implementation, see: https://github.com/bot-zen/ud-hf-parquet-tools Repository: commul/universal_dependencies Usage: python 04_generate_parquet.py [OPTIONS] Options: --test Only process 3 test treebanks (fr_gsd, en_ewt, it_isdt) --treebanks NAMES Comma-separated list of treebank names to process --blocked-treebanks FILE Path to blocked treebanks YAML file (default: tools/blocked_treebanks.yaml) --overwrite Overwrite existing parquet files (default: skip existing) -v, --verbose Print progress messages (default: True) -q, --quiet Suppress progress messages Note for developers: If you're modifying the ud-hf-parquet-tools library locally, run this script with 'python' directly instead of relying on the shebang, to ensure it uses your local editable install rather than the PyPI version: python tools/04_generate_parquet.py [options] """ import argparse import os import sys from pathlib import Path from dotenv import load_dotenv from ud_hf_parquet_tools.cli import main as ud_tools_main # Load environment variables load_dotenv() UD_VER = os.getenv("UD_VER", "2.17") # Project paths REPO_ROOT = Path(__file__).parent.parent.resolve() METADATA_FILE = REPO_ROOT / f"metadata.json" UD_REPOS_DIR = REPO_ROOT / "tools" / "UD_repos" OUTPUT_DIR = REPO_ROOT / "parquet" BLOCKED_TREEBANKS_FILE = REPO_ROOT / "tools" / "blocked_treebanks.yaml" def main(): """Main entry point - wrapper around ud-hf-parquet-tools.""" parser = argparse.ArgumentParser( description="Generate Parquet files from Universal Dependencies CoNLL-U data" ) parser.add_argument("--test", action="store_true", help="Test mode: process 3 treebanks only") parser.add_argument("--treebanks", help="Comma-separated list of treebank names") parser.add_argument("--blocked-treebanks", help="Path to blocked treebanks YAML file") parser.add_argument("--overwrite", action="store_true", help="Overwrite existing parquet files") parser.add_argument("-v", "--verbose", action="store_true", default=True, help="Verbose output") parser.add_argument("-q", "--quiet", action="store_true", help="Quiet mode") args = parser.parse_args() # Use default blocked treebanks file if not specified blocked_treebanks_path = args.blocked_treebanks or str(BLOCKED_TREEBANKS_FILE) # Build arguments for ud-hf-parquet-tools tool_args = [ "ud-hfp-tools", "generate", "--metadata", str(METADATA_FILE), "--ud-repos-dir", str(UD_REPOS_DIR), "--output-dir", str(OUTPUT_DIR), "--blocked-treebanks", blocked_treebanks_path, ] if args.test: tool_args.append("--test") if args.treebanks: tool_args.extend(["--treebanks", args.treebanks]) if args.overwrite: tool_args.append("--overwrite") if args.quiet: tool_args.append("--quiet") elif args.verbose: tool_args.append("--verbose") # Replace sys.argv and call the library's main function original_argv = sys.argv try: sys.argv = tool_args return ud_tools_main() finally: sys.argv = original_argv if __name__ == "__main__": sys.exit(main())