remove some fields
[star2016] / star2016-contributions.pl
index dde38e0..24731b2 100755 (executable)
@@ -3,9 +3,9 @@ use autodie;
 use warnings;
 use strict;
 
+use utf8;
 use XML::Simple;
 use Data::Dump qw(dump);
-use utf8;
 
 my $odt_file   = 'contributions.odt';
 
@@ -15,12 +15,12 @@ use OpenOffice::OODoc       2.101;
 my $doc = odfDocument(file => $odt_file, create => 'text');
 
 my $stat;
-my $id2nr;
+my $abstracts;
 
 $doc->createStyle(
        "Abstract",
        family          => 'paragraph',
-#      parent          => 'Default Style',
+       parent          => 'Standard',
 #      category        => 'auto',
        properties      => {
                -area                   => 'paragraph',
@@ -30,19 +30,27 @@ $doc->createStyle(
 
 
 my $nr = 0;
-foreach my $file ( glob 'contributions/*.xml' ) {
+#foreach my $file ( glob 'contributions/*.xml' ) {
+
+my $xml;
+open(my $fh, '<:encoding(utf-8)', 'contributions/all.xml');
+{
+       local $/ = undef;
+       $xml = <$fh>;
+       close($fh);
+}
 
-       my $abstract;
+#warn "---xml---", dump($xml), "---/xml---\n";
 
-       warn "# reading $file\n";
+foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
 
-       {
-               open(my $fh, '<:raw', $file);
-               local $/ = undef;
-               my $xml = <$fh>;
-#              warn dump($xml);
-               $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
-       }
+       next unless $xml;
+
+       $xml = '<?xml' . $xml;
+
+       my $abstract;
+
+       $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
 
        warn "# abstract = ", dump($abstract);
 
@@ -50,31 +58,71 @@ foreach my $file ( glob 'contributions/*.xml' ) {
        warn "# $id abstract = ", dump($abstract);
 
        foreach my $k (qw( ContributionType )) {
-               $stat->{$k}->{ $abstract->{$k}->[0] } ++;
+               push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id;
+       }
+
+       if ( $abstract->{'ContributionType'}->[0] eq 'Symposium proposal' ) {
+               my $t = $abstract->{Title}->[0];
+               push @{ $stat->{_symposium}->{ $t } }, -$id;
+       }
+
+       if ( my $s = $abstract->{Symposium_title} ) {
+               $s = $s->[0];
+               push @{ $stat->{_symposium}->{$s} }, $id;
        }
 
-       my $f = $abstract->{field};
+       if ( exists $abstract->{PrimaryAuthor}->[0]->{FamilyName} ) {
+               $stat->{_order_by}->{$id} = $abstract->{PrimaryAuthor}->[0]->{FamilyName}->[0];
+       }
+
+       $abstracts->{ $id } = $abstract;
+
+}
 
-       push @{ $stat->{_symposium}->{ $f->{1}->{'content'} } }, $id if exists $f->{1}->{content};
-       push @{ $stat->{_theme}->{     $f->{2}->{'content'} } }, $id if exists $f->{2}->{content};
+#warn "# stat = ",dump($stat);
 
-       $stat->{field}->{ $_ }++ foreach keys %$f;
+use Encode;
+sub enc {
+       my $b = shift;
+       warn "# enc in  ",Encode::is_utf8($b), dump($b);
 
-       $id2nr->{ $id } = $nr++;
+#      $b = Encode::decode('iso-8859-1',$b); # XXX doesn't work!
 
-warn "$nr";
+#      Encode::from_to($b, 'iso-8859-1','utf-8');
+#      Encode::_utf8_on($b);
+
+       Encode::_utf8_off($b);
+
+       warn "# enc out ",Encode::is_utf8($b), dump($b);
+       return $b;
+}
+sub l1 {
+       my $l = shift;
+       #return 'FIXME ref ' . dump($l) if ref $l;
+       return undef if ref $l;
+       return enc($l) if $l =~ m/([\x{80}-\x{ff}])/;
+       return $l;
+}
+
+my @authors;
+
+sub abstract2doc {
+       my $id = shift;
+
+       my $abstract = $abstracts->{$id} || die "no $id in abstracts ",dump($abstracts);
 
        my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
        $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
 
        foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
-               $doc->appendParagraph(text => join(' ',
-                       map { $a->{$_}->[0] } qw( FirstName FamilyName )
-               ), style => 'Heading 2');
-               $doc->appendParagraph(text => join(' ',
-                       map { $a->{$_}->[0] } qw( Affiliation )
-               ), style => 'Heading 3');
-               push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
+               my $v;
+               $v->{$_} = l1($a->{$_}->[0]) foreach qw( FirstName FamilyName Affiliation Email );
+               $doc->appendParagraph(text => $v->{FirstName} . ' ' . $v->{FamilyName}, style => 'Heading 2');
+               $doc->appendParagraph(text => $v->{Affiliation}, style => 'Heading 3');
+               push @{ $stat->{_Affiliation}->{ $v->{Affiliation} } }, $id;
+
+               push @authors, $v;
+
        }
 
 #      $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
@@ -82,12 +130,63 @@ warn "$nr";
                $doc->appendParagraph(text => $p, style => 'Abstract');
        }
 
-       $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
-       
+#      $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
+
+#      $doc->appendParagraph(text => "\nContributionType: " . $abstract->{ContributionType}->[0], style => 'Quotations');
 
        $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
+
+       warn "# added $id to document\n";
+}
+
+#foreach my $id ( keys %$abstracts ) {
+#      abstract2doc($id);
+#}
+
+foreach my $symposium ( keys %{ $stat->{'_symposium'} } ) {
+
+       my $t = $doc->appendParagraph(text => $symposium, style => 'Title');
+       $doc->setPageBreak( $t, position => 'before', style => 'Title');
+       $doc->appendParagraph(text => 'Symposium', style => 'Subtitle');
+
+       my @symposium_ids = sort @{ $stat->{'_symposium'}->{$symposium} };
+       warn "## [$symposium] symposium_ids ", dump( @symposium_ids );
+
+       my $proposal_id = shift @symposium_ids;
+       if ( $proposal_id < 0 ) {
+               $proposal_id = abs( $proposal_id );
+       } else {
+               warn "ERROR: symposium [$symposium] doesn't have proposal!";
+               
+       }
+#      @symposium_ids = sort { $stat->{_order_by}->{$a} cmp $stat->{_order_by}->{$b} } @symposium_ids;
+       @symposium_ids = sort @symposium_ids;
+       unshift @symposium_ids, $proposal_id;
+
+       $stat->{_order_symposium}->{$symposium} = [ @symposium_ids ];
+
+       foreach my $id ( @symposium_ids ) {
+               abstract2doc($id);
+       }
+
 }
 
+foreach my $type ( 'Oral presentation', 'Poster presentation' ) {
+
+       my $t = $doc->appendParagraph(text => $type, style => 'Title');
+       $doc->setPageBreak( $t, position => 'before', style => 'Title');
+
+       my @order = sort { lc $stat->{_order_by}->{$a} cmp lc $stat->{_order_by}->{$b} }
+               @{ $stat->{'ContributionType'}->{$type} };
+
+       $stat->{ '_order_' . $type } = [ @order ];
+
+       foreach my $id ( @order ) {
+               abstract2doc($id);
+       }
+}
+
+
 warn "# stat = ",dump($stat);
 
 $doc->save;
@@ -98,3 +197,25 @@ foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
        print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
 }
 
+
+my $last_html = '';
+open(my $authors_fh, '>', 'authors.html');
+foreach my $a ( sort { $a->{FamilyName} cmp $b->{FamilyName} } @authors ) {
+       my $html = qq{
+<li>
+ <b>$a->{FamilyName}, $a->{FirstName}</b><br>
+ $a->{Affiliation}<br>
+ <em>$a->{Email}</em>
+</li>};
+       print $authors_fh $html eq $last_html ? '<!-- dup -->' : $html;
+       $last_html = $html;
+}
+
+close $authors_fh;
+
+__DATA__
+    "Symposium proposal"  => 12,
+       "Symposium abstract"  => 52,
+    "Oral presentation"   => 141,
+    "Poster presentation" => 71,
+