14.6.11. crate_anon.nlp_webserver.tasks
crate_anon/nlp_webserver/tasks.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/>.
Tasks to process text for an NLPRP server (and be scheduled via Celery).
- crate_anon.nlp_webserver.tasks.gate_api_error(msg: str, processor: ServerProcessor | None = None) Dict[str, str | int | float | bool | None | Dict | List] [source]
Return a “GATE failed” error.
- Parameters:
msg – description of the error
processor – the
Processor
object to be used
- crate_anon.nlp_webserver.tasks.get_gate_results(results_dict: Dict[str, str | int | float | bool | None | Dict | List]) List[str | int | float | bool | None | Dict | List] [source]
Convert results in GATE JSON format to results in our internal format.
- Parameters:
results_dict – see
crate_anon.nlp_manager.constants.GateApiKeys
or https://cloud.gate.ac.uk/info/help/online-api.html- Returns:
list of dictionaries; see
crate_anon.nlp_manager.constants.GateApiKeys
- crate_anon.nlp_webserver.tasks.internal_error(msg: str, processor: ServerProcessor | None = None) Dict[str, str | int | float | bool | None | Dict | List] [source]
Log an error message, and raise a corresponding
NlprpError
for an internal server error.- Parameters:
msg – the error message
processor – the
Processor
object to be used
- crate_anon.nlp_webserver.tasks.nlprp_processor_dict(success: bool, processor: ServerProcessor | None = None, results: List[str | int | float | bool | None | Dict | List] | None = None, errcode: int | None = None, errmsg: str | None = None) Dict[str, str | int | float | bool | None | Dict | List] [source]
Returns a dictionary suitable for use as one of the elements of the
response["results"]["processors"]
array; see NLPRP.- Parameters:
success – did the request succeed?
processor – a
crate_anon.nlp_webserver.procs.Processor
, orNone
results – a JSON array of results
errcode – (if not
success
) an integer error codeerrmsg – (if not
success
) an error message
- Returns:
a JSON object in NLPRP format
- crate_anon.nlp_webserver.tasks.process_nlp_gate(text: str, processor: ServerProcessor, username: str, password: str) Dict[str, str | int | float | bool | None | Dict | List] [source]
Send text to a chosen GATE processor (via an HTTP connection, using the GATE JSON API; see https://cloud.gate.ac.uk/info/help/online-api.html).
- Parameters:
text – text to run the NLP over
processor – NLP processor; a class:crate_anon.nlp_webserver.procs.Processor
username – username in use
password – plaintext password
- Returns:
a
NlpServerResult
API failure is handled by returning a failure code/message to our client.
- crate_anon.nlp_webserver.tasks.process_nlp_internal(text: str, processor: ServerProcessor) Dict[str, str | int | float | bool | None | Dict | List] [source]
Send text to a chosen CRATE Python NLP processor and return a
NlpServerResult
.
- crate_anon.nlp_webserver.tasks.process_nlp_text_immediate(text: str, processor: ServerProcessor, username: str = '', password: str = '') Dict[str, str | int | float | bool | None | Dict | List] [source]
Function to send text immediately to the relevant processor.
- Parameters:
text – text to run the NLP over
processor – NLP processor; a class:crate_anon.nlp_webserver.procs.Processor
username – username in use
password – plaintext password
- Returns:
a
NlpServerResult