[CWB] CQPweb: help wanted for client objects
Hardie, Andrew
a.hardie at lancaster.ac.uk
Mon Jul 15 04:01:54 CEST 2019
Hi José,
Documentation is, as ever, a work in progress.
Chapter 12 of the admin manual http://cwb.sourceforge.net/files/CQPwebAdminManual.pdf is intended to be the definitive version of the API documentation, but I’ve not updated it since before the last phase of work. In particular it has nothing about the client objects since when I did the last update I’d not thought them through yet. And the function names weren’t all verb phrases at that point whereas now they are.
The list of functions, and the roadmap (ie, the parts of that list that are commented out), are visible in lib/api-lib.php in the CQPweb server code.
The idea for the client objects is that there will be individual methods for certain commonly used functions: log_in, log_out, get_version, get_cwb_version, list_api_functions,, get_api_error_info and so on.
And there will also be methods for managing the client state: the constructor (which sets the server URL), ok, set_secrets, set_corpus, get_error_code, get_error_messages … these are identically named across languages.
(Clients can have whatever private methods they like of course, e.g. the JS client object already has a couple.)
But everything else will be done via the call() method with one of the appropriate function constants
IE
Client.call(API_FUNC_FETCH_FREQLIST, [ … ])
… where the 2nd parameter is a hash of named arguments as specified by the API documentation. (Where the “hash” might be an array (PHP), dict (Python), object (JS) …)
As in the example in ch 12, the parameters and return types will be defined in a pseudo-C style, thus:
RETURN_TYPE FUNCNAME(PARAM_TYPE PARAM_NAME, …)
array list_api_functions(void)
I haven’t finished writing the call() method in PHP yet so there does not exist an illustration of how the client should construct the server call. But it will work like this:
http://server.net/cqpweb/$CORPUS/api.php?f=$FUNCTION...
… with the named function parameters appended as a sequence of &$PARAM=$ARG (with URL encoding of the $ARG value) as necessary.
The return from api.php is always a JSON string. the object structure, as created by ApiController::dispatch() in api-lib.php, is:
{
status – string “ok” or “error”
errno – integer, one of the API_ERR_ constants
// plus either (if errno != API_ERR_NONE)
errors – array of error messages
// or (if errno == API_ERR_NONE)
content – value of the return type defined for the function.
// plus possibly
user_login_token – string containing the login token for convenience (it is also sent as a cookie, but more easily accessed here)
}
…
The client object’s call() method is expected to receive and handle this object, returning just the “content” if all is OK, and otherwise storing the error code/messages appropriately within its own state variables.
Also, all clients will have access to the same set of API_FUNC_ and API_ERR_ constants that exist in the server code. I am working on automating the updating of this (via a script located alongside the client objects.)
So in short, the role of the client objects is to take away from the user the need to build up the URL and to analyse the returned JSON.
best
Andrew.
From: cwb-bounces at sslmit.unibo.it <cwb-bounces at sslmit.unibo.it> On Behalf Of José Manuel Martínez Martínez
Sent: 13 July 2019 13:19
To: Open source development of the Corpus WorkBench <cwb at sslmit.unibo.it>
Subject: Re: [CWB] CQPweb: help wanted for client objects
Hi Andrew,
thank you for your answer. I understand now better the aim and scope.
I've taken a look at the API lib, the PHP client, and the python one. Is there some documentation/example about the API, how to call the functions for instance? Are there some guidelines to keep consistent the clients across languages? Or the list of features to be implemented? Just to have an idea of the volume of work.
I find the project interesting (in fact, I was considering to write in Python a light API to interact with CQP). I'd like to contribute to the Python client and team up with whoever wants to join forces.
Cheers,
--
José Manuel Martínez Martínez
https://chozelinek.github.io
On Thu, Jul 11, 2019 at 9:57 AM Hardie, Andrew <a.hardie at lancaster.ac.uk<mailto:a.hardie at lancaster.ac.uk>> wrote:
Hi José,
The clients have their own tree in the repo, here:
https://sourceforge.net/p/cwb/code/HEAD/tree/gui/cqpweb-client/trunk/
>> Is the idea to have a client written in Python to interact with a REST API written in PHP?
Yes, except I am not sure the API will abide by the rules of REST.
To clarify: the API is accessed via an entry point within the normal CQPweb tree, at http://your.server.net/cqpweb/CORPUS/api.php . Functions can be called, and arguments sent, using GET/POST parameters on that entry point script.
The client objects are designed to be embedded into a larger software unit in the language of the user’s choice to make accessing the API less inconvenient.
That will allow other GUIs to be written that use CQPweb as a backend while handling user interaction in whatever way they like.
That’s the idea anyway; the API is not yet complete. The available functions so far can be seen at
https://sourceforge.net/p/cwb/code/HEAD/tree/gui/cqpweb/trunk/lib/api-lib.php
lines 50 thru 73.
best
Andrew.
From: cwb-bounces at sslmit.unibo.it<mailto:cwb-bounces at sslmit.unibo.it> <cwb-bounces at sslmit.unibo.it<mailto:cwb-bounces at sslmit.unibo.it>> On Behalf Of José Manuel Martínez Martínez
Sent: 07 July 2019 18:16
To: cwb at sslmit.unibo.it<mailto:cwb at sslmit.unibo.it>
Subject: Re: [CWB] CQPweb: help wanted for client objects
Hi Andrew,
this sounds interesting. But I'm not sure if I understand it. Where can I find the Python client? Is the idea to have a client written in Python to interact with a REST API written in PHP?
Cheers,
José Manuel Martínez Martínez
https://chozelinek.github.io
On 04.07.19 05:49, Hardie, Andrew wrote:
Hi all,
If you happen to be subscribed to the checkin feed for the SVN repo on sourceforge you may have noticed that I have created a number of “CQPwebClient” class definitions for different programming languages.
The idea of these is to ease use of the client API – raw API involves a lot of juggling about with GET and POST parameters. The only serious API function that is “working” theoretically at the moment is access to frequency lists. (“theoretically” because I am sure there are bugs.)
I am trying to make each client follow the same object model within the constraints of each language’s structure. The “odd one out” is the JavaScript, which is designed for asynchronous programming (As in a browser), unlike the others.
The two most complete are the JavaScript and PHP, followed by the C, the Python and the Perl. The idea is that, as far as possible, the same properties and methods should be exposed by each object model – so the sequence of calls to the client (and the parameters which need to be specified) to accomplish some task X will be the same regardless of the language.
I intend to continue to work on the JS and PHP clients myself as they are my languages of choice. (Well, actually, C is my language of choice, thus why there is a client object for C, but really it is a proof of concept rather than something I have a strong expectation of people wanting to make use of). Plus they exemplify the asynchronous/synchronous usage generally. However, for the others, having put down the rough outlines I would very much like to hand off maintenance to people who actually know what they are doing in the respective languages.
TLDR: I would be most grateful to anyone willing to volunteer to take on primary responsibility for one of the clients other than the JS and PHP versions – especially the Python, R or Perl. (BTW – the R client is just an empty file; I have no intention of actually writing it because R’s object system gives me the heebie-jeebies.)
Or if anyone would like to contribute a client object in one of the (many) languages that I’m too scared even to touch (e.g. Java, C#, Ruby, Go, Lisp, shell, Groovy, Lua, MATLAB, BASIC, INTERCAL…) then that would also be fabulous.
Anyone who is interested – just drop a note to the list. The only requirement is that you must be happy for your contributions to be released open source (with an MIT style licence).
Thanks in advance!
best
Andrew.
_______________________________________________
CWB mailing list
CWB at sslmit.unibo.it<mailto:CWB at sslmit.unibo.it>
http://liste.sslmit.unibo.it/mailman/listinfo/cwb
_______________________________________________
CWB mailing list
CWB at sslmit.unibo.it<mailto:CWB at sslmit.unibo.it>
http://liste.sslmit.unibo.it/mailman/listinfo/cwb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://liste.sslmit.unibo.it/pipermail/cwb/attachments/20190715/a9ad9387/attachment-0001.html>
More information about the CWB
mailing list