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) TextlabResult [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 textlab result including score and feedback, or None if an error occurred
- Return type:
- 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:
- integreat_cms.textlab_api.utils.dict_path(data: dict, path: list[str]) Any [source]
Resolves a path in the given data dictionary and returns the value :param data: The data dictionary to get the value from :param path: The path to lookup :return: The result of the lookup in the dictionary