Datasets:
File size: 4,279 Bytes
69286fb 2160041 69286fb 654f2d6 2160041 3ed30ac 654f2d6 3ed30ac 2160041 3ed30ac 2160041 3ed30ac 654f2d6 2160041 7c5cccf 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 2160041 654f2d6 |
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 |
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "ud-hf-parquet-tools",
# "python-dotenv",
# ]
# ///
"""
Validate Parquet files by comparing with original 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
This script can validate both:
- Remote: Downloaded from HuggingFace Hub
- Local: Local parquet files in ../parquet/
Repository: commul/universal_dependencies
Usage:
python 05_validate_parquet.py [OPTIONS]
Options:
--test Only validate 3 test treebanks (fr_gsd, en_ewt, it_isdt)
--treebanks NAMES Comma-separated list of treebank names to validate
--revision BRANCH HuggingFace Hub revision/branch (default: 2.17)
--local Validate local parquet files instead of HuggingFace Hub
--parquet-dir DIR Path to local parquet directory (implies --local)
-v, --verbose Print progress messages (default: True)
-vv, --very-verbose Show all differences
-q, --quiet Suppress progress messages
Examples:
# Validate 3 test treebanks from local files
python 05_validate_parquet.py --test --local
# Validate specific treebanks from HuggingFace Hub
python 05_validate_parquet.py --treebanks fr_gsd,en_ewt --revision 2.17
# Validate all treebanks from main branch
python 05_validate_parquet.py --revision main
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/05_validate_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-{UD_VER}.json"
UD_REPOS_DIR = REPO_ROOT / "tools" / "UD_repos"
PARQUET_DIR = REPO_ROOT / "parquet"
def main():
"""Main entry point - wrapper around ud-hf-parquet-tools."""
parser = argparse.ArgumentParser(
description="Validate Parquet files by comparing with original CoNLL-U data"
)
parser.add_argument("--test", action="store_true", help="Test mode: validate 3 treebanks only")
parser.add_argument("--treebanks", help="Comma-separated list of treebank names")
parser.add_argument("--revision", default=UD_VER, help="HuggingFace Hub revision/branch")
parser.add_argument("--local", action="store_true", help="Validate local parquet files")
parser.add_argument("--parquet-dir", help="Path to local parquet directory (implies --local)")
parser.add_argument("-v", "--verbose", action="store_true", default=True, help="Verbose output")
parser.add_argument("-vv", "--very-verbose", action="store_true", help="Show all differences")
parser.add_argument("-q", "--quiet", action="store_true", help="Quiet mode")
args = parser.parse_args()
# Build arguments for ud-hf-parquet-tools
tool_args = [
"ud-hfp-tools",
"validate",
"--metadata", str(METADATA_FILE),
"--ud-repos-dir", str(UD_REPOS_DIR),
]
# Handle parquet directory
if args.parquet_dir:
tool_args.extend(["--parquet-dir", args.parquet_dir])
elif args.local:
tool_args.extend(["--parquet-dir", str(PARQUET_DIR)])
else:
# Remote validation
tool_args.extend(["--revision", args.revision])
if args.test:
tool_args.append("--test")
if args.treebanks:
tool_args.extend(["--treebanks", args.treebanks])
if args.very_verbose:
tool_args.append("-vv")
elif 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())
|