Alvis-QueryFilter
view release on metacpan or search on metacpan
lib/Alvis/QueryFilter.pm view on Meta::CPAN
use CQL::Parser;
use URI::Escape;
use strict;
our $VERSION = '0.3';
our $verbose = 0;
my ($ERR_OK,
$ERR_CQL_PARSER_INST,
$ERR_XML_PARSER,
$ERR_NO_QUERY,
$ERR_CQL_PARSE,
$ERR_NONIMP_NODE_TYPE,
$ERR_NO_SEQ_LIST,
$ERR_TREETAGGER,
$ERR_LEMMA_DICT,
$ERR_APPLYING_TERM_NE,
$ERR_APPLYING_TYPING,
$ERR_APPLYING_ONTO,
$ERR_STRUCT2XML,
$ERR_CREATING_CAT_LIST,
$ERR_CREATING_SEQ_LIST,
$ERR_CREATING_CQL_TAIL,
$ERR_NEED_BOTH_TERM_AND_NE
)=(0..16);
my %ErrMsgs=($ERR_OK=>"",
$ERR_CQL_PARSER_INST=>"Instantiating CQL::Parser failed.",
$ERR_XML_PARSER=>"Instantiating the XML parser failed.",
$ERR_NO_QUERY=>"No query.",
$ERR_CQL_PARSE=>"CQL parsing failed.",
$ERR_NONIMP_NODE_TYPE=>'Non-implemented CQL node type.',
$ERR_NO_SEQ_LIST=>
"No current data structure representing the " .
"query expansion. No preceding UI2Zebra() " .
"call or we're out of sync. You'll get your " .
"money back.",
$ERR_TREETAGGER=>"Applying the treetagger failed.",
$ERR_LEMMA_DICT=>"Applying the lemma dictionary failed.",
$ERR_APPLYING_TERM_NE=>"Applying the terms and NEs failed.",
$ERR_APPLYING_TYPING=>"Applying the typing rules failed.",
$ERR_APPLYING_ONTO=>"Applying the ontology mappings failed.",
$ERR_STRUCT2XML=>"Converting the data structure into XML failed.",
$ERR_CREATING_CAT_LIST=>
"Extracting category part of query failed.",
$ERR_CREATING_SEQ_LIST=>
"Creating the list of possible expansions failed.",
$ERR_CREATING_CQL_TAIL=>"Converting the data structure to a CQL " .
"tail failed.",
$ERR_NEED_BOTH_TERM_AND_NE=>"We need both a term and a NE dictionary."
);
sub new
{
my $proto=shift;
my $class=ref($proto)||$proto;
my $parent=ref($proto)&&$proto;
my $self={};
bless($self,$class);
$self->_set_err_state($ERR_OK);
$self->_init(@_);
$self->{CQLParser}=new CQL::Parser();
if (!defined($self->{CQLParser}))
{
$self->_set_err_state($ERR_CQL_PARSER_INST);
return undef;
}
$Alvis::Treetagger::verbose = $verbose;
&Alvis::Treetagger::reopen();
$self->{termMaxLen} = 0;
$self->{textFields} = "text";
$self->{tcanon} = \&canonise_def;
$self->{ncanon} = \&canonise_def;
# this must match the lemma indexing rules in alvis2index.xsl
$self->{lemmaSearch} = "^[VNJ]";
return $self;
}
sub _init
{
my $self=shift;
$self->{keepLemmas}=1;
if (defined(@_))
{
my %args=@_;
@$self{ keys %args }=values(%args);
}
}
sub _set_err_state
{
my $self=shift;
my $errcode=shift;
my $errmsg=shift;
if (!defined($errcode))
{
confess("set_err_state() called with an undefined argument.");
}
if (exists($ErrMsgs{$errcode}))
{
if ($errcode==$ERR_OK)
{
$self->{errstr}="";
}
else
{
$self->{errstr}.=" " . $ErrMsgs{$errcode};
if (defined($errmsg))
( run in 2.144 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )