Alt-CWB-ambs
view release on metacpan or search on metacpan
data/vrt/VeryShortStories.vrt view on Meta::CPAN
Graphics NP Graphics
Environment NP Environment
Manager NP Manager
) ) )
screen NN screen
appeared VBD appear
. SENT .
</s>
<s>
Ed NP Ed
selected VBD select
the DT the
messages NNS message
item NN item
from IN from
one CD one
of IN of
the DT the
pull-down JJ pull-down
menus NNS menu
. SENT .
data/vrt/VeryShortStories.vrt view on Meta::CPAN
soon RB soon
as IN as
he PP he
had VBD have
returned VBN return
to TO to
his PP$ his
office NN office
, , ,
he PP he
selected VBD select
the DT the
love NN love
nest NN nest
option NN option
from IN from
the DT the
Extras NNS extra
menu NN menu
on IN on
his PP$ his
data/vrt/VeryShortStories.vrt view on Meta::CPAN
, , ,
so RB so
he PP he
had VBD have
no DT no
choice NN choice
. SENT .
</s>
<s>
Ed NP Ed
selected VBD select
film NN film
reviews NNS revue
from IN from
the DT the
Phrases NNS phrase
menu NN menu
. SENT .
</s>
<s>
This DT this
data/vrt/VeryShortStories.vrt view on Meta::CPAN
articles NNS article
. SENT .
</s>
<s>
Ed NP Ed
opted VBD opt
for IN for
affirmative JJ affirmative
phrases NNS phrase
and CC and
selected JJ selected
sex NN sex
crime NN crime
movies NNS movie
from IN from
the DT the
submenu NN <unknown>
that WDT that
appeared VBD appear
next JJ next
. SENT .
data/vrt/VeryShortStories.vrt view on Meta::CPAN
Ed NP Ed
switched VBD switch
on IN on
the DT the
computer NN computer
terminal NN terminal
on IN on
his PP$ his
desk NN desk
and CC and
selected VBD select
the DT the
messages NNS message
item NN item
. SENT .
</s>
<s>
The DT the
usual JJ usual
message NN message
from IN from
=item @attr_of_type = $reg->list_attributes($type);
=item $type = $reg->attribute($att_name);
B<list_attributes()> returns the names of all declared attributes. The
B<attribute()> method returns the type of the specified attribute, or an
undefined value if the attribute is not declared. I<$type> is one of
C<'p'> (B<positional>), C<'s'> (B<structural>), or C<'a'> (B<alignment>).
Passing one of these type codes to B<list_attributes()> will return
attributes of the selected type only.
=cut
sub list_attributes ( $;$ ) {
my ($self, $type) = @_;
my @list = @{$self->{SERIALIZE}};
if (defined $type) {
$type = lc $type;
@list = grep {$self->{ATT}->{$_} eq $type} @list;
}
lib/CWB/CEQL/Parser.pm view on Meta::CPAN
substitutions are applied unconditionally, so symbols cannot have different
meanings in different contexts).
B<CWB::CEQL::Parser> aims to overcome these limitations by combining
regexp-based matching and substitution with a simple top-down parser for
context-free grammars, as well as a shift-reduce-style parser for nested
bracketing. Parsing complexity is limited by enforcing a B<fully
deterministic> parsing algorithm: a B<DPP rule> (= constituent type,
corresponding to the LHS of a traditional CFG rule) may have multiple
expansions, but the Perl code implementing the rule has to employ heuristics
to choose a single expansion for a given input. If the selected expansion
does not match the input string, the entire parsing process fails. Again,
this decision was motivated by the observation that, in the case of simplified
query languages, it is often very easy to make such deterministic decisions
with a regular expression and/or a few lines of Perl code.
Each B<DPP rule> is implemented as a B<Perl subroutine> (or, more precisely,
B<method>). It is invoked by the parser with an input string that is expected
to be a constituent of the respective type, and returns its analysis of this
constituent. In the typical application of DPP grammars, the return value is
a string representing (part of) a low-level query expression, but grammar
lib/CWB/CEQL/Parser.pm view on Meta::CPAN
(B<GetParam>). The parameter I<$name> must have been defined by the grammar
class (which I<$grammar> is an instance of) and should be described in the
grammar's documentation.
=cut
sub SetParam {
croak 'Usage: $grammar->SetParam($name, $value)'
unless @_ == 3;
my ($self, $name, $value) = @_;
## select either global parameter values (user level) or working copy (during parse)
my $param_set = (defined $self->{INPUT}) ? $self->{PARAM} : $self->{PARAM_DEFAULTS};
croak "CWB::CEQL::Parser: parameter '$name' does not exist"
unless exists $param_set->{$name};
$param_set->{$name} = $value;
}
sub GetParam {
croak 'Usage: $grammar->GetParam($name)'
unless @_ == 2;
my ($self, $name) = @_;
lib/CWB/CEQL/Parser.pm view on Meta::CPAN
parameterized grammar. If it is used in a rule body, the new parameter
will be created in the working copy of the parameter set and will only be
available during the current parse.
=cut
sub NewParam {
confess 'Usage: $self->NewParam($name, $default_value)'
unless @_ == 3;
my ($self, $name, $value) = @_;
## select either global parameter values (user level) or working copy (during parse)
my $param_set = (defined $self->{INPUT}) ? $self->{PARAM} : $self->{PARAM_DEFAULTS};
confess "CWB::CEQL::Parser: parameter '$name' already exists, cannot create with NewParam()"
if exists $param_set->{$name};
$param_set->{$name} = $value;
}
=item I<$result> = I<$self>->B<Call>(I<$rule>, I<$input>);
Apply rule I<$rule> to input string I<$input>. The return value I<$result>
depends on the grammar rule, but is usually a string containing a translated
lib/CWB/CQP.pm view on Meta::CPAN
$self->{'error_message'} = []; # arrayref to array containing message produced by last command (if any)
## handling of CQP progress messages
$self->{'progress'} = 0; # whether progress messages are activated
$self->{'progress_handler'} = undef; # optional callback for progress messages
$self->{'progress_info'} = []; # contains last available progress information: [$total_percent, $pass, $n_passes, $message, $percent]
## debugging (prints more or less everything on stdout)
$self->{'debug'} = 0;
## select vectors for CQP output (stdout, stderr, stdout|stderr)
$self->{'select_err'} = new IO::Select($err);
$self->{'select_out'} = new IO::Select($out);
$self->{'select_any'} = new IO::Select($err, $out);
## CQP object setup complete
bless($self, $class);
## the following command will collect and ignore any output which may have been produced during startup
$self->exec("set PrettyPrint off"); # pretty-printing should be turned off for non-interactive use
return $self;
}
lib/CWB/CQP.pm view on Meta::CPAN
## NB: $lines_read includes the .EOL. terminator line, so it is safe to keep calling _update()
## until a non-zero value is returned (even if a CQP command fails with an error message).
sub _update {
my $self = shift;
my $timeout = shift || 0;
$timeout = undef
if $timeout < 0;
my $stderr_buffer = "";
my $lines = 0; # how many lines have successfully been read from stdout
while ($self->{'select_any'}->can_read($timeout)) {
## STDERR -- read all available output on stderr first
if ($self->{'select_err'}->can_read(0)) {
sysread $self->{'err'}, $stderr_buffer, $self->{'block_size'}, length($stderr_buffer); # append to $stderr_buffer
}
## STDOUT -- if there is no more data on stderr, we should be able to read from stdout
elsif ($self->{'select_out'}->can_read(0)) {
sysread $self->{'out'}, $self->{'buffer'}, $self->{'block_size'}, length($self->{'buffer'}); # append to object's input buffer
if ($self->{'buffer'} =~ /\n/) {
## if there's a complete line in the input buffer, split off all lines
my @new_lines = split /\n/, $self->{'buffer'}, -1; # make sure that last line is handled correctly if buffer ends in \n
$self->{'buffer'} = pop @new_lines; # last entry is incomplete line ("" if buffer ended in \n) => return to input buffer
foreach my $line (@new_lines) {
## skip blank line printed after each CQP command
next if $line eq "";
## handle progress messages if ProgressBar has been activated
if ($self->{'progress'} and $line =~ /^-::-PROGRESS-::-/) {
( run in 0.628 second using v1.01-cache-2.11-cpan-49f99fa48dc )