| 1 | package PMLTQ::Command::suggest; | ||
| 2 | our $AUTHORITY = 'cpan:MATY'; | ||
| 3 | $PMLTQ::Command::suggest::VERSION = '0.0.3'; | ||
| 4 | # ABSTRACT: Return query for given nodes | ||
| 5 | |||
| 6 | use PMLTQ::Base 'PMLTQ::Command'; | ||
| 7 | use PMLTQ; | ||
| 8 | use PMLTQ::Suggest::Utils; | ||
| 9 | use PMLTQ::Suggest; | ||
| 10 | use File::Path qw( make_path ); | ||
| 11 | use Getopt::Long qw(GetOptionsFromArray); | ||
| 12 | use Treex::PML; | ||
| 13 | |||
| 14 | has usage => sub { shift->extract_usage }; | ||
| 15 | |||
| 16 | my %opts; | ||
| 17 | |||
| 18 | sub run { | ||
| 19 | my $self = shift; | ||
| 20 | my @args = @_; | ||
| 21 | GetOptionsFromArray(\@args, \%opts, | ||
| 22 | 'nodes|N=s' | ||
| 23 | ) || die "invalid options"; | ||
| 24 | Treex::PML::AddResourcePath( | ||
| 25 | PMLTQ->resources_dir, | ||
| 26 | File::Spec->catfile(${FindBin::RealBin},'config'), | ||
| 27 | $ENV{HOME}.'/.tred.d', | ||
| 28 | $self->config->{resources} | ||
| 29 | ); | ||
| 30 | my @paths = $opts{nodes} ? split(/\|/, $opts{nodes}) : (); | ||
| 31 | my @positions; | ||
| 32 | foreach my $p (@paths) { | ||
| 33 | my ($path, $goto)=PMLTQ::Suggest::Utils::parse_file_suffix($p); | ||
| 34 | $path = URI->new($path)->canonical->as_string; | ||
| 35 | push @positions, [$path,$goto]; | ||
| 36 | } | ||
| 37 | my $pmltq = PMLTQ::Suggest::make_pmltq( | ||
| 38 | \@positions | ||
| 39 | ); | ||
| 40 | Encode::_utf8_off($pmltq); | ||
| 41 | print "$pmltq\n"; | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | =head1 SYNOPSIS | ||
| 46 | |||
| 47 | pmltq suggest [--resources="path to resources directory"] --nodes "FILE2#NODE_ID1|FILE2#NODE_ID2|..." | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | Return query for given nodes. It works on local PML files. | ||
| 52 | |||
| 53 | =head1 OPTIONS | ||
| 54 | |||
| 55 | =head1 PARAMS | ||
| 56 | |||
| 57 | =over 5 | ||
| 58 | |||
| 59 | =item B<treebank_config> | ||
| 60 | |||
| 61 | Path to configuration file. If a treebank_config is --, config is readed from STDIN. | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | 1; |