Alt-CWB-ambs
view release on metacpan or search on metacpan
lib/CWB/CEQL.pm view on Meta::CPAN
$CEQL->SetParam("s_attributes", { "s" => 1 });
=item C<default_ignore_case>
Indicates whether CEQL queries should perform case-insensitive matching for
word forms and lemmas (C<:c> modifier), which can be overridden with an
explicit C<:C> modifier. By default, case-insensitive matching is activated,
i.e. C<default_ignore_case> is set to 1.
=item C<default_ignore_diac>
Indicates whether CEQL queries should ignore accents (I<diacritics>) for word
forms and lemmas (C<:d> modifier), which can be overridden with an explicit
C<:D> modifier. By default, matching does I<not> ignore accents,
i.e. C<default_ignore_diac> is set to 0.
=back
=back
See the L<CWB::CEQL::Parser> manpage for more detailed information and further methods.
=head1 CEQL SYNTAX
B<** TODO **>
=head1 EXTENDING CEQL
B<** TODO **>: How to extend the standard CEQL grammar by subclassing. Note that the grammar is split into many small rules, so
it is easy to modify by overriding individual rules completely (without having to call the original rule in between or having to
replicate complicated functionality).
See L<CWB::CEQL::Parser> for details on how to write grammar rules. You should always have a copy of the B<CWB::CEQL> source code file at hand when writing your extensions. All rules of the standard CEQL grammar are listed below with short descriptio...
=head1 STANDARD CEQL RULES
=over 4
=item C<ceql_query>
=item C<default>
The default rule of B<CWB::CEQL> is C<ceql_query>. After sanitising
whitespace, it uses a heuristic to determine whether the input string is a
B<phrase query> or a B<proximity query> and delegates parsing to the
appropriate rule (C<phrase_query> or C<proximity_query>).
=cut
sub default {
return ceql_query(@_); # pass through directly to ceql_query(), without explicit Call()
}
sub ceql_query {
my ($self, $input) = @_;
$input =~ s/\s+/ /g; # change all whitespace to single blanks
$input =~ s/^\s+//; $input =~ s/\s+$//; # remove leading/trailing whitespace
# check whether there's something in the query that looks like a distance operator (same regexp as used in proximity_query rule)
if ($input =~ /(?<!\\)((<<|>>)[^<>\\ ]*(<<|>>))/) {
return $self->Call("proximity_query", $input);
}
else {
return $self->Call("phrase_query", $input);
}
}
=back
=head2 Phrase Query
=over 4
=item C<phrase_query>
A phrase query is the standard form of CEQL syntax. It matches a single token
described by constraints on word form, lemma and/or part-of-speech tag, a
sequence of such tokens, or a complex lexico-grammatical pattern. The
C<phrase_query> rule splits its input into whitespace-separated token
expressions, XML tags and metacharacters such as C<(>, C<)> and C<|>. Then it
applies the C<phrase_element> rule to each item in turn, and concatenates the
results into the complete CQP query.
=cut
sub phrase_query {
my ($self, $input) = @_;
# insert whitespace around phrase-level metacharacters
$input =~ s{(?<!\\)(</?[A-Za-z0-9_-]+>)}{ $1 }g; # XML tags (only standard CWB attribute names)
$input =~ s{(?<!\\)([(|])}{ $1 }g; # opening parenthesis ( and alternative marker |
$input =~ s{(?<!\\)([)][*+?{},0-9]*)}{ $1 }g; # closing parenthesis with optional quantifier (gobbles up all relevant characters to catch syntax errors)
# strip leading and trailing blanks, then split on whitespace
$input =~ s/^\s+//;
$input =~ s/\s+$//;
my @items = split " ", $input;
# apply shift-reduce parser to item sequence
my @cqp_code = $self->Apply("phrase_element", @items);
return "@cqp_code";
}
=item C<phrase_element>
A phrase element is either a token expression (delegated to rule
C<token_expression>), a XML tag for matching structure boundaries (delegated
to rule C<xml_tag>), sequences of arbitrary (C<+>) or skipped (C<*>) tokens,
or a phrase-level metacharacter (the latter two are handled by the
C<phrase_element> rule itself). Proper nesting of parenthesised groups is
automatically ensured by the parser.
=cut
sub phrase_element {
my ($self, $item) = @_;
if ($item eq "(") {
$self->BeginGroup("(...)"); # use named group to generate meaningful error messages
return "";
}
elsif ($item eq "|") {
( run in 2.519 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )