#!/usr/bin/perl

#package:	UAM TExt Tools
#component:	canonize
#version:	1.0
#author:	Tomasz Obrebski

use lib "/usr/local/lib/utt";
use lib "$ENV{'HOME'}/.local/lib/utt";

use strict;
use Getopt::Long;
use attr;


my $help;

GetOptions("help|h" => \$help);

if($help)
{
    print <<'END'

Transforms syntactic categories to their canonical form.

Usage: canonize

Options:
   --help -h			Help.

END
;
    exit 0;
}

#$|=1;

my %tra;

while(<>)
{
    s/$attr::pos_re\/$attr::avlist_re/trans($&)/ge;
    print;
}

sub trans
{
    my $cat=shift;
    exists($tra{$cat}) ? $tra{$cat} : ( $tra{$cat} = attr::canonize $cat );
}
