ontocast.cli.batch_process¶
Batch processing client for OntoCast.
This module provides a command-line client for batch processing multiple files through the OntoCast API server. It supports async processing with configurable concurrency limits.
The client supports: - Recursive directory scanning - File pattern matching (e.g., by extension) - Async processing with concurrency control - Progress tracking and error reporting - JSON and PDF file types
Example
Process all JSON files in a directory (max 3 concurrent)¶
python batch_process.py --url http://localhost:8999 --path ./data --pattern "*.json" --max-concurrent 3
Process all PDF files recursively¶
python batch_process.py --url http://localhost:8999 --path ./documents --pattern "*.pdf" --recursive
find_files(path, pattern, recursive)
¶
Find files matching the given pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Base path to search |
required |
pattern
|
Optional[str]
|
Glob pattern (e.g., ".json", ".pdf") or None for all files |
required |
recursive
|
bool
|
Whether to search recursively |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of matching file paths |
Source code in ontocast/cli/batch_process.py
main(url, path, pattern, recursive, max_concurrent, output, dataset)
¶
Batch process files through the OntoCast API server.
This command finds files matching the given pattern (or all supported files) and sends them to the OntoCast API server for processing. Files are processed asynchronously with a configurable concurrency limit.
Supported file types: .json, .pdf
Examples:
Process all JSON files in a directory¶
batch_process.py --url http://localhost:8999 --path ./data --pattern "*.json"
Process all PDFs recursively with 5 concurrent requests¶
batch_process.py --url http://localhost:8999 --path ./documents --pattern "*.pdf" --recursive --max-concurrent 5
Process files into a specific dataset¶
batch_process.py --url http://localhost:8999 --path ./data --pattern "*.json" --dataset my_dataset
Process a single file¶
batch_process.py --url http://localhost:8999 --path ./document.pdf
Source code in ontocast/cli/batch_process.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
process_file(client, url, file_path, semaphore, results, dataset=None)
async
¶
Process a single file by sending it to the OntoCast API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncClient
|
httpx async client |
required |
url
|
str
|
API endpoint URL |
required |
file_path
|
Path
|
Path to the file to process |
required |
semaphore
|
Semaphore
|
Semaphore to limit concurrent requests |
required |
results
|
dict
|
Dictionary to store results (success/error counts) |
required |
dataset
|
Optional[str]
|
Optional dataset name for triple store storage |
None
|
Source code in ontocast/cli/batch_process.py
process_files_async(url, file_paths, max_concurrent, dataset=None)
async
¶
Process multiple files asynchronously with concurrency control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
API endpoint URL |
required |
file_paths
|
list[Path]
|
List of file paths to process |
required |
max_concurrent
|
int
|
Maximum number of concurrent requests |
required |
dataset
|
Optional[str]
|
Optional dataset name for triple store storage |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with processing results (success count, error count, details) |