create account

Seed a SQL Database with PGN Games by programarivm

View this thread on: hive.blogpeakd.comecency.com
· @programarivm · (edited)
$28.40
Seed a SQL Database with PGN Games
### Repository

https://github.com/programarivm/pgn-chess

![eer-database.jpg](https://cdn.steemitimages.com/DQmSZXHw9vKjUhbeNMM6NzVkEyTsLYgsqxQR4F7Ecwg2RAV/eer-database.jpg)

PGN Chess is a simple, friendly, and powerful PGN (Portable Game Notation) library for running chess games from within PHP applications. It is a chess board representation that can be used in chess engines, chess applications and chess algorithms.

### New Features
[Feature/db seed #6](https://github.com/programarivm/pgn-chess/pull/6) is a new command that searches for valid games in a PGN file and seeds the PGN Chess database accordingly:

- `db-seed.php`

Example:

```
php db-seed.php Alekhine.pgn
This will search for valid PGN games in the file.
Large files (for example 50MB) may take a few seconds to be inserted into the database.
Do you want to proceed? (Y/N): y
Good! This is a valid PGN file. 3201 games were inserted into the database.
```

Now, you can get information from a particular player, Elo ranges, FIDE titles, or any other imaginable combination of properties as shown in the following example.

```
SELECT * FROM games WHERE White LIKE '%Alekhine%' AND Eco='C50';
```

> Remember: the games are syntactically valid.

This cool feature is intended to add knowledge/intelligence to the PGN Chess system in the medium term. For further information please visit section [4. Command Line Interface (CLI)](https://github.com/programarivm/pgn-chess#4-command-line-interface-cli)

### Technology Stack
- PHP 
- PDO
- MySQL

### Roadmap
The next thing to do is to write and share an amazing post on how to easily load tons of games into a chess database for multiple purposes! The feedback generated will help to spot bugs and improve the current features.

Who knows, perhaps at some point we could even use PGN Chess to create an open chess database as discussed at [Let's create a free, open, chess database](https://www.reddit.com/r/chess/comments/1559f8/lets_create_a_free_open_chess_database/). I already shared this roadmap on the Google+ community [Chess](https://plus.google.com/+Programarivm/posts/7eNXWrSJWSq).

Also, a database seeded with millions of chess games allows to train a machine learning model through a SQL interface as it is described next.

Command line: 

    php ml-train-naive-bayes.php naive-bayes.txt

PHP code:

```
use PGN\MachineLearning\NaiveBayesTrainer;

require_once __DIR__ . '/../../vendor/autoload.php';

(new NaiveBayesTrainer($argv[1]))->train('SELECT * FROM games');
``` 

### Would you help make this library better? 

Contributions are welcome.

- Feel free to send a pull request
- Drop an email at info@programarivm.com with the subject "PGN Chess Contributions"
- Leave me a comment on [Twitter](https://twitter.com/programarivm)
- Say hello on [Google+](https://plus.google.com/+Programarivm)

Many thanks.

### GitHub Account

https://github.com/programarivm
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorprogramarivm
permlinkseed-a-sql-database-with-pgn-games
categoryutopian-io
json_metadata{"tags":["utopian-io","development","chess","php"],"image":["https://cdn.steemitimages.com/DQmSZXHw9vKjUhbeNMM6NzVkEyTsLYgsqxQR4F7Ecwg2RAV/eer-database.jpg"],"links":["https://github.com/programarivm/pgn-chess","https://github.com/programarivm/pgn-chess/pull/6","https://github.com/programarivm/pgn-chess#4-command-line-interface-cli","https://www.reddit.com/r/chess/comments/1559f8/lets_create_a_free_open_chess_database/","https://plus.google.com/+Programarivm/posts/7eNXWrSJWSq","https://twitter.com/programarivm","https://plus.google.com/+Programarivm","https://github.com/programarivm"],"app":"steemit/0.1","format":"markdown"}
created2018-08-21 16:40:21
last_update2018-08-22 21:19:42
depth0
children6
last_payout2018-08-28 16:40:21
cashout_time1969-12-31 23:59:59
total_payout_value21.401 HBD
curator_payout_value6.995 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,904
author_reputation2,631,258,794,707
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id68,932,258
net_rshares20,668,164,471,715
author_curate_reward""
vote details (28)
@helo ·
$5.93
* Good use of try/catch, and object programming in general
* You have renamed many files, can you explain why?  ![](https://cdn.steemitimages.com/DQmdMjdA9MJt7YScFepuGxSmMJtNwFmZfqQijMtxE3tWHLM/image.png)



Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/3321112).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , ,
properties (23)
authorhelo
permlinkre-programarivm-seed-a-sql-database-with-pgn-games-20180822t162914965z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"image":["https://cdn.steemitimages.com/DQmdMjdA9MJt7YScFepuGxSmMJtNwFmZfqQijMtxE3tWHLM/image.png"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/3321112","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-08-22 16:29:15
last_update2018-08-22 16:29:15
depth1
children2
last_payout2018-08-29 16:29:15
cashout_time1969-12-31 23:59:59
total_payout_value4.473 HBD
curator_payout_value1.454 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length697
author_reputation121,547,934,535,311
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,034,436
net_rshares4,186,971,120,845
author_curate_reward""
vote details (7)
@programarivm · (edited)
$0.04
Hi @helo, thanks for your feedback. I believe those changes are okay, they are just a natural consequence of the refactoring process that is taking place -- by the way, I just pushed this [Documentation](https://pgn-chess.readthedocs.io/en/latest/). 

By following the convention `<object>-<action>` as in `db-create`the commands names are a bit more readable.
πŸ‘  
properties (23)
authorprogramarivm
permlinkre-helo-re-programarivm-seed-a-sql-database-with-pgn-games-20180822t181611698z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["helo"],"links":["https://pgn-chess.readthedocs.io/en/latest/"],"app":"steemit/0.1"}
created2018-08-22 18:16:12
last_update2018-08-22 19:33:09
depth2
children0
last_payout2018-08-29 18:16:12
cashout_time1969-12-31 23:59:59
total_payout_value0.036 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length360
author_reputation2,631,258,794,707
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,042,880
net_rshares25,768,991,613
author_curate_reward""
vote details (1)
@utopian-io ·
$0.02
Thank you for your review, @helo!

So far this week you've reviewed 8 contributions. Keep up the good work!
πŸ‘  ,
properties (23)
authorutopian-io
permlinkre-re-programarivm-seed-a-sql-database-with-pgn-games-20180822t162914965z-20180824t163008z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-08-24 16:30:09
last_update2018-08-24 16:30:09
depth2
children0
last_payout2018-08-31 16:30:09
cashout_time1969-12-31 23:59:59
total_payout_value0.017 HBD
curator_payout_value0.003 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length107
author_reputation152,955,367,999,756
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,244,163
net_rshares15,097,742,821
author_curate_reward""
vote details (2)
@steem-ua ·
Hi @programarivm! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!
properties (22)
authorsteem-ua
permlinkre-seed-a-sql-database-with-pgn-games-20180822t183238z
categoryutopian-io
json_metadata"{"app": "beem/0.19.54"}"
created2018-08-22 18:32:39
last_update2018-08-22 18:32:39
depth1
children0
last_payout2018-08-29 18:32:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length189
author_reputation23,214,230,978,060
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,044,127
net_rshares0
@steemitboard ·
Congratulations @programarivm! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/comments.png)](http://steemitboard.com/@programarivm) Award for the number of comments

<sub>_Click on the badge to view your Board of Honor._</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Do not miss the last post from @steemitboard:**
[SteemitBoard and the Veterans on Steemit - The First Community Badge.](https://steemit.com/veterans/@steemitboard/steemitboard-and-the-veterans-on-steemit-the-first-community-badge)

> You can upvote this notification to help all Steemit users. Learn why [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
πŸ‘  
properties (23)
authorsteemitboard
permlinksteemitboard-notify-programarivm-20180822t224323000z
categoryutopian-io
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2018-08-22 22:43:21
last_update2018-08-22 22:43:21
depth1
children0
last_payout2018-08-29 22:43:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length856
author_reputation38,975,615,169,260
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,060,421
net_rshares607,577,041
author_curate_reward""
vote details (1)
@utopian-io ·
Hey @programarivm
 **Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-seed-a-sql-database-with-pgn-games-20180822t233036z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-08-22 23:30:36
last_update2018-08-22 23:30:36
depth1
children0
last_payout2018-08-29 23:30:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length305
author_reputation152,955,367,999,756
root_title"Seed a SQL Database with PGN Games"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id69,063,274
net_rshares0