Seed a SQL Database with PGN Games

in #utopian-io6 years ago (edited)

Repository

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

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 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)

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. I already shared this roadmap on the Google+ community Chess.

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 [email protected] with the subject "PGN Chess Contributions"
  • Leave me a comment on Twitter
  • Say hello on Google+

Many thanks.

GitHub Account

https://github.com/programarivm

Sort:  
  • Good use of try/catch, and object programming in general
  • You have renamed many files, can you explain why?

Your contribution has been evaluated according to Utopian policies and 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.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

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.

By following the convention <object>-<action> as in db-createthe commands names are a bit more readable.

Thank you for your review, @helo!

So far this week you've reviewed 8 contributions. Keep up the good work!

Congratulations @programarivm! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

You can upvote this notification to help all Steemit users. Learn why here!

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!

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.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.038
BTC 96270.61
ETH 3631.10
USDT 1.00
SBD 3.88