# modarwish1/sentimentr architecture

> Architecture diagram of the GitHub repository modarwish1/sentimentr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/modarwish1/sentimentr
- Repository: https://github.com/modarwish1/sentimentr

## Overview

sentimentr is a Python sentiment-analysis library for formal and informal text. Its principal workflow accepts a document through Sentiment.get_polarity_score, evaluates clauses and matched lexical items using contextual rules, then combines and normalizes polarity into a document score. The README also documents idioms, emojis, emoticons, and subjectivity alongside the core formal and informal rules. The runtime is concentrated in one source file; the graph separates its documented stages while pointing to that implementation. Some internal calls are not visible in the excerpts, so documented relationships use README evidence.

Main entry points: [`sentimentr/sentimentr.py`](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py) (Lexical matching), [`sentimentr/lexica`](https://github.com/modarwish1/sentimentr/tree/main/sentimentr/lexica) (Lexica and modifiers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_sentiment_api["Sentiment API<br/>[sentimentr.py]"]
  node_score_result["Document score<br/>[sentimentr.py]"]
end

subgraph group_analysis["Sentiment analysis"]
  node_clause_analysis["Clause analysis<br/>[sentimentr.py]"]
  node_lexical_matching["Lexical matching<br/>[sentimentr.py]"]
  node_formal_rules["Formal context rules<br/>[sentimentr.py]"]
  node_informal_rules["Informal context rules<br/>[sentimentr.py]"]
  node_polarity_aggregation["Polarity aggregation<br/>[sentimentr.py]"]
end

subgraph group_resources["Lexical resources"]
  node_lexica["Lexica and modifiers"]
end

node_caller(("Library caller"))
node_nltk["NLTK tokenizer"]
node_wordnet[("WordNet")]

node_caller -->|"calls"| node_sentiment_api
node_sentiment_api -->|"analyzes clauses"| node_clause_analysis
node_clause_analysis -->|"matches terms"| node_lexical_matching
node_lexical_matching -->|"loads resources"| node_lexica
node_clause_analysis -->|"tokenizes text"| node_nltk
node_lexical_matching -->|"refines polarity"| node_formal_rules
node_lexical_matching -->|"refines polarity"| node_informal_rules
node_formal_rules -->|"checks word forms"| node_wordnet
node_informal_rules -->|"contributes clause scores"| node_polarity_aggregation
node_formal_rules -->|"contributes clause scores"| node_polarity_aggregation
node_polarity_aggregation -->|"normalizes score"| node_score_result
node_sentiment_api -->|"returns score"| node_score_result

click node_sentiment_api "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_clause_analysis "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_lexical_matching "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_formal_rules "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_informal_rules "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_polarity_aggregation "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_score_result "https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py"
click node_lexica "https://github.com/modarwish1/sentimentr/tree/main/sentimentr/lexica"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sentiment_api,node_score_result toneBlue
class node_clause_analysis,node_lexical_matching,node_formal_rules,node_informal_rules,node_polarity_aggregation,node_wordnet toneAmber
class node_lexica toneMint
class node_caller,node_nltk toneIndigo
```

## Components

### Public API

- [Sentiment API](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`
- [Document score](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`

### Sentiment analysis

- [Clause analysis](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`
- [Lexical matching](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`
- [Formal context rules](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`
- [Informal context rules](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`
- [Polarity aggregation](https://github.com/modarwish1/sentimentr/blob/main/sentimentr/sentimentr.py): `sentimentr/sentimentr.py`

### Lexical resources

- [Lexica and modifiers](https://github.com/modarwish1/sentimentr/tree/main/sentimentr/lexica): `sentimentr/lexica`

### Other components

- **Library caller**
- **NLTK tokenizer**
- **WordNet**

## Connections

- Library caller → Sentiment API: calls (evidence: `README.md`)
- Sentiment API → Clause analysis: analyzes clauses (evidence: `README.md`)
- Clause analysis → Lexical matching: matches terms (evidence: `README.md`)
- Lexical matching → Lexica and modifiers: loads resources (evidence: `sentimentr/sentimentr.py`)
- Clause analysis → NLTK tokenizer: tokenizes text (evidence: `sentimentr/sentimentr.py`)
- Lexical matching → Formal context rules: refines polarity (evidence: `README.md`)
- Lexical matching → Informal context rules: refines polarity (evidence: `README.md`)
- Formal context rules → WordNet: checks word forms (evidence: `README.md`)
- Informal context rules → Polarity aggregation: contributes clause scores (evidence: `README.md`)
- Formal context rules → Polarity aggregation: contributes clause scores (evidence: `README.md`)
- Polarity aggregation → Document score: normalizes score (evidence: `README.md`)
- Sentiment API → Document score: returns score (evidence: `README.md`)
