graphai.api.text.router module

async graphai.api.text.router.keywords(data: KeywordsRequest, use_nltk: bool | None = False)

Processes raw text (e.g. from an abstract of a publication, a course description or a lecture slide) and returns a list of keywords from the text.

async graphai.api.text.router.wikify(data: WikifyFromRawTextRequest | WikifyFromKeywordsRequest, method: str | None = 'es-base', restrict_to_ontology: bool | None = False, score_smoothing: bool | None = True, aggregation_coef: float | None = 0.5, filtering_threshold: float | None = 0.15, refresh_scores: bool | None = True)

Processes raw text (e.g. from an abstract of a publication, a course description or a lecture slide) and returns a list of concepts (Wikipedia pages) that are relevant to the text, each with a set of scores in [0, 1] quantifying their relevance. This is done as follows:

  1. Keyword extraction: Automatic extraction of keywords from the text. Omitted if a list of strings is provided as input

    under “keywords” instead of “raw_text”.

  2. Wikisearch: For each set of keywords, a set of at most 10 concepts (Wikipedia pages) is retrieved. This can be

    done through requests to the Wikipedia API or through elasticsearch requests.

  3. Scores: For each pair of keywords and concept, several scores are derived, taking into account the concepts graph,

    the ontology and embedding vectors, among others.

  4. Aggregation and filter: For each concept, their scores are aggregated and filtered according to some rules,

    to keep only the most relevant results.

Several arguments can be passed to have a more precise control: * method (str): Method to retrieve the concepts (Wikipedia pages). It can be either ‘wikipedia-api’, to use the Wikipedia API, or one of {‘es-base’, ‘es-score’}, to use elasticsearch. Default: ‘es-base’. * restrict_to_ontology (bool): Whether to filter concepts that are not in the ontology. Default: False. * score_smoothing (bool): Whether to apply a transformation to some scores to distribute them more evenly in [0, 1]. Default: True. * aggregation_coef (float): A number in [0, 1] that controls how the scores of the aggregated pages are computed. A value of 0 takes the sum of scores over Keywords, then normalises in [0, 1]. A value of 1 takes the max of scores over Keywords. Any value in between linearly interpolates those two approaches. Default: 0.5. * filtering_threshold (float): A number in [0, 1] that is used as a threshold for all the scores to decide whether the page is good enough from that score’s perspective. Default: 0.15. * refresh_scores (bool): Whether to recompute scores after filtering. Default: True.

async graphai.api.text.router.wikify_ontology_svg(results: List[WikifyResponseElem], level: int | None = 2)

Returns a svg file representing the ontology subgraph induced by the provided set of results.

async graphai.api.text.router.wikify_graph_svg(results: List[WikifyResponseElem], concept_score_threshold: float | None = 0.3, edge_threshold: float | None = 0.3, min_component_size: int | None = 3)

Returns a svg file representing the graph subgraph induced by the provided set of results.

async graphai.api.text.router.generate_exercise(data: GenerateTextExerciseRequest | GenerateLectureExerciseRequest)

Makes a request to the Chatbot API to generate an exercise.