pgn_chunks.pl

 pgn_chunks(+OptsAndPgns)
Chop a number of PGN files to a number of chunks, each contain a max number of games.

The last chunk will contain less than the max number. Each PGN is chunkified on its own, files are not strewn together before chunkified. Input PGNs can be given as pgn(PGNo) options or as atomic options.

Opts

debug(Dbg=true)
informational, progress messages
games(NoGames=50000)
number of games in each chunk
help(Help=false)
help messsage and exit
order(Order=sort)
or one of atoms,pgns for giving priority
pgn(PgnF)
PGN file to chunkify (multiple are allowed)
stack_limit(Slm=false)
set the stack_limit prolog flag (set integer which will be translated to Gigabytes)
usage(Usg=false)
usage message and exit

Following example will chunkify file1.pgn, file2.pgn, file3.pgn and file4 (which has no filename extension).

?- pgn_chunks([pgn(file1),file2,file3.pgn,file4]).

To test, you can use the PGN files that are distributed as examples with pack(chess_db).

Command line via pack(upsh).


> upsh pgn_chunks usage=true

> upsh pgn_chunks ../data/pgns/18.03-candidates.pgn games=10
% Writing on: '../data/pgn/18.03-candidates_cnk1.pgn'
% Writing on: '../data/pgn/18.03-candidates_cnk2.pgn'
% Writing on: '../data/pgn/18.03-candidates_cnk3.pgn'
% Writing on: '../data/pgn/18.03-candidates_cnk4.pgn'
% Writing on: '../data/pgn/18.03-candidates_cnk5.pgn'
% Writing on: '../data/pgn/18.03-candidates_cnk6.pgn'

> ls -l ../data/pgns/18*cnk*
-rw-r--r-- 1 nicos nicos 7349 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk1.pgn
-rw-r--r-- 1 nicos nicos 7446 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk2.pgn
-rw-r--r-- 1 nicos nicos 8396 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk3.pgn
-rw-r--r-- 1 nicos nicos 7170 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk4.pgn
-rw-r--r-- 1 nicos nicos 8525 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk5.pgn
-rw-r--r-- 1 nicos nicos 4488 Jan 31 13:09 ../data/pgn/18.03-candidates_cnk6.pgn
> u pgn_chunks.pl lichess_elite_2023-01.pgn stack_limit=12
> u pgn_chunks.pl lichess_elite_2023-02.pgn stack_limit=8
% Setting stack limit to: 8000000000
% Option selected: games(100000).
% Starting enumeration of list: inputs
% 1.lichess_elite_2023-02.pgn
% Ended enumeration of list: inputs
% Doing: lichess_elite_2023-02.pgn
% Length of sections: 535014
% Parts: 3
% Writing on: 'lichess_elite_2023-02_cnk1.pgn'
% Writing on: 'lichess_elite_2023-02_cnk2.pgn'
% Writing on: 'lichess_elite_2023-02_cnk3.pgn'
% Finished: pgn_chunks
author
- nicos angelopoulos
version
- 0.1 2026/01/30
See also
- SWI-Prolog packs at: https://eu.swi-prolog.org/pack/list