# keivanm/wikipedia-text-generation architecture

> Architecture diagram of the GitHub repository keivanm/wikipedia-text-generation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keivanm/wikipedia-text-generation
- Repository: https://github.com/keivanm/wikipedia-text-generation

## Overview

##### Main Components
- User Interface/Input: The command-line interface where the user supplies the urban area name (or triggers the generation of text for multiple areas).
- Python Application Layer: This includes the Python scripts (linkoping.py, linkoping100.py, linkoping100_2.py) that parse input, control the flow, and interact with the PGF library.
- GF Grammar Modules: The GF source files (linkoping.gf, linkopingEng.gf, linkopingFre.gf, linkopingSwe.gf) define the grammatical structure used for text generation.
- PGF Component: The compiled output of the GF grammar (linkoping.pgf) that the Python code loads via the PGF library (installed via pip).

##### Relationships and Interactions
- When a user runs a Python script (for example, linkoping.py with "Stockholm" as a parameter), the Python application:
- Reads the input.
- Loads the PGF file (linkoping.pgf) that was compiled from the GF source.
- Uses the PGF library to process the grammar rules.
- Generates the text based on the input urban area.
- For generating texts for multiple urban areas, one of the Python scripts (linkoping100_2.py) iterates over a list of urban areas and handles potential data inconsistencies.
- The GF files are independent modules that can be modified and recompiled to update the grammatical rules, which then change the output of the Python scripts.

##### Important Architectural Patterns / Design Principles
- Separation of Concerns: The architecture clearly separates grammar definition (GF files) from the application logic (Python scripts).
- Modularity: Different scripts handle one-instance and batch operations.
- Dependency on External Libraries: The system relies on the PGF library in Python to interface with the GF grammar.

##### Relevant Technologies and Frameworks
- Programming Languages: Python (for scripting) and GF (a specialized language for grammars).
- Libraries: PGF library (Python package for handling PGF grammars).
- Deployment/Execution Context: Command-line driven for executing text generation.

##### Additional Details
- Mention potential error handling in the batch operation script (linkoping100_2.py) for inconsistencies in the queried data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UCI("User CLI"):::cli

    subgraph "Python Application Layer"
        p1("linkoping.py"):::python
        p2("linkoping100.py"):::python
        p3("linkoping100_2.py"):::python
    end

    pcomp("PGF Component"):::pgf

    subgraph "GF Grammar Modules"
        gf1("linkoping.gf"):::gf
        gf2("linkopingEng.gf"):::gf
        gf3("linkopingFre.gf"):::gf
        gf4("linkopingSwe.gf"):::gf
    end

    OUT("Generated Text"):::output

    UCI -->|"supplies_input"| p1
    UCI -->|"supplies_input"| p2
    UCI -->|"supplies_input"| p3

    p1 -->|"loads_grammar"| pcomp
    p2 -->|"loads_grammar"| pcomp
    p3 -->|"loads_grammar"| pcomp

    gf1 -->|"compiled_into"| pcomp
    gf2 -->|"compiled_into"| pcomp
    gf3 -->|"compiled_into"| pcomp
    gf4 -->|"compiled_into"| pcomp

    pcomp -->|"processes_grammar"| OUT

    classDef cli fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef python fill:#ABEBC6,stroke:#138D75,stroke-width:2px;
    classDef gf fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef pgf fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef output fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;

    click p1 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkoping.py"
    click p2 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkoping100.py"
    click p3 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkoping100_2.py"
    click gf1 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkoping.gf"
    click gf2 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkopingEng.gf"
    click gf3 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkopingFre.gf"
    click gf4 "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkopingSwe.gf"
    click pcomp "https://github.com/keivanm/wikipedia-text-generation/blob/main/linkoping.pgf"
```
