| | from fastapi import FastAPI, Query, HTTPException, Request |
| | from typing import Optional |
| | from modules.language_processing.language_components import * |
| |
|
| |
|
| | from testing_env.api_key import Api_key |
| |
|
| | from nltk import sent_tokenize |
| | import re |
| | import language_tool_python |
| |
|
| | app = FastAPI() |
| |
|
| | @app.get("/") |
| | async def root(): |
| | return {"message": "TxT-Jur API access"} |
| |
|
| | @app.get("/check/{text}") |
| | async def read_text(text): |
| | try: |
| | splitter = LanguageComponentSplitter() |
| | sentences = splitter.split_sentences(text) |
| | utilities = Utilities() |
| | res = utilities.correct_json_sentence_split(sentences) |
| | return res |
| | except Exception as e: |
| | return str(e) |
| |
|
| |
|
| | @app.get("/correct/{text}") |
| | async def correct_text(text): |
| | try: |
| | splitter = LanguageComponentSplitter() |
| | sentences = splitter.split_sentences(text) |
| | utilities = Utilities() |
| | corrected_text = utilities.text_to_display(sentences) |
| | return corrected_text |
| | except Exception as e: |
| | return str(e) |
| |
|
| |
|
| | @app.get("/summarize_text", status_code=200) |
| | def summarize(text: Optional[str] = Query(None, title="Sentence", description = "The sentence to summarize")): |
| | id = 0 |
| | res = {} |
| | try: |
| | splitter = LanguageComponentSplitter() |
| | sentences = splitter.split_sentences(text) |
| | ort = Ortography_checker() |
| | for sentence in sentences: |
| | corrected_split = {'raw':sentence,'summarized':ort.check_spell(sentence)[1]} |
| | res[id] = corrected_split |
| | id += 1 |
| | return res |
| | except: |
| | return "not found" |
| |
|