Changeset 3142

Show
Ignore:
Timestamp:
12/14/07 20:26:42 (5 years ago)
Author:
naoya_t
Message:

r3138@localhost: naochan | 2007-12-14 20:24:29 +0900
added PDIC -> Leopard's dictionary converter

Location:
lang/perl/PDIC-Converter/trunk
Files:
7 added
3 removed
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/PDIC-Converter/trunk/README.TXT

    r2727 r3142  
    1 �������@pdic-conv version 0.1.1 (2007-12-07�� 
     1�������@pdic-conv version 0.2 (2007-12-14�� 
    22 
    33���������H 
    4 �@�u�p���Y ���Łv�i�A���N���j�����̎����f�[�^���@�EPDIC�o�C�i���`������IC�P�s�e�L�X�g�`�� (pdic1line) 
    5 �@�@�E�u�p���Y�r���[�A�v�ł������� (eview) 
     4  PDIC�`���̎������@�E�P�s�e�L�X�g�`�� (pdic-to-1line.pl) 
     5�@�@�E[NEW!] Mac OS X Leopard�́u�����v�`�� (pdic-to-leopard.pl) 
    66�@�ɕϊ������N���v�g�ł��B 
    77 
    8 �@�ȉ� <format> ������ic1line �܂���eview �ɓǂݑւ��ĉ������B 
     8�@�u�p���Y ���Łv�i�A���N���j�����̎����f�[�^���@�EPDIC�o�C�i���`������IC�P�s�e�L�X�g�`�� 
     9�@�@�E�u�p���Y�r���[�A�v�ł������� 
     10�@�ɕϊ������N���v�g�������Ă��܂��B 
     11�@�ڂ�����README.eijiro3 ������B 
     12 
     13�@Leopard�`���ւ̕ϊ��́u�Ƃ肠�����v�ł��B 
     14�@�����L���⑼�̃G���g���[�ւ̃����N�Ȃǂ̏��͂܂�����܂����@�i�����L����IL-IPA�R�[�h����F-8�ɕϊ������v����C++�̃��C�u���������ŋ߁X�ڐA���܂��j 
    915 
    1016���g�p��Ƃ� 
    1117�@�t���[�E�F�A�ł��B���ۏ؂ł��B 
    12  
    13 �@CPAN�ɍڂ������ō����������C�u�����𓯍����Ă��܂��B���C�Z���X��erl���C�Z���X�ɂ������ł��� 
    14 �@�Ƃ肠�����񎟔z�z�͍T���Ă����������L��ł��B 
    15  
    16 �@��Encode::BOCU-1 �Ƃ������C�u�����i�ٍ��ƍ��킹�Ďg����Unicode (BOCU-1) ��DIC�������߂����ł��B 
     18�@CPAN�ɍڂ������ō����������C�u�����𓯍����Ă��܂��B���C�Z���X��erl���C�Z���X�ŁB 
    1719 
    1820���Ƃ肠�����K�v�Ȃ� 
    19 �@�u�p���Y ���Łv�i�A���N���j 
    20  
    21 �@���p���Y�̃e�L�X�g�f�[�^���~���������Ȃ�P�ōŐV�f�[�^��T�`���Ŕ���Ă܂��̂ł��������������������B 
    22 �@http://www.eijiro.jp/ 
    23 �@���̏ꍇ���̃c�[���͕s�v�ł��B 
     21�@�ϊ�������PDIC�`���̎����B 
     22�@Leopard�́u�����v�`���ɕϊ��������́ALeopard�̃C���X�g�[���f�B�X�N�Ɋ܂܂��J���c�[����ɃC���X�g�[�������v���������B 
    2423 
    2524�������� 
    26 �@Mac OS X �́u�p���Y ���Łv�����삷���[�W�����Ȃ炽�Ԃ�ł��BOS X�t����erl�ōs���܂��B 
    27 �@��Windows ���̑���OS �Ŏg���ꍇ��convert-all-***.sh ��DICT_DIR ��X���������ĉ������B���Ԃ񓮂��܂��B 
     25�@Mac OS X 10.5.1�ȍ~�𐄏� 
    2826 
    29 ���g����i�P�j�u�p���Y ���Łv�̃C���X�g�[���ʼnp���Y�f�[�^����X�g�[�� 
    30 �@�@�@�@�f�X�N�g�b�v��PDICViewer1024EE �Ƃ����t�H���_���ł��܂��B 
    31 �@�i�Q�j���̃c�[��������i�z�[���f�B���N�g�������j�ɓW�J���Aconvert-all-<format>.sh �𑖂点�� 
     27���g�����@% perl pdic-to-1line.pl PDIC���� sjis  ��Shift_JIS�ŕۑ��B(Ver.4�����̂� 
     28�@�@% perl pdic-to-1line.pl PDIC����       ��UTF-8�ŕۑ��B(Unicode�����͂����� 
     29�@�@% perl pdic-to-leopard.pl PDIC���� 
     30�@�@% perl pdic-to-leopard.pl PDIC���� �t�H���g�t�@�~���[��  �����o�����\���t�H���g(CSS�p) 
    3231 
    33 �@�@% cd ~ 
    34 �@�@% tar zxf pdic-conv-0.1.1.tar.gz 
    35 �@�@% cd pdic-conv 
    36 �@�@% ./convert-all-<format>.sh 
    37 �@�@[eijiro98] 
    38 �@�@[reiji98] 
    39 �@�@[ryaku98] 
    40 �@�@[waeiji98] 
    41 �@�@% 
     32�����ӎ��� 
    4233 
    43 �@�i�Q�j�����Ǝ��Ԃ��������ŋx�e�B�R�[�q�[��[�{�[�h�ɂ��ڂ��Ȃ��悤�ɁB 
    44 �@�i�R�j~/pdic-conv/ ���@�@�@�@�@eijiro98.txt, reiji98.txt, ryaku98.txt, waeiji98.txt 
    45 �@�@�@�@�Ƃ����t�@�C�����ł����ŁA���ς������Ȃ��E�E���D���Ȃ悤�ɁB 
     34�@�A���N���u�p���Y�@���Łv�ɓ�����������IC���������ϊ��ł��܂����AGB�P�ʂɂȂ����@�f�B�X�N�e�ʂɂ��Ȃ����肪�K�v�ł��B���Ԃ������i�\�����H���\���H�j���������B 
     35�@���̂������̃c�[�����̂��o�[�W�����A�b�v�����ŁA�����̂͂��ꂩ�����Ă����͂������� 
     36�@�Ȃ��A�e�L�X�g�`���̉p���Y��pard�`���ɕϊ������́A���̃c�[���ł͂Ȃ� 
     37�@�@http://www.binword.com/blog/archives/000569.html 
     38�@�̋L�����Q�l�ɂȂ邩�Ǝv���܂��B 
    4639 
    47 ������version 0.1.1 ���Q�‚���Ƃ߁A����tsune����007/5/9�̃p�b�`��p 
     40������version 0.2 Leopard�̎����`���ɑΉ� 
     41  version 0.1.1 ���Q�‚���Ƃ߁A����tsune����007/5/9�̃p�b�`��p 
    4842    < http://subtech.g.hatena.ne.jp/otsune/20070509/EIJIROPDICConverterDiff 
    4943�@version 0.1 (2007-02-12�� 
  • lang/perl/PDIC-Converter/trunk/lib/Dictionary/PDIC.pm

    r2727 r3142  
    99 
    1010use Dictionary::PDIC::Dump; 
     11 
     12use Digest::SHA1  qw(sha1_hex); 
    1113 
    1214##use utf8; 
     
    497499# 
    498500sub render_field { 
    499     my ($self,$ref_field,$output_encoding,$output_format) = @_; 
     501    my ($self,$fh,$ref_field,$output_encoding,$output_format) = @_; 
    500502#    my $is_bocu = $self->is_bocu; 
    501503 
     
    523525        $trans =~ s/\015\n/ \\ /g; 
    524526 
    525         printf("%s\n", $entry); 
     527        print $fh "$entry\n"; 
    526528        if ($example) { 
    527             printf("%s / %s\n", $trans, $example); 
     529            print $fh "$trans / $example\n"; 
    528530        } else { 
    529             printf("%s\n", $trans); 
     531            print $fh "$trans\n"; 
    530532        } 
    531533    } elsif ($output_format eq 'PDIC-1LINE') { 
    532534        $trans =~ s/\015\n/ \\ /g; 
    533535        if ($example) { 
    534             printf("%s /// %s / %s\n", $entry, $trans, $example); 
     536            print $fh "$entry /// $trans / $example\n"; 
    535537        } else { 
    536             printf("%s /// %s\n", $entry, $trans); 
     538            print $fh "$entry /// $trans\n"; 
    537539        } 
    538540    } elsif ($output_format eq 'TAB') { 
    539541        $trans =~ s/\015\n/ \\ /g; 
    540         printf("%s\t%s\t%s\n", $entry, $trans, $example); 
     542        print $fh "$entry\t$trans\t$example\n"; 
    541543    } elsif ($output_format eq 'CSV') { 
    542544#        $trans =~ s/\015\n/ \\ /g; 
    543545        $trans =~ s/"/\\"/g; 
    544         printf("\"%s\",\"%s\",\"%s\"\n", $entry, $trans, $example); 
     546        print $fh "\"$entry\",\"$trans\",\"$example\"\n"; 
     547    } elsif ($output_format eq 'Leopard') { 
     548                my $id = sha1_hex($entry); 
     549                my $entry_escaped = $entry; 
     550                $entry_escaped =~ s/"/\&quot;/g; 
     551                print $fh "<d:entry id=\"$id\" d:title=\"$entry_escaped\">\n"; 
     552                print $fh "\t<d:index d:value=\"$entry_escaped\"/>\n"; 
     553                print $fh "\t<h1><span class='headword'>$entry</span></h1>\n"; 
     554#               print $fh "\t<span d:pr=2>| $pron |</span>\n" if $pron; 
     555                print $fh "\t<span class='meaning'>$trans</span>\n" if $trans; 
     556                print $fh "\t<span class='example'>$example</span>\n" if $example; 
     557                print $fh "</d:entry>\n"; 
    545558    } else { 
    546559        if ($pron) { 
    547             printf("%s [%s]\n", $entry, $pron); 
     560            print $fh "$entry [$pron]\n"; 
    548561        } else { 
    549             printf("%s\n", $entry); 
     562            print $fh "$entry\n"; 
    550563        } 
    551564        $trans =~ s/\015\n/\n\t/g; 
    552         printf("\t%s\n", $trans); 
    553         printf("\t%s\n", $example); 
     565        print $fh "\t$trans\n"; 
     566        print $fh "\t$example\n"; 
    554567    } 
    555568} 
     
    560573sub dump { 
    561574    my ($self,$output_encoding,$output_format) = @_; 
    562     Dictionary::PDIC::Dump::dump($self,$output_encoding,$output_format); 
    563 } 
     575    Dictionary::PDIC::Dump::dump($self,*STDOUT,$output_encoding,$output_format); 
     576} 
     577sub dump_fh { 
     578    my ($self,$fh,$output_encoding,$output_format) = @_; 
     579    Dictionary::PDIC::Dump::dump($self,$fh,$output_encoding,$output_format); 
     580} 
     581 
    564582sub dump_header { 
    565583    my $self = shift; 
    566     Dictionary::PDIC::Dump::dump_header($self); 
     584    Dictionary::PDIC::Dump::dump_header($self,*STDOUT); 
    567585} 
    568586sub dump_index { 
    569587    my ($self,$output_encoding) = @_; 
    570     Dictionary::PDIC::Dump::dump_index($self,$output_encoding); 
     588    Dictionary::PDIC::Dump::dump_index($self,*STDOUT,$output_encoding); 
    571589} 
    572590sub dump_datablock { 
    573591    my ($self,$phys,$output_encoding,$output_format) = @_; 
    574     Dictionary::PDIC::Dump::dump_datablock($self,$phys,$output_encoding,$output_format); 
     592    Dictionary::PDIC::Dump::dump_datablock($self,*STDOUT,$phys,$output_encoding,$output_format); 
    575593} 
    576594 
  • lang/perl/PDIC-Converter/trunk/lib/Dictionary/PDIC/Dump.pm

    r2727 r3142  
    88# 
    99sub dump { 
    10     my ($pdic,$output_encoding,$output_format) = @_; 
     10    my ($pdic,$fh,$output_encoding,$output_format) = @_; 
    1111 
    1212    my $cnt = 0; 
     
    1818    for (my $i=0; $i<=$#index; $i+=2) { 
    1919        my $phys = $index[$i]; 
    20         dump_datablock( $pdic, $phys, $output_encoding, $output_format ); 
     20        dump_datablock($pdic,$fh,$phys,$output_encoding,$output_format); 
    2121    } 
    2222} 
     
    2626# 
    2727sub dump_header { 
    28     my $pdic = shift; 
     28#    my $pdic = shift; 
     29        my ($pdic,$fh) = @_; 
    2930 
    3031    my %header = $pdic->header; 
    3132    while ((my $key, my $value) = each(%header)) { 
    32       printf("%s => %s\n", $key, $value); 
     33                printf $fh "%s => %s\n", $key, $value; 
    3334    } 
    3435} 
     
    3839# 
    3940sub dump_index { 
    40     my ($pdic,$output_encoding) = @_; 
     41    my ($pdic,$fh,$output_encoding) = @_; 
    4142    unless ($output_encoding) { 
    4243        $output_encoding = $pdic->is_bocu ? 'utf8' : 'shiftjis'; 
     
    5253            Encode::from_to($entry, $dict_encoding, $output_encoding); 
    5354        } 
    54         printf("- phys=%d entry=\"%s\"\n", $index[$i], $entry); 
     55        printf $fh, "- phys=%d entry=\"%s\"\n", $index[$i], $entry; 
    5556    } 
    5657} 
     
    6061# 
    6162sub dump_datablock { 
    62     my ($pdic,$phys,$output_encoding,$output_format) = @_; 
     63    my ($pdic,$fh,$phys,$output_encoding,$output_format) = @_; 
    6364 
    6465    my @result = (); 
     
    6970 
    7071    foreach my $ref_field (@result) { 
    71         $pdic->render_field($ref_field,$output_encoding,$output_format); 
     72        $pdic->render_field($fh,$ref_field,$output_encoding,$output_format); 
    7273    } 
    7374}