File size: 1,584 Bytes
aaaff44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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"