A tool for generating and annotating Czech language examples for training a grammar checker Opravidlo 2.0.
Opravidlo Annotations is designed to help create annotated examples of Czech language phenomena by:
- Fetching concordances (text examples) from corpus query systems (Kontext and Sketch Engine)
- Processing these examples to extract relevant sentences
- Annotating the sentences to highlight specific language phenomena
- Saving the annotated examples in text and Word formats with accompanying logs of queries
The project is organized into several modules:
main.py: The entry point for the application, containing configuration for queriescore/generate_concordances.py: Handles fetching concordances from corpus query systemscore/concordance2annotation.py: Processes concordances and adds annotations
api/kontext.py: Interface for the Kontext corpus query systemapi/sketch_engine.py: Interface for the Sketch Engine corpus query system
utils/utils.py: General utility functions for file handling and text processingutils/query_logs.py: Functions for logging queries and generating documentation
settings.py: Contains configuration settings, including API tokens and file paths
-
Install the required dependencies:
pip install -r requirements.txt -
Set up environment variables for API access:
- Create a
.envfile in the project root - Add your API tokens:
KONTEXT_TOKEN=your_kontext_token SKETCH_ENGINE_TOKEN=your_sketch_engine_token SKETCH_ENGINE_USERNAME=your_sketch_engine_username
- Create a
-
Configure your query in
main.py:# Set corpus manager and corpus name corpus_manager = "kontext" # Options: "kontext", "sketch", "combo" corpus_name = "syn2020" # Corpus name depends on the manager # Define target word and its variants target = "jejích" variants = ["jejich"] is_target_valid = False # Is the target orthographically correct? # Define the corpus query query = '[lemma="jejích" & tag=".*"]' # Set number of concordances to fetch number_of_concordances_to_fetch = 80 number_of_concordances_to_log = 10 # Set output filename filename = "jejích_jejich"
-
Run the script:
python -m opravidlo_annotations.main -
The script will:
- Fetch concordances from the specified corpus
- Process and annotate the concordances
- Save the results to text and Word files
- Generate documentation of queries in JSON and text formats
The annotated sentences will be in the format:
Beginning of the sentence [*error|correct|corpus*] rest of the sentence.
For example:
Stál před [*jejích|jejich|corpus*] chalupou.
- Use the
combocorpus manager to fetch examples from multiple corpora - Customize annotation format by modifying the
add_annotation_to_sentencefunction - Create custom target variant constructors for complex language phenomena
- Set up a query for a specific language phenomenon
- Run the script to generate annotated examples
- Review the examples in the generated text or Word files
- Use the check function to verify the distribution of variants
- Use the generated examples as training data for Opravidlo 2.0