Looking for PGN sorting but in order of my choice

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
PaulieD
Posts: 205
Joined: Tue Jun 25, 2013 6:19 pm

Looking for PGN sorting but in order of my choice

Post by PaulieD » Sun Jan 18, 2015 1:55 am

I am looking to sort some PGN databases I have in ECO order.
A,B,C,D,E
So Game 1 would be A
Game 2 would be B
Then keep repeating that order through the balance of the database.
Is there an automated way to just set a tool that could do that automatically?

I have done 500 games by hand in Chessbase and it gets old very fast.

Ferdy
Posts: 4051
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Looking for PGN sorting but in order of my choice

Post by Ferdy » Sun Jan 18, 2015 2:42 am

PaulieD wrote:I am looking to sort some PGN databases I have in ECO order.
A,B,C,D,E
So Game 1 would be A
Game 2 would be B
Then keep repeating that order through the balance of the database.
Is there an automated way to just set a tool that could do that automatically?

I have done 500 games by hand in Chessbase and it gets old very fast.
A combination of dos commands using pgn-extract can do this. Copy paste and save as a batch file, say eco-sort.bat
The src.pgn is your pgn file, the option -E3 will extract A00, A01, up to E99. You can use E4, to get finer classification, like A00a, A01b, but I have not tried it. It depends on the eco codes found in games.

I have tried this in windows 7, and it worked. You need pgn-extract program of course.

eco_sort.bat

Code: Select all

:: Extract games by eco
pgn-extract-17-14 -E3 src.pgn

:: rename src.pgn to src.npgn
rename src.pgn src.npgn

:: combine the generated pgn files
copy *.pgn final.pgn

:: rename the final.pgn to final.npgn
rename final.pgn final.npgn

:: delete the a00.pgn, a01.pgn ... e99.pgn files
:: be sure you don't have other pgn files in this directory
:: because it will be deleted too.
del *.pgn

:: rename back the final.pgn
rename final.npgn final.pgn

:: rename back the src.pgn
rename src.npgn src.pgn

echo done!!

PaulieD
Posts: 205
Joined: Tue Jun 25, 2013 6:19 pm

Re: Looking for PGN sorting but in order of my choice

Post by PaulieD » Sun Jan 18, 2015 3:01 am

What happened is it put them in all A00 then all A01 and so on
I should have been more specific possibly.
Game 1 any A Eco code
Game 2 any B Eco code
Game 3 any C Eco code

It was quick I hope that file can be modified to accomplish my request.
Many Thanks.

Edit:
I tried the E1 switch and all it did was jumble all the A's to the top of the pgn.

Ferdy
Posts: 4051
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Looking for PGN sorting but in order of my choice

Post by Ferdy » Sun Jan 18, 2015 4:18 am

PaulieD wrote:What happened is it put them in all A00 then all A01 and so on
I should have been more specific possibly.
Game 1 any A Eco code
Game 2 any B Eco code
Game 3 any C Eco code

It was quick I hope that file can be modified to accomplish my request.
Many Thanks.

Edit:
I tried the E1 switch and all it did was jumble all the A's to the top of the pgn.
I think I misunderstand what you wanted.

Can you give an example? I cannot understand game 1 and game 2 and game 3. How many files are your original files? Do you want game1.pgn all contains "A" eco codes?, game2.pgn contains "B" eco codes? What is your expected output? Can you give an example?

Adam Hair
Posts: 3201
Joined: Wed May 06, 2009 8:31 pm
Location: Fuquay-Varina, North Carolina

Re: Looking for PGN sorting but in order of my choice

Post by Adam Hair » Sun Jan 18, 2015 10:01 am

I think what Paul means is that he wants to order the games in his source pgn so that games 1, 6, 11, ... are eco code A, games 2, 7, 12, ... are eco B, ..., and games 5, 10, 15, .... are eco code E.

I think I have the means of doing this using pgn extract, some of Norm Pollock's tools, Unix commands, and an unreleased version of Gaviota that can match a position in an epd file to a game containing that position. It would be a convoluted process, but it might work okay.

PaulieD
Posts: 205
Joined: Tue Jun 25, 2013 6:19 pm

Re: Looking for PGN sorting but in order of my choice

Post by PaulieD » Sun Jan 18, 2015 11:28 am

Yes!
What Adam is saying here is correct. The databases are 5-10,000 games long.
In sequential order, as looking into a chessbase viewer the first game or game number 1 would also be eco code A, game 2 scrolling down would be eco code B and so on...game 6 A again, Game 7 B again.
When finished I should see in the database window
1.A
2.B
3.C
4.D
5.E
This would continue through the whole database.
Of course all the other pgn header information would be there also.
Thanks for your attention in this matter.
Here is a pic of what I am seeking:

Image

Norm Pollock
Posts: 1017
Joined: Thu Mar 09, 2006 3:15 pm
Location: Long Island, NY, USA
Contact:

Re: Looking for PGN sorting but in order of my choice

Post by Norm Pollock » Sun Jan 18, 2015 8:30 pm

Before

https://www.dropbox.com/s/ru0k32xh2yrtt ... 30.7z?dl=0

After

https://www.dropbox.com/s/e44yhauw2ezn5 ... lt.7z?dl=0


The number of games with ECO's A,B,C,D,E were different
Number of ECOs = 15363 A: 1687 B: 1750 C: 7736 D: 3601 E: 589

So when there are no more E games for example, the games will be output among A,B,C,D. Then when there are no more A games, the games will be output among B,C,D. And so on.

I limited the number of games for any ECO starting letter to 10000 games. Therefore my strategy can only work to a max of 50000 games where there are equal number of games for each starting letter. I don't know how far I can stretch the max. Right now I want to see if it meets the specs.

PaulieD
Posts: 205
Joined: Tue Jun 25, 2013 6:19 pm

Re: Looking for PGN sorting but in order of my choice

Post by PaulieD » Sun Jan 18, 2015 10:34 pm

Wow,
Norm that is nice. Wish it was mine!
Could you have sorted a wider variety of numbers within each ECO code like my diagram above...

Can you show me how to do it to my pgn?

Norm Pollock
Posts: 1017
Joined: Thu Mar 09, 2006 3:15 pm
Location: Long Island, NY, USA
Contact:

Re: Looking for PGN sorting but in order of my choice

Post by Norm Pollock » Sun Jan 18, 2015 11:15 pm

PaulieD wrote:Wow,
Norm that is nice. Wish it was mine!
Could you have sorted a wider variety of numbers within each ECO code like my diagram above...

Can you show me how to do it to my pgn?
The strategy is quite complex and uses quite a few tricks with DOS commands. Basically I created a file for EACH game by modifying an existing tool that I had written. Each game was contained within its own file. Then I renamed the files so that when I copied them together they would be copied in the sorted order you specified. I don't know how large I could go. If you have a million game file, I would need a million files. Maybe I could break it down into sections.

If you want, you could send me your pgn file by uploading it to dropbox or wherever, and posting the link, and I could work on it.

PaulieD
Posts: 205
Joined: Tue Jun 25, 2013 6:19 pm

Re: Looking for PGN sorting but in order of my choice

Post by PaulieD » Sun Jan 18, 2015 11:28 pm

Thank you Norm,

Here is my 5000 games pgn. I am not sure if there are exactly 1000 of each ECO code, probably not.

The first 500 games were sorted in order, by hand, and is the one pictured further back in the thread.

https://www.mediafire.com/?59vj2u2at6aure1

Post Reply