# royashcenazi/parsigs architecture

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

- Interactive diagram: https://gitdiagram.com/royashcenazi/parsigs
- Repository: https://github.com/royashcenazi/parsigs

## Overview

##### Main Components

a) Core Processing Pipeline:
- Input Layer (Raw Sig Text)
- NER Model Layer
- Rule-Based Processing Layer
- Structured Output Layer

b) Supporting Components:
- Resource Management System (for drug_names.txt and latin_frequency.json)
- Testing Framework
- Research/Training Infrastructure

**[Raw Sig Text Input] → [NER Processing] → [Rule-Based Processing] → [Structured Output]**

##### Specific Implementation Details

a) Data Flow:
- How the SigParser class (parse_sig_api.py) orchestrates the processing
- How the StructuredSig object is populated
- Demonstrate resource file utilization

b) Component Integration:
- Integration with SpaCy NER model
- Configuration management (config files in research/config)
- Testing framework integration

##### Key Architectural Elements

Specific components:
**[Resource Management]**
- Drug Names Database
- Latin Frequency Dictionary

**[Core Parser]**
- NER Model
- Rule Engine
- Attribute Extractor

**[Output Structure]**
- StructuredSig Object
- Drug Information
- Dosage Details
- Frequency Data
- Period Information

##### Technical Details to Highlight

- Privacy-first architecture (no external APIs)
- Model training pipeline
- Configuration management
- Test coverage integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        RawText[Raw Sig Text]:::input
    end

    subgraph CoreProcessing
        Parser["Core Parser"]:::core
        click Parser "https://github.com/royashcenazi/parsigs/blob/master/parsigs/parse_sig_api.py"
        
        subgraph Resources
            DrugDB["Drug Names Database"]:::resource
            click DrugDB "https://github.com/royashcenazi/parsigs/blob/master/parsigs/resources/drug_names.txt"
            LatinDict["Latin Frequency Dictionary"]:::resource
            click LatinDict "https://github.com/royashcenazi/parsigs/blob/master/parsigs/resources/latin_frequency.json"
        end

        subgraph NER
            SpacyNER["SpaCy NER Model"]:::model
            EntityRecog["Entity Recognition"]:::process
        end

        subgraph RuleEngine
            StaticRules["Static Rules Engine"]:::process
            PatternMatch["Pattern Matching"]:::process
            AttrExtract["Attribute Extraction"]:::process
        end
    end

    subgraph Research
        direction TB
        Training["Training Infrastructure"]:::research
        click Training "https://github.com/royashcenazi/parsigs/blob/master/research/dosage_instructions_ner.ipynb"
        BERTTraining["BERT Training"]:::research
        click BERTTraining "https://github.com/royashcenazi/parsigs/blob/master/research/dosage_instructions_ner_bert.ipynb"
        DataPrep["Data Preprocessing"]:::research
        click DataPrep "https://github.com/royashcenazi/parsigs/blob/master/research/pre_process_data.py"
        
        subgraph Config
            BaseConfig["Base Config"]:::config
            click BaseConfig "https://github.com/royashcenazi/parsigs/blob/master/research/config/config.cfg"
            BERTConfig["BERT Config"]:::config
            click BERTConfig "https://github.com/royashcenazi/parsigs/blob/master/research/config/config_bert.cfg"
            CompactConfig["Compact BERT Config"]:::config
            click CompactConfig "https://github.com/royashcenazi/parsigs/blob/master/research/config/config_compact_bert.cfg"
        end
    end

    subgraph Testing
        APITests["API Tests"]:::test
        click APITests "https://github.com/royashcenazi/parsigs/blob/master/tests/test_parsig_api.py"
        PropTests["Properties Tests"]:::test
        click PropTests "https://github.com/royashcenazi/parsigs/blob/master/tests/test_properties_parsig_api.py"
        InflectTests["Inflection Tests"]:::test
        click InflectTests "https://github.com/royashcenazi/parsigs/blob/master/tests/test_inflect.py"
    end

    subgraph Output
        StructuredOutput["Structured Sig Object"]:::output
        DrugInfo["Drug Information"]:::data
        DosageDetails["Dosage Details"]:::data
        FreqData["Frequency Data"]:::data
        PeriodInfo["Period Information"]:::data
    end

    subgraph Development
        Playground["Playground Environment"]:::dev
        click Playground "https://github.com/royashcenazi/parsigs/blob/master/playground.py"
    end

    %% Connections
    RawText --> Parser
    Parser --> DrugDB
    Parser --> LatinDict
    Parser --> SpacyNER
    SpacyNER --> EntityRecog
    EntityRecog --> StaticRules
    StaticRules --> PatternMatch
    PatternMatch --> AttrExtract
    AttrExtract --> StructuredOutput
    StructuredOutput --> DrugInfo
    StructuredOutput --> DosageDetails
    StructuredOutput --> FreqData
    StructuredOutput --> PeriodInfo
    
    Training --> SpacyNER
    BERTTraining --> SpacyNER
    DataPrep --> Training
    Config --> Training

    Parser -.-> APITests
    Parser -.-> PropTests
    Parser -.-> InflectTests
    
    Parser -.-> Playground

    %% Styles
    classDef input fill:#FFA07A
    classDef core fill:#4169E1
    classDef resource fill:#90EE90
    classDef model fill:#9370DB
    classDef process fill:#4169E1,stroke:#333
    classDef research fill:#DDA0DD
    classDef config fill:#FFD700
    classDef test fill:#20B2AA
    classDef output fill:#FFA07A
    classDef data fill:#B8860B
    classDef dev fill:#98FB98
```
