# hltcoe/predpatt architecture

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

- Interactive diagram: https://gitdiagram.com/hltcoe/predpatt
- Repository: https://github.com/hltcoe/predpatt

## Overview

##### Main Components
- Core Extraction Library ("predpatt" directory):
- This contains modules such as UDParse.py, patt.py, rules.py, and util files (e.g., UDParser.py and others). These files encapsulate the main functionality for processing Universal Dependencies and executing predicate-argument extraction.
- REST API Layer ("api/rest" directory):
- Contains app.py, Dockerfile, and parsing script (ParseyPredFace.py) which likely wraps the core library into a web service.
- This layer is designed to expose the core functionalities as RESTful endpoints, making them easily accessible to external applications.
- Command-line / Server Interface ("bin" directory):
- The server.py script here may be used to run the application in a command-line mode or serve as a lightweight server, providing another mode of interaction with the core functionality.
- Testing and Documentation:
- The "test" directory, with various conllu and expect files and notebook examples, shows that there is a robust test suite ensuring accuracy and gives usage examples.
- The "doc" directory and "tutorial.ipynb" provide extensive documentation and usage guidelines.
- Configuration and Setup:
- Files like setup.py and the LICENSE/README at the top level help in configuring and distributing the project.

##### Relationships and Interactions
- The REST API (api/rest) acts as an intermediary between external requests and the core processing logic in the "predpatt" module.
- The command-line interface (bin/server.py) provides an entry point that, like the API, leverages the core extraction functions.
- The core library is the heart of the system and is designed for extensibility; its outputs are used by both the API and CLI modes.
- Testing and documentation components ensure that the correct function of these layers is maintained and demonstrate usage.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into a core library ("predpatt"), REST API layer, and CLI layer shows a clear separation of concerns.
- Extensibility: The core extraction engine is designed with extensible, interpretable rules – it allows for further layers of semantic annotation.
- Reusability: The same extraction functions are used in multiple interfaces (API, command-line), emphasizing code reuse.
- Containerization: The presence of Dockerfile under the API directory suggests that containerized deployment was considered for easy distribution and environment management.

##### Relevant Technologies and Frameworks
- Primary Language: Python.
- Web Framework: Likely Flask or a similar lightweight framework (inferred from app.py in the API directory).
- Containerization: Docker (as indicated by the Dockerfile).
- Testing Tools and Notebook: Python tests and the Jupyter Notebook (tutorial.ipynb) for interactive demonstration.
- Standard scripting practices via server scripts and setup files.

##### Elements
- Core Extraction Module (predpatt) – label submodules such as UD parsing, rule processing, and utility functions.
- REST API Service – include Docker container depiction, API entry point (app.py), and parsing interface (ParseyPredFace.py).
- Command-line Interface/Server (bin/server.py) – a separate node for CLI operations.
- Visual Differentiations:

##### Putting It All Together
– From the user's perspective, inputs travel from network requests or command-line commands into these interfaces.
– Include external dependencies like Docker for containerized deployment.
– Finally, note that extensive tests and documentation support the overall system and should be referenced as part of the development and verification process.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interfaces
    subgraph "External Interfaces"
        APIReq["API_Request"]:::external
        CLIReq["CLI_Command"]:::external
    end

    %% Service Layer
    subgraph "Service Layer"
        RESTAPI["REST_API_Service"]:::api
        CLI["CLI_Interface"]:::cli
    end

    %% Core Processing Layer
    subgraph "Core Processing"
        CoreExtraction["Core_Extraction_Library"]:::core
    end

    %% Supporting Components
    subgraph "Supporting Components"
        Testing["Testing_Suite"]:::test
        Documentation["Documentation"]:::docs
        Tutorial["Tutorial_Notebook"]:::docs
        Configuration["Configuration_&_Setup"]:::config
    end

    %% Data Flows
    APIReq -->|"calls"| RESTAPI
    CLIReq -->|"issues"| CLI
    RESTAPI -->|"invokes"| CoreExtraction
    CLI -->|"invokes"| CoreExtraction
    CoreExtraction -->|"returns"| RESTAPI
    CoreExtraction -->|"returns"| CLI
    CoreExtraction ---|"verified by"| Testing
    CoreExtraction ---|"guided by"| Documentation
    Documentation ---|"supplemented by"| Tutorial
    Documentation ---|"configured by"| Configuration

    %% Click Events
    click CoreExtraction "https://github.com/hltcoe/predpatt/tree/master/predpatt/"
    click RESTAPI "https://github.com/hltcoe/predpatt/tree/master/api/rest/"
    click CLI "https://github.com/hltcoe/predpatt/blob/master/bin/server.py"
    click Testing "https://github.com/hltcoe/predpatt/tree/master/test/"
    click Documentation "https://github.com/hltcoe/predpatt/tree/master/doc/"
    click Tutorial "https://github.com/hltcoe/predpatt/blob/master/tutorial.ipynb"
    click Configuration "https://github.com/hltcoe/predpatt/blob/master/setup.py"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef cli fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef test fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef docs fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#F5DEB3,stroke:#000,stroke-width:2px;
```
