chiark / gitweb /
chart parser calls ocean scraper
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Mon, 31 Aug 2009 15:59:28 +0000 (16:59 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Mon, 31 Aug 2009 15:59:28 +0000 (16:59 +0100)
yarrg/yppedia-chart-parser

index fca7abd7f45652f783fa01b330e6ff05fe389f39..3f773a3341744544c7b869b9b40c6501ef93f724 100755 (executable)
@@ -20,6 +20,7 @@ my %winode2island;
 my %winode2lines;
 my %wiccix2arch;
 my $wialldists;
+my %wtisland2arch;
 
 my $dbdists= Graph::Undirected->new();
 my %dbisland2arch;
@@ -187,12 +188,14 @@ sub yppedia_archs_sourceinfo () {
     foreach my $arch (sort keys %{ $oceans{$ocean} }) {
        foreach my $islename (sort keys %{ $oceans{$ocean}{$arch} }) {
            my $islenode= $wiisland2node{$islename};
-           defined $islenode or
+           if (!defined $islenode) {
                error("island $islename in source-info but not in WP map");
+               next;
+           }
            my $ccix= $wiarchs->connected_component_by_vertex($islenode);
            my $oldarch= $wiccix2arch{$ccix};
-           error("island $islename in $arch in source-info".
-                 " connected to $oldarch as well")
+           error("island in $arch in source-info".
+                 " connected to $oldarch as well: $islename")
                if defined $oldarch && $oldarch ne $arch;
            printf DEBUG "%-5s force-island-arch cc%-2d %-10s %s\n",
                $islenode, $ccix, $arch, $islename;
@@ -360,6 +363,15 @@ sub compare_island_lists () {
        }
     }
     foreach my $island (sort keys %wiisland2node) {
+       my $wtarch= $wtisland2arch{$island};
+       my $wiarch= wiisland2arch($island);
+       if (!defined $wtarch) {
+           error("island from chart not found on ocean page: $island");
+       } elsif (defined $wiarch and $wtarch ne $wiarch) {
+           error("island in $wtarch on ocean page but".
+                 " concluded $wiarch from chart: $island");
+       }
+
        my $dbarch= $dbisland2arch{$island};
        if (!defined $dbarch) {
            my $wiarch= wiisland2arch($island);
@@ -371,6 +383,11 @@ sub compare_island_lists () {
            change("island new in $wiarch: $island");
        }
     }
+    foreach my $island (sort keys %wtisland2arch) {
+       my $node= $wiisland2node{$island};
+       next if defined $node;
+       error("island on ocean page but not in chart: $island");
+    }
 }
 
 sub shortest_path_reduction ($$) {
@@ -499,6 +516,25 @@ sub yppedia_graph_spr () {
     $wispr= shortest_path_reduction('wi',$base);
 }
 
+sub yppedia_ocean_fetch () {
+    open OCEAN, '-|', "./yppedia-ocean-scraper", $ocean or die $!;
+    my $arch;
+    while (<OCEAN>) {
+       chomp;
+       if (m/^ocean /) {
+           $' eq $ocean or die;
+       } elsif (m/^  /) {
+           die unless defined $arch;
+           $wtisland2arch{$'}= $arch;
+       } elsif (m/^ /) {
+           $arch= $';
+       } else {
+           die;
+       }
+    }
+    $?=0; $!=0; close OCEAN; $? and die $?; $! and die $!;
+}
+
 sub compare_distances () {
     foreach my $ia (sort keys %dbisland2arch) {
        my $na= $wiisland2node{$ia};
@@ -543,6 +579,8 @@ progress("setting archs from labels");      yppedia_archs_chart_labels();
 progress("setting archs from nearby");      yppedia_archs_fillbynearest();
 progress("computing yppedia spr");          yppedia_graph_spr();
 
+progress("fetching yppedia ocean text");    yppedia_ocean_fetch();
+
 progress("comparing islands");              compare_island_lists();
 progress("comparing distances");            compare_distances();