quorlen 1.0.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/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +341 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Muthana ALMaiah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<h1 align="center">Lexva</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>A standalone, zero-dependency text worthiness scorer and lexicon analysis engine.</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://img.shields.io/badge/Node.js-%3E%3D%2018-blue.svg" alt="Node.js Version" />
|
|
9
|
+
<img src="https://img.shields.io/badge/TypeScript-5.4-blue.svg" alt="TypeScript Version" />
|
|
10
|
+
<img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License MIT" />
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## 🚀 Overview
|
|
14
|
+
|
|
15
|
+
Lexva 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.
|
|
16
|
+
|
|
17
|
+
## 📦 Project Structure
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
Lexva/
|
|
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
|
+
```
|
|
30
|
+
|
|
31
|
+
## 🛠️ Installation & Setup
|
|
32
|
+
|
|
33
|
+
1. **Navigate to the JavaScript ecosystem folder:**
|
|
34
|
+
```bash
|
|
35
|
+
cd javascript
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. **Install dependencies:**
|
|
39
|
+
```bash
|
|
40
|
+
npm install
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. **Build the production bundle:**
|
|
44
|
+
```bash
|
|
45
|
+
npm run build
|
|
46
|
+
```
|
|
47
|
+
*Outputs clean JavaScript, `.d.ts` declaration files, and maps to the `./dist` folder.*
|
|
48
|
+
|
|
49
|
+
## 💻 Usage
|
|
50
|
+
|
|
51
|
+
Run the verification script directly from the root `Lexva/` directory via `ts-node`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx ts-node javascript/example.ts
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Quick Example
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { TextWorthinessScorer } from 'lexva';
|
|
61
|
+
|
|
62
|
+
// Load your lexicon configuration (see dictionary.json for the schema)
|
|
63
|
+
const lexicon = require('./path/to/your/dictionary.json');
|
|
64
|
+
|
|
65
|
+
const scorer = new TextWorthinessScorer(lexicon);
|
|
66
|
+
const result = scorer.score("This product is completely ecstatic, a legendary triumph.");
|
|
67
|
+
|
|
68
|
+
console.log(`Score: ${result.score}`);
|
|
69
|
+
console.log(`Lexicon Subscore: ${result.lexicon}`);
|
|
70
|
+
console.log(`Matched Critical Words:`, result.hits.critical);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 📜 License
|
|
74
|
+
|
|
75
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
76
|
+
|
|
77
|
+
<hr/>
|
|
78
|
+
<p align="center">Built with ❤️ by Muthana ALMaiah</p>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LexiconConfig, LexvaOptions, LexvaResult } from './types';
|
|
2
|
+
export { LexiconConfig, LexvaOptions, LexvaResult, IntensityTier } from './types';
|
|
3
|
+
export declare class TextWorthinessScorer {
|
|
4
|
+
private stemMap;
|
|
5
|
+
private phraseMap;
|
|
6
|
+
private phraseRegex;
|
|
7
|
+
private stemFunc;
|
|
8
|
+
private stemToOriginal;
|
|
9
|
+
private superlativePattern;
|
|
10
|
+
private experientialPattern;
|
|
11
|
+
private negators;
|
|
12
|
+
private alpha;
|
|
13
|
+
constructor(config: LexiconConfig, options?: LexvaOptions);
|
|
14
|
+
private createStemmer;
|
|
15
|
+
private parseLexicon;
|
|
16
|
+
private buildPhraseRegex;
|
|
17
|
+
private isNegated;
|
|
18
|
+
score(text: string): LexvaResult;
|
|
19
|
+
private findWordInProcessed;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAElF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlF,qBAAa,oBAAoB;IAC7B,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,QAAQ,CAA2B;IAG3C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAAe;gBAEhB,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,YAAiB;IAqC7D,OAAO,CAAC,aAAa;IAiDrB,OAAO,CAAC,YAAY;IA0DpB,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,SAAS;IASV,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAmKvC,OAAO,CAAC,mBAAmB;CAK9B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextWorthinessScorer = void 0;
|
|
4
|
+
// Deterministic text significance and intensity evaluator.
|
|
5
|
+
class TextWorthinessScorer {
|
|
6
|
+
stemMap = new Map();
|
|
7
|
+
phraseMap = new Map();
|
|
8
|
+
phraseRegex = null;
|
|
9
|
+
stemFunc;
|
|
10
|
+
// Maps each stem back to its original dictionary word for human-readable hit output
|
|
11
|
+
stemToOriginal = new Map();
|
|
12
|
+
superlativePattern = null;
|
|
13
|
+
experientialPattern = null;
|
|
14
|
+
negators = new Set();
|
|
15
|
+
alpha = 4.0;
|
|
16
|
+
constructor(config, options = {}) {
|
|
17
|
+
if (config.metadata?.alpha !== undefined)
|
|
18
|
+
this.alpha = config.metadata.alpha;
|
|
19
|
+
if (options.alpha !== undefined)
|
|
20
|
+
this.alpha = options.alpha;
|
|
21
|
+
if (config.metadata?.negators) {
|
|
22
|
+
for (const n of config.metadata.negators) {
|
|
23
|
+
const lower = n.toLowerCase();
|
|
24
|
+
this.negators.add(lower);
|
|
25
|
+
// Track split contraction forms (e.g. "don't" -> "don" and "t")
|
|
26
|
+
if (lower.includes("'")) {
|
|
27
|
+
const parts = lower.split("'");
|
|
28
|
+
if (parts.length === 2 && parts[1] === 't') {
|
|
29
|
+
this.negators.add(parts[0]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.stemFunc = this.createStemmer(config.metadata?.suffixes || []);
|
|
35
|
+
this.parseLexicon(config);
|
|
36
|
+
if (config.amplifier_patterns?.superlatives && config.amplifier_patterns.superlatives.length > 0) {
|
|
37
|
+
const escaped = config.amplifier_patterns.superlatives.map(s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
38
|
+
this.superlativePattern = new RegExp(`\\b(${escaped.join('|')})\\b`, 'gi');
|
|
39
|
+
}
|
|
40
|
+
if (config.amplifier_patterns?.experiential && config.amplifier_patterns.experiential.length > 0) {
|
|
41
|
+
const escaped = config.amplifier_patterns.experiential.map(s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\s+/g, '\\s+'));
|
|
42
|
+
this.experientialPattern = new RegExp(`(?<=^|[^\\p{L}])(${escaped.join('|')})(?=[^\\p{L}]|$)`, 'giu');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Morphological stemmer
|
|
46
|
+
createStemmer(suffixes) {
|
|
47
|
+
const sortedSuffixes = [...suffixes].sort((a, b) => b.length - a.length);
|
|
48
|
+
const isVowel = (c) => 'aeiou'.includes(c);
|
|
49
|
+
const isConsonant = (c) => c >= 'a' && c <= 'z' && !isVowel(c);
|
|
50
|
+
return (word) => {
|
|
51
|
+
let w = word.toLowerCase();
|
|
52
|
+
// Suffix transforms
|
|
53
|
+
if (w.endsWith('ies') && w.length > 4)
|
|
54
|
+
return w.slice(0, -3) + 'y';
|
|
55
|
+
if (w.endsWith('ied') && w.length > 4)
|
|
56
|
+
return w.slice(0, -3) + 'y';
|
|
57
|
+
if (w.endsWith('ying') && w.length > 4) {
|
|
58
|
+
const base = w.slice(0, -4);
|
|
59
|
+
if (base.length >= 2)
|
|
60
|
+
return base + 'y';
|
|
61
|
+
}
|
|
62
|
+
for (const suf of sortedSuffixes) {
|
|
63
|
+
if (w.endsWith(suf) && w.length - suf.length >= 3) {
|
|
64
|
+
const base = w.slice(0, -suf.length);
|
|
65
|
+
// Consonant doubling (e.g. running -> run)
|
|
66
|
+
if (base.length >= 3
|
|
67
|
+
&& base[base.length - 1] === base[base.length - 2]
|
|
68
|
+
&& isConsonant(base[base.length - 1])
|
|
69
|
+
&& !['s', 'l', 'f', 'z'].includes(base[base.length - 1])) {
|
|
70
|
+
return base.slice(0, -1);
|
|
71
|
+
}
|
|
72
|
+
// Silent-e restoration (e.g. hoping -> hope)
|
|
73
|
+
if ((suf === 'ing' || suf === 'ed') && base.length >= 3) {
|
|
74
|
+
const lastChar = base[base.length - 1];
|
|
75
|
+
const secondLast = base[base.length - 2];
|
|
76
|
+
const thirdLast = base[base.length - 3];
|
|
77
|
+
if (isConsonant(lastChar)
|
|
78
|
+
&& isVowel(secondLast)
|
|
79
|
+
&& isConsonant(thirdLast)
|
|
80
|
+
&& !['w', 'x', 'y'].includes(lastChar)) {
|
|
81
|
+
return base + 'e';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return base;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return w;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Build search maps from the lexicon config
|
|
91
|
+
parseLexicon(jsonData) {
|
|
92
|
+
const critical = new Set();
|
|
93
|
+
const high = new Set();
|
|
94
|
+
const medium = new Set();
|
|
95
|
+
const categories = jsonData.categories || {};
|
|
96
|
+
for (const catKey in categories) {
|
|
97
|
+
const cat = categories[catKey];
|
|
98
|
+
if (cat.weight_groups) {
|
|
99
|
+
if (cat.weight_groups.critical)
|
|
100
|
+
cat.weight_groups.critical.forEach((w) => critical.add(w));
|
|
101
|
+
if (cat.weight_groups.high)
|
|
102
|
+
cat.weight_groups.high.forEach((w) => high.add(w));
|
|
103
|
+
if (cat.weight_groups.medium)
|
|
104
|
+
cat.weight_groups.medium.forEach((w) => medium.add(w));
|
|
105
|
+
}
|
|
106
|
+
if (cat.weight && cat.words) {
|
|
107
|
+
const weight = cat.weight;
|
|
108
|
+
cat.words.forEach((w) => {
|
|
109
|
+
if (weight === 'critical')
|
|
110
|
+
critical.add(w);
|
|
111
|
+
else if (weight === 'high')
|
|
112
|
+
high.add(w);
|
|
113
|
+
else if (weight === 'medium')
|
|
114
|
+
medium.add(w);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const addSet = (wordSet, tier) => {
|
|
119
|
+
wordSet.forEach(originalWord => {
|
|
120
|
+
const w = originalWord.toLowerCase();
|
|
121
|
+
if (w.includes(' ') || w.includes('-')) {
|
|
122
|
+
const existing = this.phraseMap.get(w);
|
|
123
|
+
if (!existing || tier === 'critical' || (tier === 'high' && existing === 'medium')) {
|
|
124
|
+
this.phraseMap.set(w, tier);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const stem = this.stemFunc(originalWord);
|
|
129
|
+
const existing = this.stemMap.get(stem);
|
|
130
|
+
if (!existing || tier === 'critical' || (tier === 'high' && existing === 'medium')) {
|
|
131
|
+
this.stemMap.set(stem, tier);
|
|
132
|
+
this.stemToOriginal.set(stem, w);
|
|
133
|
+
}
|
|
134
|
+
const exactExisting = this.stemMap.get(w);
|
|
135
|
+
if (!exactExisting || tier === 'critical' || (tier === 'high' && exactExisting === 'medium')) {
|
|
136
|
+
this.stemMap.set(w, tier);
|
|
137
|
+
this.stemToOriginal.set(w, w);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
addSet(medium, 'medium');
|
|
143
|
+
addSet(high, 'high');
|
|
144
|
+
addSet(critical, 'critical');
|
|
145
|
+
this.phraseRegex = this.buildPhraseRegex(this.phraseMap);
|
|
146
|
+
}
|
|
147
|
+
// Build regex for multi-word phrase matching
|
|
148
|
+
buildPhraseRegex(phraseMap) {
|
|
149
|
+
const phrases = Array.from(phraseMap.keys());
|
|
150
|
+
if (phrases.length === 0)
|
|
151
|
+
return null;
|
|
152
|
+
phrases.sort((a, b) => b.length - a.length);
|
|
153
|
+
const escaped = phrases.map(p => {
|
|
154
|
+
const strictEscaped = p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
155
|
+
return strictEscaped.replace(/(\\?-|\s)+/g, '[\\s\\-]+');
|
|
156
|
+
});
|
|
157
|
+
return new RegExp(`(?<=^|[^\\p{L}])(${escaped.join('|')})(?=[^\\p{L}]|$)`, 'giu');
|
|
158
|
+
}
|
|
159
|
+
// Returns true if a word position is preceded by a negator
|
|
160
|
+
isNegated(index, words) {
|
|
161
|
+
const start = Math.max(0, index - 3);
|
|
162
|
+
for (let i = start; i < index; i++) {
|
|
163
|
+
if (this.negators.has(words[i]))
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// Evaluates the worthiness and intensity of a text segment.
|
|
169
|
+
score(text) {
|
|
170
|
+
const emptyResult = {
|
|
171
|
+
score: 0, lexicon: 0, structure: 0,
|
|
172
|
+
hits: { critical: [], high: [], medium: [] },
|
|
173
|
+
meta: { wordCount: 0, uniqueWordCount: 0, sentenceCount: 0, lexicalDiversity: 0 }
|
|
174
|
+
};
|
|
175
|
+
if (!text || typeof text !== 'string' || text.trim().length === 0) {
|
|
176
|
+
return emptyResult;
|
|
177
|
+
}
|
|
178
|
+
const lowerText = text.toLowerCase();
|
|
179
|
+
const wordsRaw = lowerText.match(/\p{L}+/gu) || [];
|
|
180
|
+
const wordCount = wordsRaw.length;
|
|
181
|
+
const charCount = text.length;
|
|
182
|
+
if (wordCount === 0) {
|
|
183
|
+
return emptyResult;
|
|
184
|
+
}
|
|
185
|
+
const uniqueWords = new Set(wordsRaw);
|
|
186
|
+
const uniqueWordCount = uniqueWords.size;
|
|
187
|
+
const lexicalDiversity = uniqueWordCount / wordCount;
|
|
188
|
+
const hitCritical = [];
|
|
189
|
+
const hitHigh = [];
|
|
190
|
+
const hitMedium = [];
|
|
191
|
+
let rawLexiconScore = 0;
|
|
192
|
+
const hitPhrases = new Set();
|
|
193
|
+
let processedText = lowerText;
|
|
194
|
+
// Match multi-word phrases
|
|
195
|
+
if (this.phraseRegex) {
|
|
196
|
+
const phraseMatches = lowerText.matchAll(this.phraseRegex);
|
|
197
|
+
for (const match of phraseMatches) {
|
|
198
|
+
const phrase = match[0].toLowerCase().replace(/[\s\-]+/g, ' ');
|
|
199
|
+
let tier = this.phraseMap.get(phrase);
|
|
200
|
+
if (tier && !hitPhrases.has(phrase)) {
|
|
201
|
+
hitPhrases.add(phrase);
|
|
202
|
+
const indexInText = match.index || 0;
|
|
203
|
+
const textBefore = lowerText.substring(Math.max(0, indexInText - 20), indexInText);
|
|
204
|
+
const wordsBefore = textBefore.match(/\p{L}+/gu) || [];
|
|
205
|
+
const isNeg = wordsBefore.slice(-3).some(w => this.negators.has(w));
|
|
206
|
+
if (isNeg) {
|
|
207
|
+
if (tier === 'critical')
|
|
208
|
+
tier = 'high';
|
|
209
|
+
else if (tier === 'high')
|
|
210
|
+
tier = 'medium';
|
|
211
|
+
else
|
|
212
|
+
tier = undefined;
|
|
213
|
+
}
|
|
214
|
+
if (tier === 'critical') {
|
|
215
|
+
hitCritical.push(phrase);
|
|
216
|
+
rawLexiconScore += 0.5;
|
|
217
|
+
}
|
|
218
|
+
else if (tier === 'high') {
|
|
219
|
+
hitHigh.push(phrase);
|
|
220
|
+
rawLexiconScore += 0.3;
|
|
221
|
+
}
|
|
222
|
+
else if (tier === 'medium') {
|
|
223
|
+
hitMedium.push(phrase);
|
|
224
|
+
rawLexiconScore += 0.1;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
processedText = lowerText.replace(this.phraseRegex, (m) => ' '.repeat(m.length));
|
|
229
|
+
}
|
|
230
|
+
// Match individual words
|
|
231
|
+
const wordHitSet = new Set();
|
|
232
|
+
for (let i = 0; i < wordsRaw.length; i++) {
|
|
233
|
+
const rawWord = wordsRaw[i];
|
|
234
|
+
const stem = this.stemFunc(rawWord);
|
|
235
|
+
let tier = this.stemMap.get(stem) || this.stemMap.get(rawWord);
|
|
236
|
+
if (tier && !wordHitSet.has(stem)) {
|
|
237
|
+
const wordIndex = this.findWordInProcessed(processedText, rawWord, i, wordsRaw);
|
|
238
|
+
if (wordIndex === -1)
|
|
239
|
+
continue;
|
|
240
|
+
wordHitSet.add(stem);
|
|
241
|
+
if (this.isNegated(i, wordsRaw)) {
|
|
242
|
+
if (tier === 'critical')
|
|
243
|
+
tier = 'high';
|
|
244
|
+
else if (tier === 'high')
|
|
245
|
+
tier = 'medium';
|
|
246
|
+
else
|
|
247
|
+
tier = undefined;
|
|
248
|
+
}
|
|
249
|
+
const displayWord = this.stemToOriginal.get(stem) || this.stemToOriginal.get(rawWord) || rawWord;
|
|
250
|
+
if (tier === 'critical') {
|
|
251
|
+
hitCritical.push(displayWord);
|
|
252
|
+
rawLexiconScore += 0.5;
|
|
253
|
+
}
|
|
254
|
+
else if (tier === 'high') {
|
|
255
|
+
hitHigh.push(displayWord);
|
|
256
|
+
rawLexiconScore += 0.3;
|
|
257
|
+
}
|
|
258
|
+
else if (tier === 'medium') {
|
|
259
|
+
hitMedium.push(displayWord);
|
|
260
|
+
rawLexiconScore += 0.1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Amplifier scores
|
|
265
|
+
if (this.superlativePattern) {
|
|
266
|
+
const matches = text.match(this.superlativePattern) || [];
|
|
267
|
+
if (matches.length > 0) {
|
|
268
|
+
rawLexiconScore += Math.min(0.12, matches.length * 0.04);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (this.experientialPattern) {
|
|
272
|
+
const matches = text.match(this.experientialPattern) || [];
|
|
273
|
+
if (matches.length > 0) {
|
|
274
|
+
rawLexiconScore += Math.min(0.15, matches.length * 0.05);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const exclamationCount = (text.match(/!/g) || []).length;
|
|
278
|
+
if (exclamationCount > 0) {
|
|
279
|
+
rawLexiconScore += Math.min(0.10, exclamationCount * 0.03);
|
|
280
|
+
}
|
|
281
|
+
// Standard scaling normalization
|
|
282
|
+
const lexiconScore = rawLexiconScore > 0
|
|
283
|
+
? rawLexiconScore / Math.sqrt(rawLexiconScore * rawLexiconScore + this.alpha)
|
|
284
|
+
: 0;
|
|
285
|
+
// Structure & Complexity metrics
|
|
286
|
+
let structureScore = 0;
|
|
287
|
+
structureScore += lexicalDiversity * 0.4;
|
|
288
|
+
if (charCount >= 300)
|
|
289
|
+
structureScore += 0.20;
|
|
290
|
+
else if (charCount >= 150)
|
|
291
|
+
structureScore += 0.10;
|
|
292
|
+
else if (charCount >= 60)
|
|
293
|
+
structureScore += 0.05;
|
|
294
|
+
const sentenceCount = text.split(/[.!?]+/).filter(s => s.trim().length > 0).length;
|
|
295
|
+
const avgWordsPerSentence = wordCount / Math.max(sentenceCount, 1);
|
|
296
|
+
if (avgWordsPerSentence > 4)
|
|
297
|
+
structureScore += 0.10;
|
|
298
|
+
if (sentenceCount > 1)
|
|
299
|
+
structureScore += 0.10;
|
|
300
|
+
const hasNumbers = /\d/.test(text);
|
|
301
|
+
const hasProperNouns = /[^.!?¡¿]\s+[A-ZÀ-ÖØ-Þ][a-zà-öø-ÿ]{2,}/u.test(text);
|
|
302
|
+
const hasPunctuation = /[?…]/.test(text);
|
|
303
|
+
const hasQuotes = /["']/.test(text);
|
|
304
|
+
if (hasNumbers)
|
|
305
|
+
structureScore += 0.05;
|
|
306
|
+
if (hasProperNouns)
|
|
307
|
+
structureScore += 0.05;
|
|
308
|
+
if (hasPunctuation)
|
|
309
|
+
structureScore += 0.05;
|
|
310
|
+
if (hasQuotes)
|
|
311
|
+
structureScore += 0.05;
|
|
312
|
+
structureScore = Math.min(1.0, structureScore);
|
|
313
|
+
// Blended total score
|
|
314
|
+
const lexicalWeight = 0.80;
|
|
315
|
+
const structureWeight = 0.20;
|
|
316
|
+
const totalScore = (lexiconScore * lexicalWeight) + (structureScore * structureWeight);
|
|
317
|
+
return {
|
|
318
|
+
score: Math.min(Math.max(totalScore, 0), 1),
|
|
319
|
+
lexicon: Number(lexiconScore.toFixed(4)),
|
|
320
|
+
structure: Number(structureScore.toFixed(4)),
|
|
321
|
+
hits: {
|
|
322
|
+
critical: hitCritical,
|
|
323
|
+
high: hitHigh,
|
|
324
|
+
medium: hitMedium
|
|
325
|
+
},
|
|
326
|
+
meta: {
|
|
327
|
+
wordCount,
|
|
328
|
+
uniqueWordCount,
|
|
329
|
+
sentenceCount,
|
|
330
|
+
lexicalDiversity: Number(lexicalDiversity.toFixed(4))
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
findWordInProcessed(processedText, word, _wordIndex, _allWords) {
|
|
335
|
+
const regex = new RegExp(`(?<=^|[^\\p{L}])${word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?=[^\\p{L}]|$)`, 'iu');
|
|
336
|
+
const match = processedText.match(regex);
|
|
337
|
+
return match ? (match.index ?? 0) : -1;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.TextWorthinessScorer = TextWorthinessScorer;
|
|
341
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAIA,2DAA2D;AAC3D,MAAa,oBAAoB;IACrB,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC3C,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC7C,WAAW,GAAkB,IAAI,CAAC;IAClC,QAAQ,CAA2B;IAE3C,oFAAoF;IAC5E,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,kBAAkB,GAAkB,IAAI,CAAC;IACzC,mBAAmB,GAAkB,IAAI,CAAC;IAC1C,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,KAAK,GAAW,GAAG,CAAC;IAE5B,YAAY,MAAqB,EAAE,UAAwB,EAAE;QACzD,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7E,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5D,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC;YAC5B,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACvC,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;gBAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAEzB,gEAAgE;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,KAAK,CAAC,CAAC;QACzC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;CACJ;AA5VD,oDA4VC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type IntensityTier = 'critical' | 'high' | 'medium';
|
|
2
|
+
export interface LexiconConfig {
|
|
3
|
+
metadata?: {
|
|
4
|
+
version?: string;
|
|
5
|
+
language?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
last_updated?: string;
|
|
8
|
+
suffixes?: string[];
|
|
9
|
+
negators?: string[];
|
|
10
|
+
alpha?: number;
|
|
11
|
+
};
|
|
12
|
+
categories?: Record<string, any>;
|
|
13
|
+
amplifier_patterns?: {
|
|
14
|
+
superlatives?: string[];
|
|
15
|
+
experiential?: string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface LexvaOptions {
|
|
19
|
+
/** Override the default alpha normalization constant */
|
|
20
|
+
alpha?: number;
|
|
21
|
+
/** Apply a specific profile (for future use) */
|
|
22
|
+
profile?: 'standard' | 'sensitive' | 'strict';
|
|
23
|
+
}
|
|
24
|
+
export interface LexvaResult {
|
|
25
|
+
/** Final blended score [0, 1] */
|
|
26
|
+
score: number;
|
|
27
|
+
/** Lexicon sub-score [0, 1] */
|
|
28
|
+
lexicon: number;
|
|
29
|
+
/** Structural complexity sub-score [0, 1] */
|
|
30
|
+
structure: number;
|
|
31
|
+
/** Categorized lists of matched words/phrases */
|
|
32
|
+
hits: {
|
|
33
|
+
critical: string[];
|
|
34
|
+
high: string[];
|
|
35
|
+
medium: string[];
|
|
36
|
+
};
|
|
37
|
+
/** Extracted metadata from the text analysis */
|
|
38
|
+
meta: {
|
|
39
|
+
wordCount: number;
|
|
40
|
+
uniqueWordCount: number;
|
|
41
|
+
sentenceCount: number;
|
|
42
|
+
lexicalDiversity: number;
|
|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ChD,IAAI,EAAE;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;KAC5B,CAAC;CACL"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "quorlen",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A standalone, zero-dependency text worthiness scorer and lexicon analysis engine.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"start": "ts-node example.ts",
|
|
11
|
+
"test": "ts-node example.ts",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"author": "Muthana ALMaiah",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"text-worthiness",
|
|
18
|
+
"nlp",
|
|
19
|
+
"sentiment-analysis",
|
|
20
|
+
"lexicon",
|
|
21
|
+
"text-intensity",
|
|
22
|
+
"deterministic"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/5bbvm/Quorlen.git",
|
|
27
|
+
"directory": "javascript"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/5bbvm/Quorlen/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/5bbvm/Quorlen/tree/main/javascript#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^20.0.0",
|
|
41
|
+
"ts-node": "^10.9.2",
|
|
42
|
+
"typescript": "^5.4.5"
|
|
43
|
+
}
|
|
44
|
+
}
|