|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
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_dotenv() |
|
|
UD_VER = os.getenv("UD_VER", "2.17") |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
tool_args = [ |
|
|
"ud-hfp-tools", |
|
|
"validate", |
|
|
"--metadata", str(METADATA_FILE), |
|
|
"--ud-repos-dir", str(UD_REPOS_DIR), |
|
|
] |
|
|
|
|
|
|
|
|
if args.parquet_dir: |
|
|
tool_args.extend(["--parquet-dir", args.parquet_dir]) |
|
|
elif args.local: |
|
|
tool_args.extend(["--parquet-dir", str(PARQUET_DIR)]) |
|
|
else: |
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
original_argv = sys.argv |
|
|
try: |
|
|
sys.argv = tool_args |
|
|
return ud_tools_main() |
|
|
finally: |
|
|
sys.argv = original_argv |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
sys.exit(main()) |
|
|
|