Hugh S. Myers > Chess-PGN-Filter-0.13 > Chess::PGN::Filter

Download:
Chess-PGN-Filter-0.13.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.13   Source  

NAME ^

Chess::PGN::Filter - Perl extension for converting PGN files to other formats.

SYNOPSIS ^

 use Chess::PGN::Filter;

 filter(source => $pgn,filtertype => 'XML');

OR

 my %substitutions = (
     hsmyers => 'Myers, Hugh S (ID)',
 );

 my @exclude = qw(
     WhiteElo
     BlackElo
     EventDate
 );

 filter(
     source => $pgn,
     filtertype => 'TEXT',
     substitutions => \%substitutions,
     nags => 'yes',
     exclude => \@exclude,
 );

OR

 filter(
     source => $pgn,
     filtertype => 'DOM',
 );

OR

 $dom = filter(
     source => $pgn,
     filtertype => 'DOM',
     verbose => 0,
 );

DESCRIPTION ^

This is a typical text in one side, different text out the otherside filter module. There are as of this writing, the following supported choices:

1. XML -- Converts from .pgn to .xml using the included pgn.dtd as the validation document. This is for the most part a one to one transliteration of the PGN standard into XMLese. It does have the additional virtue of allowing positions to be encoded within the XML output. These are generated by an embedded NAG of {0} and automatically (user controlled) at the end of each game. As a kind of adjunct to the position diagrams, pgn.dtd optionally allows each move to include it's FEN string. This allows scripted animation for web pages generated this information.
2. TEXT -- Although the PGN standard is widely available, many program that generate .pgn do so in an ill-formed way. This mode is an attempt to 'normalize' away the various flaws found in the 'wild'! This includes things like game text all on a single line without a preceding blank line. Or castling indicated with zeros rather than the letter 'O'. There is at least one application that carefully indents the first move! The list of oddities is probably as long as the list of applications.
3. DOM -- A Document Object Model (DOM) makes for a very convenient interim form, common to all other filter types. Useful in both the design and debugging phases of filter construction. By way of self-documentation, here is an example of a single game that shows all of the obvious features of the DOM:
 $VAR1 = {
          'Tags' => {
                      'Site' => 'Boise (ID)',
                      'Event' => 'Cabin Fever Open',
                      'Round' => '1',
                      'ECO' => '?',
                      'Date' => '1997.??.??',
                      'White' => 'Barrett Curtis',
                      'Black' => 'Myers Hugh S',
                      'Result' => '1-0'
                    },
          'Gametext' => [
                          {
                            'Movenumber' => '1',
                            'Epd' => 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3',
                            'Movetext' => 'e4'
                          },
                          {
                            'Movenumber' => '2',
                            'Epd' => 'rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6',
                            'Movetext' => 'd5'
                          },
                          {
                            'Movenumber' => '3',
                            'Epd' => 'rnbqkbnr/ppp1pppp/8/3pP3/8/8/PPPP1PPP/RNBQKBNR b KQkq -',
                            'Movetext' => 'e5'
                          },
                          {
                            'Movenumber' => '4',
                            'Comment' => 'Playing ...Bf5 before closing the c8-h3 diagonal has  some positive features.',
                            'Epd' => 'rnbqkbnr/ppp2ppp/4p3/3pP3/8/8/PPPP1PPP/RNBQKBNR w KQkq -',
                            'Movetext' => 'e6'
                          },
                          {
                            'Movenumber' => '5',
                            'Epd' => 'rnbqkbnr/ppp2ppp/4p3/3pP3/3P4/8/PPP2PPP/RNBQKBNR b KQkq d3',
                            'Movetext' => 'd4'
                          },
                          {
                            'Movenumber' => '6',
                            'Comment' => 'Time to think like a Frenchie - c7-c5!',
                            'Epd' => 'r1bqkbnr/ppp2ppp/2n1p3/3pP3/3P4/8/PPP2PPP/RNBQKBNR w KQkq -',
                            'Movetext' => 'Nc6',
                            'Rav' => [
                                       {
                                         'Movenumber' => '6',
                                         'Epd' => 'rnbqkbnr/pp3ppp/4p3/2ppP3/3P4/8/PPP2PPP/RNBQKBNR w KQkq c6',
                                         'Movetext' => 'c5'
                                       }
                                     ]
                          },
 .
 .
 .
                          {
                            'Movenumber' => '29',
                            'Comment' => ' (Bxe5) Black could  still kick for a while if he had played ...Bxe5.',
                            'Epd' => 'r1bq1rk1/2p1npb1/2n1p2P/pp1pP1p1/3P2P1/2P4Q/PP2BP2/RNB1K2R b KQ -',
                            'Movetext' => 'h6'
                          }
                        ]
        };

Briefly, the DOM is a multiply nested data structure of hashes and arrays. In a sort of outline form, it more or less follows this schematic:

I PGN Document Root
A. Extra-Game Comments
1. Before 1st Game
2. After Each Game
B. Games
1. Tagset
2. Extra-Gametext Comments
3. Gametext
a. Moves
1.) Movetext
2.) Comment
3.) NAG
4.) RAV (essentially an instance of Gametext)

The 'extra' comments have not yet been implemented. See the TODO list.

Owing to a dearth of imagination, there is but one exported routine in the module:

filter(parameter_hash)

There are however, a small host of known keys for parameter_hash and they are as follows:

EXPORT

filter - given a source file and specification, convert to supported output. See details in Description.

DEPENDENCIES

use Chess::PGN::Parse;
use Chess::PGN::EPD;
use Text::DelimMatch;
use Carp;
use Data::Dumper;

TODO ^

KNOWN BUGS ^

None known; Unknown? Of course, though I try to be neat...

AUTHOR ^

Hugh S. Myers

Always: hsmyers@sdragons.com