File size: 5,731 Bytes
c8f1b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# tools/ Directory

Quick reference for the Universal Dependencies dataset generation pipeline.

## Quick Start: Add New UD Version

```bash
# Set version
export NEW_VER=2.18
cd tools
echo "UD_VER=${NEW_VER}" > .env

# Fetch metadata
./00_fetch_ud_clarin-dspace_metadata.py -o
./00_fetch_ud_codes_and_flags.sh -o
./01_fetch_ud_repos.sh

# Initialize repositories
cd UD_repos
git init
bash ../.UD_submodules_add.commands
git submodule foreach "git fetch --tags && git checkout r${NEW_VER} && touch .tag-r${NEW_VER}"
cd ..

# Generate files
./02_generate_metadata.py -o
./03_generate_README.py -o
uv run ./04_generate_parquet.py
uv run ./05_validate_parquet.py --local --test

# Sync to root
cp README-${NEW_VER} ../README.md
cp metadata-${NEW_VER}.json ../metadata.json
git add ../parquet ../README.md ../metadata.json
```

**For detailed instructions, see:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md)

## Pipeline Scripts

### 00 - Fetch Metadata

**00_fetch_ud_clarin-dspace_metadata.py**
- Downloads citation and description from LINDAT/CLARIN repository
- Creates: `etc/citation-{VER}`, `etc/description-{VER}`
- Update `url_postfixes` dict for new versions

**00_fetch_ud_codes_and_flags.sh**
- Downloads language codes and flags from UD docs-automation
- Creates: `etc/codes_and_flags-{VER}.yaml`, `etc/codes_and_flags-latest.yaml`
- Update `VER_MAPPING` for new versions

### 01 - Fetch Repositories

**01_fetch_ud_repos.sh**
- Discovers all UD repositories on GitHub
- Creates: `.UD_submodules_add.commands`
- Run commands in `UD_repos/` directory to fetch all treebanks

### 02 - Generate Metadata

**02_generate_metadata.py**
- Extracts metadata from local UD directories
- Collects: summaries, licenses, splits, statistics, blocked status
- Creates: `metadata-{VER}.json`
- Reads: `blocked_treebanks.yaml` for license restrictions

### 03 - Generate README

**03_generate_README.py**
- Renders Jinja2 template with metadata
- Creates: `README-{VER}` (HuggingFace dataset card)
- Uses: `templates/README.tmpl`, `metadata-{VER}.json`, `etc/citation-{VER}`, `etc/description-{VER}`

### 04 - Generate Parquet

**04_generate_parquet.py**
- Wrapper script calling `ud-hf-parquet-tools` library
- Converts CoNLL-U files to Parquet format
- Creates: `../parquet/{treebank}/{split}.parquet`
- Options: `--test`, `--overwrite`, `--blocked-treebanks`

### 05 - Validate Parquet

**05_validate_parquet.py**
- Wrapper script calling `ud-hf-parquet-tools` library
- Validates Parquet files against CoNLL-U source
- Options: `--local`, `--test`, `--mode text`

## Directory Structure

```
tools/
├── 00_fetch_ud_clarin-dspace_metadata.py   # Fetch citation/description
├── 00_fetch_ud_codes_and_flags.sh          # Fetch language metadata
├── 01_fetch_ud_repos.sh                    # Discover UD repos
├── 02_generate_metadata.py                 # Extract treebank metadata
├── 03_generate_README.py                   # Generate dataset card
├── 04_generate_parquet.py                  # Generate Parquet files
├── 05_validate_parquet.py                  # Validate Parquet files
├── blocked_treebanks.yaml                  # License-restricted treebanks
├── etc/
│   ├── citation-{VER}                      # Generated citations
│   ├── description-{VER}                   # Generated descriptions
│   └── codes_and_flags-{VER}.yaml          # Language metadata
├── templates/
│   └── README.tmpl                         # Jinja2 template for dataset card
├── metadata-{VER}.json                     # Generated metadata (output)
├── README-{VER}                            # Generated dataset card (output)
└── UD_repos/                               # Git submodules (created by 01)
    ├── UD_{Language}-{Treebank}/           # Individual treebanks
    └── .UD_submodules_add.commands         # Generated submodule commands
```

## Configuration

**Environment Variables (.env)**
```bash
UD_VER=2.17  # Current UD version
```

**Blocked Treebanks (blocked_treebanks.yaml)**
```yaml
pt_cintil:
  reason: "Restrictive license prohibits redistribution in derived formats"
  license: "CC BY-NC-SA 4.0"
  url: "https://github.com/UniversalDependencies/UD_Portuguese-CINTIL"
```

## Dependencies

- Python 3.12+
- `uv` (for running scripts with dependencies)
- `ud-hf-parquet-tools` (for parquet generation/validation)
- Git with submodules support

Install dependencies:
```bash
pip install ud-hf-parquet-tools pyyaml python-dotenv jinja2
```

## Common Operations

**Test on subset:**
```bash
uv run ./04_generate_parquet.py --test  # Tests 3 treebanks
uv run ./05_validate_parquet.py --test  # Validates 3 treebanks
```

**Force regeneration:**
```bash
./02_generate_metadata.py -o            # Override existing
./03_generate_README.py -o
uv run ./04_generate_parquet.py --overwrite
```

**Skip blocked treebanks:**
```bash
uv run ./04_generate_parquet.py --blocked-treebanks blocked_treebanks.yaml
```

## Troubleshooting

**Script not found:**
- Scripts use `#!/usr/bin/env -S uv run --script` shebang
- Make executable: `chmod +x *.py *.sh`
- Or run with: `uv run --script ./script.py`

**Missing dependencies:**
```bash
pip install ud-hf-parquet-tools
```

**Submodule checkout fails:**
```bash
cd UD_repos
git submodule foreach 'git fetch --tags && (git checkout r2.17 || git checkout main)'
```

## Documentation

- **Comprehensive guide:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md)
- **Blocked treebanks:** [BLOCKED_TREEBANKS.md](BLOCKED_TREEBANKS.md)
- **Migration guide:** [MIGRATION.md](../MIGRATION.md)
- **Parquet tools:** https://github.com/bot-zen/ud-hf-parquet-tools