14.6.14. crate_anon.nlp_webserver.views
crate_anon/nlp_webserver/views.py
Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CRATE.
CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.
Pyramid views making up the CRATE NLPRP web server.
- class crate_anon.nlp_webserver.views.NlpWebViews(request: Request)[source]
Class to provide HTTP views (via Pyramid) for our NLPRP server.
- check_token() bool [source]
Checks to see if the user has given the correct token for the current session connected to their username.
- create_error_response(error: NlprpError) Dict[str, str | int | float | bool | None | Dict | List] [source]
Returns an HTTP response for a given error and description of the error
- create_response(status: int, extra_info: Dict[str, str | int | float | bool | None | Dict | List] | None = None) Dict[str, str | int | float | bool | None | Dict | List] [source]
Returns a JSON HTTP response with some standard information for a given HTTP status and extra information to add to the response.
Ensures the HTTP status matches the NLPRP JSON status.
- delete_from_queue() Dict[str, str | int | float | bool | None | Dict | List] [source]
Deletes from the queue all entries specified by the client.
- fetch_from_queue() Dict[str, str | int | float | bool | None | Dict | List] [source]
Fetches requests for all document-processor pairs for the queue_id supplied by the user (if complete).
- handle_nlprp_request() Dict[str, str | int | float | bool | None | Dict | List] [source]
The main function. Authenticates user and checks the request is not malformed, then calls the function relating to the command specified by the user.
- index() Dict[str, str | int | float | bool | None | Dict | List] [source]
The top-level “index” view. Passes all the work to
handle_nlprp_request()
, except for error handling.
- list_processors() Dict[str, str | int | float | bool | None | Dict | List] [source]
Returns an HTTP response listing the available NLP processors.
- parse_command(command: str) Dict[str, str | int | float | bool | None | Dict | List] [source]
Parse the NLPRP command.
- process_now(process_request: NlprpProcessRequest) Dict[str, str | int | float | bool | None | Dict | List] [source]
Processes the text supplied by the user immediately, without putting it in the queue.
- Parameters:
process_request – a
NlprpProcessRequest
- put_in_queue(process_request: NlprpProcessRequest) Dict[str, str | int | float | bool | None | Dict | List] [source]
Puts the document-processor pairs specified by the user into a celery queue to be processed.
- Parameters:
process_request – a
NlprpProcessRequest
- class crate_anon.nlp_webserver.views.NlprpProcessRequest(nlprp_request: Dict[str, str | int | float | bool | None | Dict | List])[source]
Represents an NLPRP process command. Takes the request JSON, and offers efficient views on it.
Uses the global
crate_anon.nlp_server.procs.Processors
class to find processors.- __init__(nlprp_request: Dict[str, str | int | float | bool | None | Dict | List]) None [source]
- Parameters:
nlprp_request – dictionary from the (entire) JSON NLPRP request
- Raises:
NlprpError –
- gen_text_metadataobj() Generator[Tuple[str, str | int | float | bool | None | Dict | List], None, None] [source]
Generates text and metadata pairs from the request, with the metadata in JSON object (Python dictionary) format.
- Yields:
tuple –
(text, metadata)
, as above