Textlab API
Apps
Textlab API Client
- class integreat_cms.textlab_api.textlab_api_client.TextlabClient(username: str, password: str)[source]
Bases:
object
Client for the textlab api. Supports login and hix-score retrieval.
A detailed API documentation can be found at https://comlab-ulm.github.io/swagger-V8/
- benchmark(text: str, text_type: int = 420) float | None [source]
Retrieves the hix score of the given text.
- Parameters:
text (str) – The text to calculate the score for
text_type (int) – The id of the text type (“Textsorte”) or, in terms of the api, benchmark to query. A benchmark is a pre-defined set of modules producing various metrics. They can have threshold/target values, depending on the type of text the benchmark is trying to represent. The available text types activated for the logged in account can be queried by sending a simple GET request to the
/benchmark
endpoint, complete with all metrics that get included for it. You can find the not so helpful API “documentation” here: https://comlab-ulm.github.io/swagger-V8/ But since for now we are only interested in the HIX score anyway, we just use the benchmark “Letter Demo Integreat” with ID420
by default.
- Returns:
The score, or None if an error occurred
- Return type:
float | None
- login() None [source]
Authorizes for the textlab api. On success, sets the token attribute.
- Raises:
urllib.error.HTTPError – If the login was not successful
- Return type:
None
Utils
This module contains helpers for the TextLab API client
- integreat_cms.textlab_api.utils.check_hix_score(request: HttpRequest, source_translation: EventTranslation | PageTranslation | POITranslation, show_message: bool = True) bool [source]
Check whether the required HIX score is met and it is not ignored
- Parameters:
request (HttpRequest) – The current request
source_translation (EventTranslation | (PageTranslation | POITranslation)) – The source translation
show_message (bool) – whether the massage should be shown to users.
- Returns:
Whether the HIX constraints are valid
- Return type: