[CWB] multiple commands with WebCqp::Query

Stefan Evert stefan.evert at uos.de
Wed Aug 16 16:20:54 CEST 2006


Hi everybody!

Sorry I couldn't answer your question earlier, but I was just too  
busy at ESSLLI. Good to see that you've managed to work your way  
around these problems.

I didn't notice at first that your script uses the WebCqp::Query  
module, which it shouldn't.  WebCqp::Query is fairly old legacy code  
that was intended to provide a convenient interface for simple CGI  
scripts.  It does quite a lot of post-processing on the CQP query  
results and may run its own setup code.  While you can still use it  
to execute plain CQP commands, this is an inefficient and unstable  
approach.

Instead, you should directly use the CQP module ("use CQP"), which  
provides the exec() and query() methods that you've used in your  
solution below.  In the testsuite, there is no need to use the query 
() method (except if you want to test the query lock mechanism  
itself, but since it's main purpose is to fail if you attempt a lock  
violation, it can only be tested by an advanced solution that can  
handle a CQP that dies suddenly). Simply capture the output of _any_  
CQP command with

@lines = $cqp->exec("....");

Note that running a query won't produce any output when CQP is in  
child mode, so you have to "cat" the matches explicitly (but you  
could also "dump" them or do frequency counts instead).  Like so:

$cqp->exec("A = $query");
@results = $cqp->exec("cat A");

Are you aware of the very useful idiom

($no_of_matches) = $cqp->exec("size A")

?

Hope this helps & best wishes,
Stefan

PS: Do we need a README guide around the CWB/Perl modules which  
explains when you'll be wanting to use which modules, and which  
modules you shouldn't use in the first place?



On 9 Aug 2006, at 13:44, Lars Nygaard wrote:

> I earlier asked a question on how to use multiple commands in the  
> perl interface. After poking about in the modules, I discovered  
> that the way to do this. Since it wasn't obvious to me (though it  
> might have been for others ...), the solution is reproduced here:
>
>
>  $q->exec(  ... first command ...    );
>  $q->exec(  ... second command ...    );
>  ...
>  @results = $q->query(   ... command producing kwic lines ...);
>
>
> cheers,
> lars
>
> PS: Did any of you get a chance to look at the script for running  
> test suites?
>
> _______________________________________________
> CWB mailing list
> CWB at sslmit.unibo.it
> http://devel.sslmit.unibo.it/mailman/listinfo/cwb
>



More information about the CWB mailing list