Datasets:
Unify release-handle mapping and harden tools pipeline
Browse files- add shared tools/etc/ud_release_handles.tsv for UD version->CLARIN handle mapping
- make metadata and snapshot fetch scripts read from the shared mapping
- add snapshot cleanup controls (--keep-archive, --keep-backup)
- fix metadata generation output guard for first-run/nonexistent output files
- ADDING_NEW_UD_VERSION.md +14 -5
- tools/00_fetch_ud_clarin-dspace_metadata.py +24 -17
- tools/01_fetch_ud_snapshot.sh +38 -22
- tools/02_generate_metadata.py +3 -1
- tools/README.md +13 -2
- tools/etc/ud_release_handles.tsv +13 -0
ADDING_NEW_UD_VERSION.md
CHANGED
|
@@ -83,11 +83,10 @@ cat .env
|
|
| 83 |
|
| 84 |
**Before running**, update the script to add the new version's handle ID:
|
| 85 |
|
| 86 |
-
1. Open `
|
| 87 |
-
2.
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
"2.18": "11234/1-XXXX", # Check UD website for correct handle
|
| 91 |
```
|
| 92 |
|
| 93 |
**Where to find handle?** Visit the [UD release page](https://universaldependencies.org/) and check the LINDAT citation link.
|
|
@@ -127,6 +126,11 @@ cat .env
|
|
| 127 |
|
| 128 |
**What does this do?** Downloads the official release archive from LINDAT/CLARIN (`https://hdl.handle.net/<handle>/allzip`), extracts it, and points `UD_repos` to the extracted snapshot.
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
### 7. Verify Snapshot Layout
|
| 131 |
|
| 132 |
```bash
|
|
@@ -405,6 +409,11 @@ cd tools
|
|
| 405 |
ls -ld UD_repos ud-treebanks-v2.18
|
| 406 |
```
|
| 407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
### Issue: Metadata extraction fails for a treebank
|
| 409 |
|
| 410 |
**Problem:** A treebank is malformed or missing expected files.
|
|
|
|
| 83 |
|
| 84 |
**Before running**, update the script to add the new version's handle ID:
|
| 85 |
|
| 86 |
+
1. Open `tools/etc/ud_release_handles.tsv`
|
| 87 |
+
2. Add entry for new version:
|
| 88 |
+
```text
|
| 89 |
+
2.18 11234/1-XXXX
|
|
|
|
| 90 |
```
|
| 91 |
|
| 92 |
**Where to find handle?** Visit the [UD release page](https://universaldependencies.org/) and check the LINDAT citation link.
|
|
|
|
| 126 |
|
| 127 |
**What does this do?** Downloads the official release archive from LINDAT/CLARIN (`https://hdl.handle.net/<handle>/allzip`), extracts it, and points `UD_repos` to the extracted snapshot.
|
| 128 |
|
| 129 |
+
**Useful options:**
|
| 130 |
+
- `--online`: Force re-download and re-extraction
|
| 131 |
+
- `--keep-archive`: Keep the downloaded zip after extraction
|
| 132 |
+
- `--keep-backup`: Keep previous snapshot as `ud-treebanks-v{VER}.bak.<timestamp>`
|
| 133 |
+
|
| 134 |
### 7. Verify Snapshot Layout
|
| 135 |
|
| 136 |
```bash
|
|
|
|
| 409 |
ls -ld UD_repos ud-treebanks-v2.18
|
| 410 |
```
|
| 411 |
|
| 412 |
+
If you need to preserve artifacts for debugging:
|
| 413 |
+
```bash
|
| 414 |
+
./01_fetch_ud_snapshot.sh --online --rev 2.18 --keep-archive --keep-backup
|
| 415 |
+
```
|
| 416 |
+
|
| 417 |
### Issue: Metadata extraction fails for a treebank
|
| 418 |
|
| 419 |
**Problem:** A treebank is malformed or missing expected files.
|
tools/00_fetch_ud_clarin-dspace_metadata.py
CHANGED
|
@@ -32,23 +32,24 @@ handle_redirect_url_prefix = "https://lindat.mff.cuni.cz/repository/items/"
|
|
| 32 |
outfile_pathprefix = "./etc/"
|
| 33 |
citation_outfile_name = "citation-{rev}"
|
| 34 |
description_outfile_name = "description-{rev}"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
"
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
# Parse command line arguments
|
| 54 |
parser = argparse.ArgumentParser(description=__doc__,
|
|
@@ -66,6 +67,12 @@ logging.basicConfig(
|
|
| 66 |
datefmt='%Y-%m-%d %H:%M:%S'
|
| 67 |
)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# Iterate over the URL postfixes
|
| 70 |
for rev,handle in url_postfixes.items():
|
| 71 |
|
|
|
|
| 32 |
outfile_pathprefix = "./etc/"
|
| 33 |
citation_outfile_name = "citation-{rev}"
|
| 34 |
description_outfile_name = "description-{rev}"
|
| 35 |
+
release_handle_map_file = Path(__file__).parent / "etc" / "ud_release_handles.tsv"
|
| 36 |
+
|
| 37 |
+
def load_release_handles(path: Path) -> dict[str, str]:
|
| 38 |
+
"""
|
| 39 |
+
Load the UD-version -> LINDAT handle mapping from a TSV file.
|
| 40 |
+
"""
|
| 41 |
+
mapping: dict[str, str] = {}
|
| 42 |
+
with path.open("r", encoding="utf-8") as fh:
|
| 43 |
+
for lineno, raw_line in enumerate(fh, start=1):
|
| 44 |
+
line = raw_line.strip()
|
| 45 |
+
if not line or line.startswith("#"):
|
| 46 |
+
continue
|
| 47 |
+
fields = line.split()
|
| 48 |
+
if len(fields) != 2:
|
| 49 |
+
raise ValueError(f"Invalid mapping format at {path}:{lineno}: {raw_line.rstrip()}")
|
| 50 |
+
rev, handle = fields
|
| 51 |
+
mapping[rev] = handle
|
| 52 |
+
return mapping
|
| 53 |
|
| 54 |
# Parse command line arguments
|
| 55 |
parser = argparse.ArgumentParser(description=__doc__,
|
|
|
|
| 67 |
datefmt='%Y-%m-%d %H:%M:%S'
|
| 68 |
)
|
| 69 |
|
| 70 |
+
# Load version -> handle mapping
|
| 71 |
+
try:
|
| 72 |
+
url_postfixes = load_release_handles(release_handle_map_file)
|
| 73 |
+
except (OSError, ValueError) as e:
|
| 74 |
+
raise SystemExit(f"Failed to load release-handle mapping from {release_handle_map_file}: {e}")
|
| 75 |
+
|
| 76 |
# Iterate over the URL postfixes
|
| 77 |
for rev,handle in url_postfixes.items():
|
| 78 |
|
tools/01_fetch_ud_snapshot.sh
CHANGED
|
@@ -12,23 +12,12 @@ set -euo pipefail
|
|
| 12 |
[ -e .env ] && . .env
|
| 13 |
|
| 14 |
ONLINE_MODE=false
|
|
|
|
|
|
|
| 15 |
UD_VER=${UD_VER:-"2.17"}
|
| 16 |
UDS_SUBDIR="UD_repos"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Keep this in sync with tools/00_fetch_ud_clarin-dspace_metadata.py.
|
| 20 |
-
declare -A HANDLE_MAPPING
|
| 21 |
-
HANDLE_MAPPING["2.7"]="11234/1-3424"
|
| 22 |
-
HANDLE_MAPPING["2.8"]="11234/1-3687"
|
| 23 |
-
HANDLE_MAPPING["2.9"]="11234/1-4611"
|
| 24 |
-
HANDLE_MAPPING["2.10"]="11234/1-4758"
|
| 25 |
-
HANDLE_MAPPING["2.11"]="11234/1-4923"
|
| 26 |
-
HANDLE_MAPPING["2.12"]="11234/1-5150"
|
| 27 |
-
HANDLE_MAPPING["2.13"]="11234/1-5287"
|
| 28 |
-
HANDLE_MAPPING["2.14"]="11234/1-5502"
|
| 29 |
-
HANDLE_MAPPING["2.15"]="11234/1-5787"
|
| 30 |
-
HANDLE_MAPPING["2.16"]="11234/1-5901"
|
| 31 |
-
HANDLE_MAPPING["2.17"]="11234/1-6036"
|
| 32 |
|
| 33 |
###################
|
| 34 |
#############
|
|
@@ -36,7 +25,7 @@ HANDLE_MAPPING["2.17"]="11234/1-6036"
|
|
| 36 |
# USAGE
|
| 37 |
#
|
| 38 |
usage() { OUTPUT=${1:-"verbose"}
|
| 39 |
-
echo "Usage: $0 [-o] [-r VER]" >&2
|
| 40 |
[ "$OUTPUT" = "short" ] && exit 0
|
| 41 |
>&2 cat << EOF
|
| 42 |
|
|
@@ -56,6 +45,8 @@ Options:
|
|
| 56 |
-h Print this help message
|
| 57 |
-o|--online Force re-download and re-extract
|
| 58 |
-r|--rev VER UD version to fetch (default: \${UD_VER} from .env)
|
|
|
|
|
|
|
| 59 |
EOF
|
| 60 |
}
|
| 61 |
#
|
|
@@ -63,7 +54,7 @@ EOF
|
|
| 63 |
############
|
| 64 |
##################
|
| 65 |
|
| 66 |
-
VALID_ARGS=$(getopt -o hor: --long help,online,rev: -- "$@")
|
| 67 |
if [[ $? -ne 0 ]]; then
|
| 68 |
usage "short"
|
| 69 |
exit 1
|
|
@@ -75,16 +66,31 @@ do
|
|
| 75 |
case "$1" in
|
| 76 |
-o | --online) ONLINE_MODE=true; shift ;;
|
| 77 |
-r | --rev) UD_VER="$2"; shift 2 ;;
|
|
|
|
|
|
|
| 78 |
-h | --help) usage; shift ; exit 0 ;;
|
| 79 |
--) shift ; break ;;
|
| 80 |
*) >&2 echo "Unsupported option: $1"; usage; exit 1 ;;
|
| 81 |
esac
|
| 82 |
done
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
if [[ -z "${HANDLE}" ]]; then
|
| 86 |
>&2 echo "Unsupported UD version: ${UD_VER}"
|
| 87 |
-
>&2 echo "Update
|
| 88 |
exit 1
|
| 89 |
fi
|
| 90 |
|
|
@@ -133,9 +139,14 @@ PY
|
|
| 133 |
fi
|
| 134 |
|
| 135 |
if [[ -d "${SNAPSHOT_DIR}" ]]; then
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
fi
|
| 140 |
|
| 141 |
mv "${snapshot_candidates[0]}" "${SNAPSHOT_DIR}"
|
|
@@ -153,6 +164,11 @@ else
|
|
| 153 |
echo "Snapshot directory already exists: ${SNAPSHOT_DIR}"
|
| 154 |
fi
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
if [[ -L "${UDS_SUBDIR}" ]]; then
|
| 157 |
ln -sfn "${SNAPSHOT_DIR}" "${UDS_SUBDIR}"
|
| 158 |
elif [[ ! -e "${UDS_SUBDIR}" ]]; then
|
|
|
|
| 12 |
[ -e .env ] && . .env
|
| 13 |
|
| 14 |
ONLINE_MODE=false
|
| 15 |
+
KEEP_ARCHIVE=false
|
| 16 |
+
KEEP_BACKUP=false
|
| 17 |
UD_VER=${UD_VER:-"2.17"}
|
| 18 |
UDS_SUBDIR="UD_repos"
|
| 19 |
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 20 |
+
HANDLE_MAP_FILE="${SCRIPT_DIR}/etc/ud_release_handles.tsv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
###################
|
| 23 |
#############
|
|
|
|
| 25 |
# USAGE
|
| 26 |
#
|
| 27 |
usage() { OUTPUT=${1:-"verbose"}
|
| 28 |
+
echo "Usage: $0 [-o] [-r VER] [--keep-archive] [--keep-backup]" >&2
|
| 29 |
[ "$OUTPUT" = "short" ] && exit 0
|
| 30 |
>&2 cat << EOF
|
| 31 |
|
|
|
|
| 45 |
-h Print this help message
|
| 46 |
-o|--online Force re-download and re-extract
|
| 47 |
-r|--rev VER UD version to fetch (default: \${UD_VER} from .env)
|
| 48 |
+
--keep-archive Keep downloaded zip archive after extraction
|
| 49 |
+
--keep-backup Keep existing snapshot directory as timestamped backup
|
| 50 |
EOF
|
| 51 |
}
|
| 52 |
#
|
|
|
|
| 54 |
############
|
| 55 |
##################
|
| 56 |
|
| 57 |
+
VALID_ARGS=$(getopt -o hor: --long help,online,rev:,keep-archive,keep-backup -- "$@")
|
| 58 |
if [[ $? -ne 0 ]]; then
|
| 59 |
usage "short"
|
| 60 |
exit 1
|
|
|
|
| 66 |
case "$1" in
|
| 67 |
-o | --online) ONLINE_MODE=true; shift ;;
|
| 68 |
-r | --rev) UD_VER="$2"; shift 2 ;;
|
| 69 |
+
--keep-archive) KEEP_ARCHIVE=true; shift ;;
|
| 70 |
+
--keep-backup) KEEP_BACKUP=true; shift ;;
|
| 71 |
-h | --help) usage; shift ; exit 0 ;;
|
| 72 |
--) shift ; break ;;
|
| 73 |
*) >&2 echo "Unsupported option: $1"; usage; exit 1 ;;
|
| 74 |
esac
|
| 75 |
done
|
| 76 |
|
| 77 |
+
if [[ ! -r "${HANDLE_MAP_FILE}" ]]; then
|
| 78 |
+
>&2 echo "Missing handle mapping file: ${HANDLE_MAP_FILE}"
|
| 79 |
+
exit 1
|
| 80 |
+
fi
|
| 81 |
+
|
| 82 |
+
HANDLE="$(
|
| 83 |
+
awk -v ver="${UD_VER}" '
|
| 84 |
+
BEGIN { FS="[[:space:]]+" }
|
| 85 |
+
/^[[:space:]]*#/ { next }
|
| 86 |
+
NF < 2 { next }
|
| 87 |
+
$1 == ver { print $2; exit }
|
| 88 |
+
' "${HANDLE_MAP_FILE}"
|
| 89 |
+
)"
|
| 90 |
+
|
| 91 |
if [[ -z "${HANDLE}" ]]; then
|
| 92 |
>&2 echo "Unsupported UD version: ${UD_VER}"
|
| 93 |
+
>&2 echo "Update ${HANDLE_MAP_FILE} first."
|
| 94 |
exit 1
|
| 95 |
fi
|
| 96 |
|
|
|
|
| 139 |
fi
|
| 140 |
|
| 141 |
if [[ -d "${SNAPSHOT_DIR}" ]]; then
|
| 142 |
+
if [[ "${KEEP_BACKUP}" == true ]]; then
|
| 143 |
+
backup_dir="${SNAPSHOT_DIR}.bak.$(date +%s)"
|
| 144 |
+
echo "Existing ${SNAPSHOT_DIR} found; moving it to ${backup_dir}"
|
| 145 |
+
mv "${SNAPSHOT_DIR}" "${backup_dir}"
|
| 146 |
+
else
|
| 147 |
+
echo "Existing ${SNAPSHOT_DIR} found; removing it"
|
| 148 |
+
rm -rf "${SNAPSHOT_DIR}"
|
| 149 |
+
fi
|
| 150 |
fi
|
| 151 |
|
| 152 |
mv "${snapshot_candidates[0]}" "${SNAPSHOT_DIR}"
|
|
|
|
| 164 |
echo "Snapshot directory already exists: ${SNAPSHOT_DIR}"
|
| 165 |
fi
|
| 166 |
|
| 167 |
+
if [[ "${KEEP_ARCHIVE}" != true ]] && [[ -f "${SNAPSHOT_ARCHIVE}" ]]; then
|
| 168 |
+
echo "Removing archive ${SNAPSHOT_ARCHIVE}"
|
| 169 |
+
rm -f "${SNAPSHOT_ARCHIVE}"
|
| 170 |
+
fi
|
| 171 |
+
|
| 172 |
if [[ -L "${UDS_SUBDIR}" ]]; then
|
| 173 |
ln -sfn "${SNAPSHOT_DIR}" "${UDS_SUBDIR}"
|
| 174 |
elif [[ ! -e "${UDS_SUBDIR}" ]]; then
|
tools/02_generate_metadata.py
CHANGED
|
@@ -282,7 +282,9 @@ if __name__ == '__main__':
|
|
| 282 |
|
| 283 |
# Write the metadata to json
|
| 284 |
output_fn = f"metadata-{UD_VER}.json"
|
| 285 |
-
|
|
|
|
|
|
|
| 286 |
with open(output_fn, 'w') as fh:
|
| 287 |
json.dump(results, fh, ensure_ascii=False, sort_keys=True,
|
| 288 |
indent=4, separators=(',', ': '))
|
|
|
|
| 282 |
|
| 283 |
# Write the metadata to json
|
| 284 |
output_fn = f"metadata-{UD_VER}.json"
|
| 285 |
+
output_path = Path(output_fn)
|
| 286 |
+
should_write = args.override or (not output_path.exists()) or output_path.stat().st_size == 0
|
| 287 |
+
if should_write:
|
| 288 |
with open(output_fn, 'w') as fh:
|
| 289 |
json.dump(results, fh, ensure_ascii=False, sort_keys=True,
|
| 290 |
indent=4, separators=(',', ': '))
|
tools/README.md
CHANGED
|
@@ -36,7 +36,7 @@ git add ../parquet ../README.md ../metadata.json
|
|
| 36 |
**00_fetch_ud_clarin-dspace_metadata.py**
|
| 37 |
- Downloads citation and description from LINDAT/CLARIN repository
|
| 38 |
- Creates: `etc/citation-{VER}`, `etc/description-{VER}`
|
| 39 |
-
-
|
| 40 |
|
| 41 |
**00_fetch_ud_codes_and_flags.sh**
|
| 42 |
- Downloads language codes and flags from UD docs-automation
|
|
@@ -49,6 +49,7 @@ git add ../parquet ../README.md ../metadata.json
|
|
| 49 |
- Downloads official UD release snapshot from LINDAT/CLARIN (`allzip`)
|
| 50 |
- Creates: `ud-treebanks-v{VER}/`
|
| 51 |
- Creates/updates symlink: `UD_repos -> ud-treebanks-v{VER}`
|
|
|
|
| 52 |
|
| 53 |
### 02 - Generate Metadata
|
| 54 |
|
|
@@ -95,7 +96,8 @@ tools/
|
|
| 95 |
├── etc/
|
| 96 |
│ ├── citation-{VER} # Generated citations
|
| 97 |
│ ├── description-{VER} # Generated descriptions
|
| 98 |
-
│
|
|
|
|
| 99 |
├── templates/
|
| 100 |
│ └── README.tmpl # Jinja2 template for dataset card
|
| 101 |
├── metadata-{VER}.json # Generated metadata (output)
|
|
@@ -167,6 +169,15 @@ pip install ud-hf-parquet-tools
|
|
| 167 |
./01_fetch_ud_snapshot.sh --online --rev 2.17
|
| 168 |
```
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
## Documentation
|
| 171 |
|
| 172 |
- **Comprehensive guide:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md)
|
|
|
|
| 36 |
**00_fetch_ud_clarin-dspace_metadata.py**
|
| 37 |
- Downloads citation and description from LINDAT/CLARIN repository
|
| 38 |
- Creates: `etc/citation-{VER}`, `etc/description-{VER}`
|
| 39 |
+
- Uses: `etc/ud_release_handles.tsv` for version -> handle mapping
|
| 40 |
|
| 41 |
**00_fetch_ud_codes_and_flags.sh**
|
| 42 |
- Downloads language codes and flags from UD docs-automation
|
|
|
|
| 49 |
- Downloads official UD release snapshot from LINDAT/CLARIN (`allzip`)
|
| 50 |
- Creates: `ud-treebanks-v{VER}/`
|
| 51 |
- Creates/updates symlink: `UD_repos -> ud-treebanks-v{VER}`
|
| 52 |
+
- Options: `--online`, `--keep-archive`, `--keep-backup`
|
| 53 |
|
| 54 |
### 02 - Generate Metadata
|
| 55 |
|
|
|
|
| 96 |
├── etc/
|
| 97 |
│ ├── citation-{VER} # Generated citations
|
| 98 |
│ ├── description-{VER} # Generated descriptions
|
| 99 |
+
│ ├── codes_and_flags-{VER}.yaml # Language metadata
|
| 100 |
+
│ └── ud_release_handles.tsv # UD version -> CLARIN handle mapping
|
| 101 |
├── templates/
|
| 102 |
│ └── README.tmpl # Jinja2 template for dataset card
|
| 103 |
├── metadata-{VER}.json # Generated metadata (output)
|
|
|
|
| 169 |
./01_fetch_ud_snapshot.sh --online --rev 2.17
|
| 170 |
```
|
| 171 |
|
| 172 |
+
**Disk usage after repeated snapshot refreshes:**
|
| 173 |
+
```bash
|
| 174 |
+
# Default behavior deletes archive and replaces old snapshot directory
|
| 175 |
+
./01_fetch_ud_snapshot.sh --online --rev 2.17
|
| 176 |
+
|
| 177 |
+
# Keep archive and timestamped backup only when needed
|
| 178 |
+
./01_fetch_ud_snapshot.sh --online --rev 2.17 --keep-archive --keep-backup
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
## Documentation
|
| 182 |
|
| 183 |
- **Comprehensive guide:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md)
|
tools/etc/ud_release_handles.tsv
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# UD version to LINDAT/CLARIN handle mapping
|
| 2 |
+
# Format: <ud_version><whitespace><handle>
|
| 3 |
+
2.7 11234/1-3424
|
| 4 |
+
2.8 11234/1-3687
|
| 5 |
+
2.9 11234/1-4611
|
| 6 |
+
2.10 11234/1-4758
|
| 7 |
+
2.11 11234/1-4923
|
| 8 |
+
2.12 11234/1-5150
|
| 9 |
+
2.13 11234/1-5287
|
| 10 |
+
2.14 11234/1-5502
|
| 11 |
+
2.15 11234/1-5787
|
| 12 |
+
2.16 11234/1-5901
|
| 13 |
+
2.17 11234/1-6036
|