collect abstract and then generate document
[star2016] / star2016-contributions.pl
1 #!/usr/bin/perl
2 use autodie;
3 use warnings;
4 use strict;
5
6 use XML::Simple;
7 use Data::Dump qw(dump);
8 use utf8;
9
10 my $odt_file   = 'contributions.odt';
11
12 my $xs = XML::Simple->new();
13
14 use     OpenOffice::OODoc       2.101;
15 my $doc = odfDocument(file => $odt_file, create => 'text');
16
17 my $stat;
18 my $abstracts;
19
20 $doc->createStyle(
21         "Abstract",
22         family          => 'paragraph',
23         parent          => 'Standard',
24 #       category        => 'auto',
25         properties      => {
26                 -area                   => 'paragraph',
27                 'fo:text-align' => 'justify'
28         }
29 );
30
31
32 my $nr = 0;
33 #foreach my $file ( glob 'contributions/*.xml' ) {
34
35 my $xml;
36 open(my $fh, '<', 'contributions/all.xml');
37 {
38         local $/ = undef;
39         $xml = <$fh>;
40         close($fh);
41 }
42
43 foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
44
45         next unless $xml;
46
47         $xml = '<?xml' . $xml;
48
49         my $abstract;
50
51 print $xml;
52
53         $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
54
55         warn "# abstract = ", dump($abstract);
56
57         my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
58         warn "# $id abstract = ", dump($abstract);
59
60         foreach my $k (qw( ContributionType )) {
61                 push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id;
62         }
63
64         if ( my $s = $abstract->{Symposium_title} ) {
65                 $s = $s->[0];
66                 push @{ $stat->{_symposium}->{$s} }, $id;
67         }
68
69         $abstracts->{ $id } = $abstract;
70
71 }
72
73 warn "# stat = ",dump($stat);
74
75 sub abstract2doc {
76         my $id = shift;
77
78         my $abstract = $abstracts->{$id} || die "no $id in abstracts ",dump($abstracts);
79
80         my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
81         $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
82
83         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
84                 $doc->appendParagraph(text => join(' ',
85                         map { $a->{$_}->[0] } qw( FirstName FamilyName )
86                 ), style => 'Heading 2');
87                 $doc->appendParagraph(text => join(' ',
88                         map { $a->{$_}->[0] } qw( Affiliation )
89                 ), style => 'Heading 3');
90                 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
91         }
92
93 #       $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
94         foreach my $p ( split(/[\n\r]+/, $abstract->{Content}->[0] ) ) {
95                 $doc->appendParagraph(text => $p, style => 'Abstract');
96         }
97
98         $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
99         
100
101         $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
102
103         warn "# added $id to document\n";
104 }
105
106 foreach my $id ( keys %$abstracts ) {
107         abstract2doc($id);
108 }
109
110 warn "# stat = ",dump($stat);
111
112 $doc->save;
113
114
115 open(my $fh, '>', 'affiliation.csv');
116 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
117         print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
118 }
119
120 __DATA__
121     "Symposium proposal"  => 12,
122         "Symposium abstract"  => 52,
123     "Oral presentation"   => 141,
124     "Poster presentation" => 71,
125