[CWB] CWB::CQP - adding easy of use

Alberto Simões ambs at di.uminho.pt
Tue Mar 30 21:56:57 CEST 2010


Dear all,
and especially Stefan,

CWB::CQP is the base to interact with CQP, and it works greatly. But I
think some usability can be added.

I though of adding them and send a patch, but no sure if it will be
accepted, and given I intend to use this new functionality, I need to
know if I should go for the patch or for a personal module using CWB::CQP.

I will be happy to provide patches for any of the two suggestions
bellow. Just poke me!


Enough of talk. Code!

1) while exec allows to do anything, shortcuts will be great:
     @corpora = $cqp->show_corpora()  # or list_corpora
     $cqp->set(LEFTKWICDelim => '<b>', RightKWICDelim => '</b>');

2) while the $cqp->ok method is enough, with the Try::Tiny module things
could get a lot cleaner.

      sub exec {
          my ($self, @args) = @_;
          my $answer = $self->old_exec(@args);
          die ($self->error_message) unless $self->ok;
          return $answer;
      }

and the user would use eval around it, or,


      use Try::Tiny;
      use CWB::CQP;

      try {
         $cqp->exec("...");
      } catch {
         print "ERROR: $_" # $_ gets the die message.
      }

Of course Try::Tiny supports other constructs but not relevant at the
moment.



-- 
Alberto Simões


More information about the CWB mailing list