User:Xybot/FixRomanianDiacritics

From OpenStreetMap Wiki
Jump to: navigation, search

This is the Ruleset FixRomanianDiacritics of the Xybot script

sub begin {
  my $me = shift;
  Data::Primitive->setCreator("FixRomanianDiacritics");
  Data::Primitive->setComment('Correction of romanian diacritic characters');
}

sub process {
  my ($me, $obj) = @_;

  my $resultstr = "";
  my $work = $obj;
  my $clone = undef;

  while (($k,$v) = each(%{$work->{"tags"}})) {
    if (defined($v)) {
      my $gotcha=0;
      $gotcha++ if ($v =~ s/Â/Â/g);          # Morbus Potlatch c382  Latin Capital Letter A With Circumflex
      $gotcha++ if ($v =~ s/Ã/ă/g);          # Morbus Potlatch c383 ă Latin Small Letter A With Breve
      $gotcha++ if ($v =~ s/â/â/g);          # Morbus Potlatch c3a2 â Latin Small Letter A With Circumflex
      $gotcha++ if ($v =~ s/ã/ã/g);          # Morbus Potlatch c3a3 ã Latin Small Letter A With Tilde
      $gotcha++ if ($v =~ s/Ä‚/Ă/g);          # Morbus Potlatch c482 Ă Latin Capital Letter A With Breve
      $gotcha++ if ($v =~ s/ÃŽ/Î/g);          # Morbus Potlatch c38e Î Latin Capital Letter I With Circumflex
      $gotcha++ if ($v =~ s/î/î/g);          # Morbus Potlatch c3ae î Latin Small Letter I With Circumflex
      $gotcha++ if ($v =~ s/Åž/Ş/g);          # Morbus Potlatch c59e Ş Latin Capital Letter S With Cedilla
      $gotcha++ if ($v =~ s/ÅŸ/ş/g);          # Morbus Potlatch c59f ş Latin Small Letter S With Cedilla
      $gotcha++ if ($v =~ s/Å¢/Ţ/g);          # Morbus Potlatch c5a2 Ţ Latin Capital Letter T With Cedilla
      $gotcha++ if ($v =~ s/Å£/ţ/g);          # Morbus Potlatch c3a3 ţ Latin Small Letter T With Cedilla
      $gotcha++ if ($v =~ s/Ç�/Ǎ/g);          # Morbus Potlatch c78d Ǎ Latin Capital Letter A With Caron
      $gotcha++ if ($v =~ s/ÇŽ/ǎ/g);          # Morbus Potlatch c78e ǎ Latin Small Letter A With Caron
      $gotcha++ if ($v =~ s/Ș/Ș/g);          # Morbus Potlatch c898 Ș Latin Capital Letter S With Comma Below
      $gotcha++ if ($v =~ s/È™/ș/g);          # Morbus Potlatch c899 ș Latin Small Letter S With Comma Below
      $gotcha++ if ($v =~ s/Èš/Ț/g);          # Morbus Potlatch c89a Ț Latin Capital Letter T With Comma Below
      $gotcha++ if ($v =~ s/È›/ț/g);          # Morbus Potlatch c89B ț Latin Small Letter T With Comma Below
      $gotcha++ if ($v =~ s/Ã/Ã/g);          # Morbus Potlatch c383 à Latin Capital Letter A With Tilde

      $gotcha++ if ($v =~ s/ã|ǎ/ă/g);         # SMALL LETTER A WITH BREVE
      $gotcha++ if ($v =~ s/Ã|Ǎ/Ă/g);         # CAPITAL LETTER A WITH BREVE
      $gotcha++ if ($v =~ s/ş/ș/g);           # SMALL LETTER S WITH COMMA BELOW
      $gotcha++ if ($v =~ s/Ş/Ș/g);           # CAPITAL LETTER S WITH COMMA BELOW
      $gotcha++ if ($v =~ s/ţ/ț/g);           # SMALL LETTER T WITH COMMA BELOW
      $gotcha++ if ($v =~ s/Ţ/Ț/g);           # CAPITAL LETTER T WITH COMMA BELOW

      if ($gotcha) {
        $resultstr .= sprintf " - key '%s' modifying value '%s' to '%s'", $k, $work->{"tags"}->{$k}, $v;

        $clone=$work->clone() unless defined($clone);
        $clone->{"tags"}->{$k} = $v;
        $work=$clone;
      }
      if ($v =~ /^\s*(\(type road name\))\s*$/i) {
        $clone=$work->clone() unless defined($clone);
        delete $clone->{"tags"}->{$k};
        $resultstr .= sprintf " - deleting meaningless tag '%s=%s'", $k, $v,
        $work=$clone;
      }
    }
  }
  $obj->log(ref($obj), $work->{"id"}, $resultstr, $obj->update($clone, $me)) if (defined($clone));
}