This project is a tool to quickly check German texts for compliance with the rules for plain language ("Einfache Sprache") according to the "Handbuch einfache Sprache, 2022 edition".
At the moment, the tool can check for compliance with the following of those rules:
- Keine Verneinung mit "nicht" (no negation using the word "nicht")
- Keine Konjunktive (no subjunctive)
- Nur Punkt, Komma, und Doppelpunkt als Satzzeichen (only ".", ",", and ":" for punctuation)
- Zahlen immer als Ziffer (writing numbers as numbers and not as words)
- einfacher Wortschatz (only using simple words, the tool allows for selection of the language levels A1, A2, or B1 by the Goethe Institut to check if easy enough words are used)
The project follows a client-server architecture, with the React frontend making requests to the Python Flask backend using HTTP.
For the text analysis the project uses spaCy.io, a free open-source library for Natural Language Processing in Python.
Main component, responsible for rendering the UI and handling user interactions.
The useState
hook is used to declare and initialize state variables in the App component. The following state variables are used:
-
textInput
: Holds the current user input in the text input field. -
textResult
: Holds an array of text highlights generated by the language analysis. -
checks
: Holds an array of language checks to be displayed in the analysis results. -
loading
: Holds a boolean value indicating whether a language analysis is currently being performed.
The useEffect
hook is used to fetch the initial set of language checks and highlights from the server when the component mounts. It runs only once when the component is mounted.
The runChecks method is called when the user submits a text for analysis. It performs a POST request to the server with the text input and selected level of analysis, and sets the state variables based on the response.
The render method returns the UI elements of the App component. These include:
- A header element with the title of the application.
- A section element with the TextInput component, which allows the user to input text for analysis, and an AnalysisResult component, which displays the language checks and highlights.
- A Footer component at the bottom of the page.
Props: onSend
(method), submittedText
(string), highlights
(object)
Description: Renders a form with language level select, a contenteditable to allow users to input text and a button to submit it for checking. Also renders the submitted text and highlights specific words based on the highlights passed as a prop.
Props: check
(object)
Description: Renders a listItem displaying the name of the check and if it's passed or failed
Props: checks
(list of objects)
Description: Renders the list of checks, using check.name
as key prop to ensure that each Check component is uniquely identified by its name.
Props: none
Description: Renders a footer for the application
Method: GET
, POST
Input parameters: text
, level
Output format: JSON,
response_body = { "checks": text_check_results, "text": text, "highlights": text_to_highlight }
-
key
checks
: a list of Check objects{'name': 'check name', 'result': 'pass or fail'}
-
key
text
: normalized string of the submitted text -
key
highlights
: list of two main objects, index- and character-based highlights
a. keyindex-based
: contains objects for highlights based on their text-index, format{'highlight name': [list of tuples with start and end indeces]}
b. key
character-based
: contains objects for highlights based on complete word lookup, format{'highlight name': ['list', 'of', 'strings', 'to', 'highlight']}
Description: Returns a JSON response with text checks, the submitted text, and information on what text to render highlighted
To run tests for the project, navigate to the respective folder and use the following commands:
Frontend: yarn test
Launches the test runner in the interactive watch mode. See the section about running tests for more information.
Backend: pytest
For more detailed logging use pytest -vv