quorlen 1.0.1 β†’ 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <h1 align="center">Quorlen</h1>
2
2
 
3
3
  <p align="center">
4
- <strong>A standalone, zero-dependency text worthiness scorer and lexicon analysis engine.</strong>
4
+ <strong>A lightweight, zero-dependency engine that estimates the importance of text.</strong>
5
5
  </p>
6
6
 
7
7
  <p align="center">
@@ -10,69 +10,232 @@
10
10
  <img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License MIT" />
11
11
  </p>
12
12
 
13
- ## πŸš€ Overview
13
+ ---
14
14
 
15
- Quorlen is a lightweight, pure TypeScript scoring module designed to evaluate the "worthiness" or intensity of text. It uses a deterministic morphological stemming approach and lexicon dictionaries to parse, analyze, and grade text with zero external dependencies.
15
+ ## Why Quorlen Exists
16
16
 
17
- ## πŸ“¦ Project Structure
17
+ In natural language processing, we are often tasked with analyzing user communications, logs, or documents. Traditional sentiment analysis categorizes text along emotional axes:
18
+ - **Sentiment Analysis** answers: *"How does this text feel?"* (Positive, Negative, Neutral)
19
+ - **Quorlen** answers: *"How much does this text matter?"* (Significance, Importance, Impact)
18
20
 
19
- ```text
20
- Quorlen/
21
- └── javascript/
22
- β”œβ”€β”€ src/
23
- β”‚ β”œβ”€β”€ index.ts # Core scoring engine
24
- β”‚ β”œβ”€β”€ types.ts # Public TypeScript interfaces and types
25
- β”‚ └── dictionary.json # Lexicon configuration and weights
26
- β”œβ”€β”€ package.json # Node.js dependencies and scripts
27
- β”œβ”€β”€ tsconfig.json # TypeScript compilation settings
28
- └── example.ts # Verification and testing script
29
- ```
21
+ These are fundamentally different questions.
22
+
23
+ A sentiment analyzer might score a tragedy and a minor daily inconvenience similarly because both contain negative words. Conversely, it might score a life-changing wedding announcement and a trivial compliment similarly because both contain positive words.
24
+
25
+ Quorlen filters out the noise. It isolates routine chatter from pivotal events, helping you focus resources on text containing high-impact milestones, crises, or material announcements.
26
+
27
+ ---
28
+
29
+ ## Significance vs. Sentiment
30
+
31
+ Quorlen scores text on a scale from `0.0` (trivial/no significance) to `1.0` (critical significance). Each score is automatically classified into a **Significance Tier** for easy consumption. Notice how sentiment polarity does not dictate the importance score:
32
+
33
+ | Input Text | Sentiment | Score | Tier | Primary Triggers Matched |
34
+ | :--- | :--- | :---: | :---: | :--- |
35
+ | `"I ate breakfast."` | Neutral | **`0.0800`** | `Routine` | *None (routine action)* |
36
+ | `"The server returned a 500 error."` | Negative | **`0.1100`** | `Routine` | *None (standard log)* |
37
+ | `"I got promoted today."` | Positive | **`0.3019`** | `Meaningful` | `promoted` *(critical milestone)* |
38
+ | `"My father passed away."` | Negative | **`0.3019`** | `Meaningful` | `passed away` *(critical milestone)* |
39
+ | `"We're getting married next week."` | Positive | **`0.3319`** | `Meaningful` | `married` *(critical milestone)* |
40
+ | `"A catastrophic earthquake hit the coast, causing widespread devastation and forcing emergency evacuations."` | Negative | **`0.6528`** | `Significant` | `earthquake` *(critical)*, `emergency` *(critical)*, `catastrophic` *(high)*, `devastation` *(high)* |
41
+ | `""The biopsy came back positive for malignant cancer," the doctor said. We are devastated."` | Negative | **`0.7107`** | `Critical` | `biopsy` *(critical)*, `malignant` *(critical)*, `cancer` *(critical)*, `devastated` *(high)* |
42
+
43
+ ---
44
+
45
+ ## Key Features
46
+
47
+ - **Zero Dependencies**: Pure TypeScript implementation with zero external runtime requirements.
48
+ - **Deterministic Evaluation**: 100% reproducible results. No machine learning models, no network requests, and no asynchronous cold starts.
49
+ - **Morphological Stemmer**: A built-in morphological stemmer handles pluralizations, verb tenses, and suffix modifications dynamically (e.g., `graduated` and `graduation` map to the same root).
50
+ - **Phrase and Suffix Matching**: Matches complex multi-word idioms (e.g., `passed away`, `fell in love`, `gave up`) alongside single-word triggers.
51
+ - **Amplifiers and Intensifiers**: Detects superlatives, experiential structures (e.g., `first ever`, `never felt`), and exclamation marks to scale significance appropriately.
52
+ - **Context-Aware Negation**: Identifies negators (e.g., `not`, `don't`, `never`) within a three-word window and de-escalates the importance score to avoid false positives.
53
+ - **Syntactic Complexity Metrics**: Integrates structural featuresβ€”such as lexical diversity, sentence count, proper nouns, numbers, quotes, and character lengthβ€”into the final blended score.
54
+
55
+ ---
56
+
57
+ ## Target Use Cases
58
+
59
+ Quorlen is built for modern developers designing content-rich applications, AI pipelines, and workflow automation:
60
+
61
+ - **LLM and RAG Cost Reduction**: Filter out low-significance conversational chatter, logs, or system instructions before passing text to embeddings or LLM contexts.
62
+ - **Summarization & Keyphrase Extraction**: Prioritize sentences containing major milestone updates or critical information before feeding text to a summarizer.
63
+ - **Notification Routing**: Route notifications dynamically. Bubble up messages with high significance scores (e.g., legal warnings, support issues) while silencing daily updates.
64
+ - **CRM and Customer Support**: Automatically flag and escalate incoming support tickets referencing high-importance events (e.g., bankruptcy, lawsuits, medical emergencies).
65
+ - **Productivity & Note-Taking Applications**: Extract meaningful notes, journals, or highlights automatically by scoring entry significance.
66
+
67
+ ---
30
68
 
31
- ## πŸ› οΈ Installation & Setup
69
+ ## Installation
32
70
 
33
- 1. **Navigate to the JavaScript ecosystem folder:**
71
+ ### From npm (Usage)
72
+ ```bash
73
+ npm install quorlen
74
+ ```
75
+
76
+ ### Local Development (Contributing)
77
+ 1. Clone the repository and navigate to the JavaScript ecosystem directory:
34
78
  ```bash
35
79
  cd javascript
36
80
  ```
37
-
38
- 2. **Install dependencies:**
81
+ 2. Install the dev dependencies:
39
82
  ```bash
40
83
  npm install
41
84
  ```
42
-
43
- 3. **Build the production bundle:**
85
+ 3. Compile the TypeScript source code:
44
86
  ```bash
45
87
  npm run build
46
88
  ```
47
- *Outputs clean JavaScript, `.d.ts` declaration files, and maps to the `./dist` folder.*
89
+ *Outputs standard JavaScript, source maps, and `.d.ts` definition files to the `./dist` folder.*
48
90
 
49
- ## πŸ’» Usage
91
+ ---
50
92
 
51
- Run the verification script directly from the root `Quorlen/` directory via `ts-node`:
93
+ ## Quick Start
52
94
 
53
- ```bash
54
- npx ts-node javascript/example.ts
95
+ ```typescript
96
+ import { TextWorthinessScorer } from 'quorlen';
97
+
98
+ // Import the default English significance lexicon config
99
+ import lexiconConfig from 'quorlen/dist/dictionary.json';
100
+
101
+ // Initialize the scorer with the lexicon configuration
102
+ const scorer = new TextWorthinessScorer(lexiconConfig);
103
+
104
+ const text = "I finally graduated college today! I'm completely ecstatic, this is a legendary triumph.";
105
+ const result = scorer.score(text);
106
+
107
+ console.log(`Significance Score: ${result.score}`); // ~0.7944
108
+ console.log(`Significance Tier: ${result.tier}`); // "Critical"
109
+ console.log(`Lexicon Hits:`, result.hits);
110
+ console.log(`Text Word Count: ${result.meta.wordCount}`);
55
111
  ```
56
112
 
57
- ### Quick Example
113
+ ---
114
+
115
+ ## Significance Tiers
116
+
117
+ Every `QuorlenResult` includes a `tier` field that classifies the numerical `score` into a named significance tier. These tiers are calculated automatically and provide a human-readable classification that is more accurate than hardcoded thresholds:
118
+
119
+ | Tier | Score Range | Description | Example |
120
+ | :--- | :---: | :--- | :--- |
121
+ | **`Routine`** | `0.00` – `0.14` | Trivial daily chatter, greetings, system logs, or transactional instructions with no significance. | `"I am heading out for a walk now."` |
122
+ | **`Minor`** | `0.15` – `0.24` | Low-importance updates with a single weak keyword hit, mild notices, or slightly notable observations. | `"The database backup finished at 3am."` |
123
+ | **`Meaningful`** | `0.25` – `0.44` | Single clear milestone markers β€” career changes, personal announcements, or moderate-impact events. | `"I got promoted today."` |
124
+ | **`Significant`** | `0.45` – `0.69` | Multi-trigger high-impact events β€” natural disasters, corporate crises, accidents with injuries. | `"A catastrophic earthquake hit the coast, causing widespread devastation."` |
125
+ | **`Critical`** | `0.70` – `1.00` | Extreme emergencies containing dense critical triggers β€” medical diagnoses, mass disasters, terror events. | `"The biopsy came back positive for malignant cancer."` |
58
126
 
59
127
  ```typescript
60
- import { TextWorthinessScorer } from 'quorlen';
128
+ const result = scorer.score("My father passed away.");
129
+ console.log(result.tier); // "Meaningful"
130
+
131
+ if (result.tier === 'Critical' || result.tier === 'Significant') {
132
+ // Escalate notification
133
+ }
134
+ ```
135
+
136
+ ---
61
137
 
62
- // Load your lexicon configuration (see dictionary.json for the schema)
63
- const lexicon = require('./path/to/your/dictionary.json');
138
+ ## API Reference
64
139
 
65
- const scorer = new TextWorthinessScorer(lexicon);
66
- const result = scorer.score("This product is completely ecstatic, a legendary triumph.");
140
+ Quorlen exports a main scoring class and several TypeScript types/interfaces to structure inputs and outputs.
67
141
 
68
- console.log(`Score: ${result.score}`);
69
- console.log(`Lexicon Subscore: ${result.lexicon}`);
70
- console.log(`Matched Critical Words:`, result.hits.critical);
142
+ ### Class: `TextWorthinessScorer`
143
+
144
+ The main execution engine of Quorlen.
145
+
146
+ #### Constructor
147
+
148
+ ```typescript
149
+ constructor(config: LexiconConfig, options?: QuorlenOptions)
71
150
  ```
72
151
 
73
- ## πŸ“œ License
152
+ - **Purpose**: Creates an instance of the scoring engine loaded with a custom or default lexicon and operational options.
153
+ - **Parameters**:
154
+ - `config`: `LexiconConfig` β€” Dictionaries containing categories, words, and weights.
155
+ - `options` (Optional): `QuorlenOptions` β€” Fine-tuning settings.
156
+ - **Example**:
157
+ ```typescript
158
+ import { TextWorthinessScorer } from 'quorlen';
159
+ import config from 'quorlen/dist/dictionary.json';
160
+
161
+ const scorer = new TextWorthinessScorer(config, { alpha: 3.0 });
162
+ ```
163
+
164
+ #### Method: `score`
165
+
166
+ ```typescript
167
+ public score(text: string): QuorlenResult
168
+ ```
169
+
170
+ - **Purpose**: Parses, stems, analyzes, and returns a detailed significance score for the provided string.
171
+ - **Parameters**:
172
+ - `text`: `string` β€” The input text to score.
173
+ - **Return Value**: `QuorlenResult` β€” The score breakdown, hits, and text metadata.
174
+ - **Example**:
175
+ ```typescript
176
+ const result = scorer.score("The team won the championship!");
177
+ console.log(result.score); // e.g. 0.5421
178
+ ```
179
+
180
+ ---
181
+
182
+ ### Interfaces
183
+
184
+ #### `LexiconConfig`
185
+ Defines the dictionary config schema containing lexical categories and weights.
186
+ - **Properties**:
187
+ - `metadata` (Optional): Metadata block defining suffix lists for stemmer, negator sets, and the `alpha` normalization factor.
188
+ - `categories`: Key-value map grouping words and phrases under relevance weights (`critical`, `high`, `medium`).
189
+ - `amplifier_patterns` (Optional): List of superlative and experiential strings used for score scaling.
190
+
191
+ #### `QuorlenOptions`
192
+ Fine-tuning configuration parameters.
193
+ - **Properties**:
194
+ - `alpha` (Optional): Overrides the default mathematical constant (`alpha`) used in sigmoid scaling of lexicon scores. A lower alpha scales small scores up faster.
195
+
196
+ #### `SignificanceTier`
197
+ A string literal union type representing the named significance classification.
198
+ - **Values**: `'Routine'` | `'Minor'` | `'Meaningful'` | `'Significant'` | `'Critical'`
199
+
200
+ #### `QuorlenResult`
201
+ The output returned by the `score()` method.
202
+ - **Properties**:
203
+ - `score` (`number`): The final blended significance score `[0, 1]` combining lexicon matches and structural complexity.
204
+ - `tier` (`SignificanceTier`): The named significance tier automatically calculated from the score β€” `Routine`, `Minor`, `Meaningful`, `Significant`, or `Critical`.
205
+ - `lexicon` (`number`): The lexicon-specific sub-score `[0, 1]` representing matched words, phrases, and amplifiers.
206
+ - `structure` (`number`): The structural complexity sub-score `[0, 1]` based on punctuation, quotes, diversity, and length metrics.
207
+ - `hits`: Object categorizing matched terms into `critical`, `high`, and `medium` lists.
208
+ - `meta`: Text-level metadata (sentence count, word count, unique words, and lexical diversity).
209
+
210
+ ---
211
+
212
+ ## Technical & Performance Characteristics
213
+
214
+ ### Complexity & Execution Speed
215
+ Quorlen is optimized for speed and high-throughput environments:
216
+ - **Time Complexity**: $O(N)$ where $N$ is the number of characters. Morphological stemming and phrase matching are performed via unified regex maps and direct hash lookups, avoiding nested loops.
217
+ - **Space Complexity**: $O(K)$ where $K$ is the dictionary lexicon size.
218
+ - **Memory Footprint**: Negligible. The default configuration uses less than 300KB of RAM in execution.
219
+
220
+ ### Deterministic Architecture
221
+ Because Quorlen is entirely deterministic, it offers distinct advantages over LLM-based significance filters:
222
+ - **Reproducibility**: Identical text inputs will *always* result in the same numerical score down to the decimal point.
223
+ - **Zero Latency Spikes**: Execution is synchronous and local, typically completing in sub-millisecond durations.
224
+ - **Offline Reliability**: Run in browser threads, edge functions (Cloudflare Workers, Vercel Edge), or embedded microservices without internet or API key access.
225
+
226
+ ---
227
+
228
+ ## Roadmap
229
+
230
+ - [ ] Support custom profiles (`standard`, `sensitive`, `strict`) directly within scoring options.
231
+ - [ ] Implement multi-lingual dictionaries (German, Spanish, French, and Japanese).
232
+ - [ ] Provide optional callback interfaces to register custom runtime stemmers.
233
+
234
+ ---
235
+
236
+ ## License
74
237
 
75
- Distributed under the MIT License. See `LICENSE` for more information.
238
+ Distributed under the MIT License. See `LICENSE` for more details.
76
239
 
77
- <hr/>
240
+ ---
78
241
  <p align="center">Built with ❀️ by Muthana ALMaiah</p>