@higher.archi/boe 1.0.24 → 1.0.26
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/dist/engines/sentiment/compiler.d.ts +12 -0
- package/dist/engines/sentiment/compiler.d.ts.map +1 -0
- package/dist/engines/sentiment/compiler.js +111 -0
- package/dist/engines/sentiment/compiler.js.map +1 -0
- package/dist/engines/sentiment/engine.d.ts +47 -0
- package/dist/engines/sentiment/engine.d.ts.map +1 -0
- package/dist/engines/sentiment/engine.js +89 -0
- package/dist/engines/sentiment/engine.js.map +1 -0
- package/dist/engines/sentiment/index.d.ts +9 -0
- package/dist/engines/sentiment/index.d.ts.map +1 -0
- package/dist/engines/sentiment/index.js +21 -0
- package/dist/engines/sentiment/index.js.map +1 -0
- package/dist/engines/sentiment/strategy.d.ts +19 -0
- package/dist/engines/sentiment/strategy.d.ts.map +1 -0
- package/dist/engines/sentiment/strategy.js +398 -0
- package/dist/engines/sentiment/strategy.js.map +1 -0
- package/dist/engines/sentiment/types.d.ts +125 -0
- package/dist/engines/sentiment/types.d.ts.map +1 -0
- package/dist/engines/sentiment/types.js +31 -0
- package/dist/engines/sentiment/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/engines/sentiment/compiler.ts +138 -0
- package/src/engines/sentiment/engine.ts +118 -0
- package/src/engines/sentiment/index.ts +41 -0
- package/src/engines/sentiment/strategy.ts +510 -0
- package/src/engines/sentiment/types.ts +188 -0
- package/src/index.ts +31 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentiment Engine Compiler
|
|
3
|
+
*
|
|
4
|
+
* Validates sentiment rulesets, normalizes lexicon keys to lowercase,
|
|
5
|
+
* and resolves config defaults.
|
|
6
|
+
*/
|
|
7
|
+
import type { SentimentRuleSet, CompiledSentimentRuleSet } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Compile and validate a sentiment ruleset.
|
|
10
|
+
*/
|
|
11
|
+
export declare function compileSentimentRuleSet(ruleSet: SentimentRuleSet): CompiledSentimentRuleSet;
|
|
12
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/engines/sentiment/compiler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,gBAAgB,GACxB,wBAAwB,CAuE1B"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sentiment Engine Compiler
|
|
4
|
+
*
|
|
5
|
+
* Validates sentiment rulesets, normalizes lexicon keys to lowercase,
|
|
6
|
+
* and resolves config defaults.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.compileSentimentRuleSet = compileSentimentRuleSet;
|
|
10
|
+
const errors_1 = require("../../core/errors");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
/**
|
|
13
|
+
* Compile and validate a sentiment ruleset.
|
|
14
|
+
*/
|
|
15
|
+
function compileSentimentRuleSet(ruleSet) {
|
|
16
|
+
if (!ruleSet.id) {
|
|
17
|
+
throw new errors_1.CompilationError('Sentiment ruleset requires an id');
|
|
18
|
+
}
|
|
19
|
+
if (ruleSet.mode !== 'sentiment') {
|
|
20
|
+
throw new errors_1.CompilationError(`Expected mode 'sentiment', got '${ruleSet.mode}'`);
|
|
21
|
+
}
|
|
22
|
+
if (!ruleSet.lexiconConfig || !ruleSet.lexiconConfig.lexicon) {
|
|
23
|
+
throw new errors_1.CompilationError('Sentiment ruleset requires a lexiconConfig with a lexicon');
|
|
24
|
+
}
|
|
25
|
+
const lexiconKeys = Object.keys(ruleSet.lexiconConfig.lexicon);
|
|
26
|
+
if (lexiconKeys.length === 0) {
|
|
27
|
+
throw new errors_1.CompilationError('Lexicon must contain at least one entry');
|
|
28
|
+
}
|
|
29
|
+
// Compile the lexicon
|
|
30
|
+
const lexicon = compileLexicon(ruleSet.lexiconConfig);
|
|
31
|
+
// Resolve config defaults
|
|
32
|
+
const config = {
|
|
33
|
+
capsBoost: ruleSet.config?.capsBoost ?? types_1.SENTIMENT_DEFAULTS.capsBoost,
|
|
34
|
+
exclamationBoost: ruleSet.config?.exclamationBoost ?? types_1.SENTIMENT_DEFAULTS.exclamationBoost,
|
|
35
|
+
negationWindow: ruleSet.config?.negationWindow ?? types_1.SENTIMENT_DEFAULTS.negationWindow
|
|
36
|
+
};
|
|
37
|
+
switch (ruleSet.strategy) {
|
|
38
|
+
case 'token-level':
|
|
39
|
+
return {
|
|
40
|
+
id: ruleSet.id,
|
|
41
|
+
name: ruleSet.name,
|
|
42
|
+
mode: 'sentiment',
|
|
43
|
+
strategy: 'token-level',
|
|
44
|
+
lexicon,
|
|
45
|
+
config
|
|
46
|
+
};
|
|
47
|
+
case 'document-level': {
|
|
48
|
+
const pattern = ruleSet.sentenceSplitPattern ?? '[.!?]+';
|
|
49
|
+
return {
|
|
50
|
+
id: ruleSet.id,
|
|
51
|
+
name: ruleSet.name,
|
|
52
|
+
mode: 'sentiment',
|
|
53
|
+
strategy: 'document-level',
|
|
54
|
+
lexicon,
|
|
55
|
+
config,
|
|
56
|
+
sentenceSplitPattern: new RegExp(pattern)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
case 'aspect-based': {
|
|
60
|
+
if (!ruleSet.aspects || ruleSet.aspects.length === 0) {
|
|
61
|
+
throw new errors_1.CompilationError('Aspect-based strategy requires at least one aspect');
|
|
62
|
+
}
|
|
63
|
+
const aspects = ruleSet.aspects.map(a => a.toLowerCase());
|
|
64
|
+
return {
|
|
65
|
+
id: ruleSet.id,
|
|
66
|
+
name: ruleSet.name,
|
|
67
|
+
mode: 'sentiment',
|
|
68
|
+
strategy: 'aspect-based',
|
|
69
|
+
lexicon,
|
|
70
|
+
config,
|
|
71
|
+
aspects
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
throw new errors_1.CompilationError(`Unknown sentiment strategy: '${ruleSet.strategy}'`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function compileLexicon(input) {
|
|
79
|
+
// Normalize all keys to lowercase
|
|
80
|
+
const lexicon = {};
|
|
81
|
+
for (const [key, value] of Object.entries(input.lexicon)) {
|
|
82
|
+
lexicon[key.toLowerCase()] = value;
|
|
83
|
+
}
|
|
84
|
+
const boosters = {};
|
|
85
|
+
if (input.boosters) {
|
|
86
|
+
for (const [key, value] of Object.entries(input.boosters)) {
|
|
87
|
+
boosters[key.toLowerCase()] = value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const negation = new Set((input.negation ?? []).map(w => w.toLowerCase()));
|
|
91
|
+
const idioms = {};
|
|
92
|
+
let idiomMaxLength = 0;
|
|
93
|
+
if (input.idioms) {
|
|
94
|
+
for (const [key, value] of Object.entries(input.idioms)) {
|
|
95
|
+
const normalized = key.toLowerCase();
|
|
96
|
+
idioms[normalized] = value;
|
|
97
|
+
const wordCount = normalized.split(/\s+/).length;
|
|
98
|
+
if (wordCount > idiomMaxLength) {
|
|
99
|
+
idiomMaxLength = wordCount;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
lexicon,
|
|
105
|
+
boosters,
|
|
106
|
+
negation,
|
|
107
|
+
idioms,
|
|
108
|
+
_idiomMaxLength: idiomMaxLength
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/engines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@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentiment Engine
|
|
3
|
+
*
|
|
4
|
+
* Text sentiment analysis engine that scores text using dictionary-lookup
|
|
5
|
+
* and heuristic rules. Supports token-level, document-level, and aspect-based
|
|
6
|
+
* analysis strategies with injectable lexicon configuration.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const engine = new SentimentEngine();
|
|
11
|
+
* engine.add({ type: 'Review', data: { text: 'The product is absolutely fantastic!' } });
|
|
12
|
+
*
|
|
13
|
+
* const result = engine.execute(compiledRuleset);
|
|
14
|
+
* console.log(result.compound); // 0.85 (positive)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import { WorkingMemory, Fact, FactInput, FactChange } from '../../core';
|
|
18
|
+
import type { CompiledSentimentRuleSet, SentimentOptions, SentimentResult } from './types';
|
|
19
|
+
export declare class SentimentEngine {
|
|
20
|
+
private wm;
|
|
21
|
+
private strategy;
|
|
22
|
+
constructor(workingMemory?: WorkingMemory);
|
|
23
|
+
add<T = Record<string, any>>(input: FactInput<T>): Fact<T>;
|
|
24
|
+
remove(factId: string): Fact | undefined;
|
|
25
|
+
update<T = Record<string, any>>(input: FactInput<T>): Fact<T>;
|
|
26
|
+
get(factId: string): Fact | undefined;
|
|
27
|
+
getByType(type: string): Fact[];
|
|
28
|
+
getAll(): Fact[];
|
|
29
|
+
has(factId: string): boolean;
|
|
30
|
+
size(): number;
|
|
31
|
+
clear(): void;
|
|
32
|
+
getChanges(): FactChange[];
|
|
33
|
+
clearChanges(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Execute a sentiment analysis ruleset.
|
|
36
|
+
*
|
|
37
|
+
* Extracts text from all facts in working memory, applies the configured
|
|
38
|
+
* sentiment strategy, and returns compound scores with token-level detail.
|
|
39
|
+
*
|
|
40
|
+
* @param ruleSet - Compiled sentiment ruleset
|
|
41
|
+
* @param options - Runtime options (onToken callback)
|
|
42
|
+
* @returns Sentiment result with compound score, label, and detail
|
|
43
|
+
*/
|
|
44
|
+
execute(ruleSet: CompiledSentimentRuleSet, options?: SentimentOptions): SentimentResult;
|
|
45
|
+
getWorkingMemory(): WorkingMemory;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/engines/sentiment/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,aAAa,EACb,IAAI,EACJ,SAAS,EACT,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAIjB,qBAAa,eAAe;IAC1B,OAAO,CAAC,EAAE,CAAgB;IAC1B,OAAO,CAAC,QAAQ,CAAoB;gBAExB,aAAa,CAAC,EAAE,aAAa;IASzC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAI1D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIxC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAI7D,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIrC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE;IAI/B,MAAM,IAAI,IAAI,EAAE;IAIhB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,IAAI;IAIb,UAAU,IAAI,UAAU,EAAE;IAI1B,YAAY,IAAI,IAAI;IAQpB;;;;;;;;;OASG;IACH,OAAO,CACL,OAAO,EAAE,wBAAwB,EACjC,OAAO,GAAE,gBAAqB,GAC7B,eAAe;IAQlB,gBAAgB,IAAI,aAAa;CAGlC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sentiment Engine
|
|
4
|
+
*
|
|
5
|
+
* Text sentiment analysis engine that scores text using dictionary-lookup
|
|
6
|
+
* and heuristic rules. Supports token-level, document-level, and aspect-based
|
|
7
|
+
* analysis strategies with injectable lexicon configuration.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const engine = new SentimentEngine();
|
|
12
|
+
* engine.add({ type: 'Review', data: { text: 'The product is absolutely fantastic!' } });
|
|
13
|
+
*
|
|
14
|
+
* const result = engine.execute(compiledRuleset);
|
|
15
|
+
* console.log(result.compound); // 0.85 (positive)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SentimentEngine = void 0;
|
|
20
|
+
const core_1 = require("../../core");
|
|
21
|
+
const strategy_1 = require("./strategy");
|
|
22
|
+
class SentimentEngine {
|
|
23
|
+
wm;
|
|
24
|
+
strategy;
|
|
25
|
+
constructor(workingMemory) {
|
|
26
|
+
this.wm = workingMemory ?? new core_1.WorkingMemory();
|
|
27
|
+
this.strategy = new strategy_1.SentimentExecutor();
|
|
28
|
+
}
|
|
29
|
+
// ========================================
|
|
30
|
+
// IWorkingMemory Implementation
|
|
31
|
+
// ========================================
|
|
32
|
+
add(input) {
|
|
33
|
+
return this.wm.add(input);
|
|
34
|
+
}
|
|
35
|
+
remove(factId) {
|
|
36
|
+
return this.wm.remove(factId);
|
|
37
|
+
}
|
|
38
|
+
update(input) {
|
|
39
|
+
return this.wm.update(input);
|
|
40
|
+
}
|
|
41
|
+
get(factId) {
|
|
42
|
+
return this.wm.get(factId);
|
|
43
|
+
}
|
|
44
|
+
getByType(type) {
|
|
45
|
+
return this.wm.getByType(type);
|
|
46
|
+
}
|
|
47
|
+
getAll() {
|
|
48
|
+
return this.wm.getAll();
|
|
49
|
+
}
|
|
50
|
+
has(factId) {
|
|
51
|
+
return this.wm.has(factId);
|
|
52
|
+
}
|
|
53
|
+
size() {
|
|
54
|
+
return this.wm.size();
|
|
55
|
+
}
|
|
56
|
+
clear() {
|
|
57
|
+
this.wm.clear();
|
|
58
|
+
}
|
|
59
|
+
getChanges() {
|
|
60
|
+
return this.wm.getChanges();
|
|
61
|
+
}
|
|
62
|
+
clearChanges() {
|
|
63
|
+
this.wm.clearChanges();
|
|
64
|
+
}
|
|
65
|
+
// ========================================
|
|
66
|
+
// Engine Execution
|
|
67
|
+
// ========================================
|
|
68
|
+
/**
|
|
69
|
+
* Execute a sentiment analysis ruleset.
|
|
70
|
+
*
|
|
71
|
+
* Extracts text from all facts in working memory, applies the configured
|
|
72
|
+
* sentiment strategy, and returns compound scores with token-level detail.
|
|
73
|
+
*
|
|
74
|
+
* @param ruleSet - Compiled sentiment ruleset
|
|
75
|
+
* @param options - Runtime options (onToken callback)
|
|
76
|
+
* @returns Sentiment result with compound score, label, and detail
|
|
77
|
+
*/
|
|
78
|
+
execute(ruleSet, options = {}) {
|
|
79
|
+
return this.strategy.run(ruleSet, this.wm, options);
|
|
80
|
+
}
|
|
81
|
+
// ========================================
|
|
82
|
+
// Utility Methods
|
|
83
|
+
// ========================================
|
|
84
|
+
getWorkingMemory() {
|
|
85
|
+
return this.wm;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.SentimentEngine = SentimentEngine;
|
|
89
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/engines/sentiment/engine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,qCAK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AE,CAAC,YAAY,EAAE,CAAC;IACzB,CAAC;IAED,2CAA2C;IAC3C,mBAAmB;IACnB,2CAA2C;IAE3C;;;;;;;;;OASG;IACH,OAAO,CACL,OAAiC,EACjC,UAA4B,EAAE;QAE9B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,2CAA2C;IAC3C,kBAAkB;IAClB,2CAA2C;IAE3C,gBAAgB;QACd,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;CACF;AArFD,0CAqFC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentiment Engine -- Text Sentiment Analysis
|
|
3
|
+
*/
|
|
4
|
+
export type { SentimentStrategy, SentimentLabel, SentimentLexicon, CompiledSentimentLexicon, SentimentConfig, TokenLevelSentimentRuleSet, DocumentLevelSentimentRuleSet, AspectBasedSentimentRuleSet, SentimentRuleSet, CompiledTokenLevelSentimentRuleSet, CompiledDocumentLevelSentimentRuleSet, CompiledAspectBasedSentimentRuleSet, CompiledSentimentRuleSet, TokenModifier, TokenScore, SentenceResult, AspectResult, SentimentResult, SentimentOptions } from './types';
|
|
5
|
+
export { SENTIMENT_DEFAULTS, resolveSentimentLabel } from './types';
|
|
6
|
+
export { compileSentimentRuleSet } from './compiler';
|
|
7
|
+
export { SentimentExecutor, sentimentStrategy } from './strategy';
|
|
8
|
+
export { SentimentEngine } from './engine';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/engines/sentiment/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,eAAe,EACf,0BAA0B,EAC1B,6BAA6B,EAC7B,2BAA2B,EAC3B,gBAAgB,EAChB,kCAAkC,EAClC,qCAAqC,EACrC,mCAAmC,EACnC,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sentiment Engine -- Text Sentiment Analysis
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SentimentEngine = exports.sentimentStrategy = exports.SentimentExecutor = exports.compileSentimentRuleSet = exports.resolveSentimentLabel = exports.SENTIMENT_DEFAULTS = void 0;
|
|
7
|
+
// Constants & utilities
|
|
8
|
+
var types_1 = require("./types");
|
|
9
|
+
Object.defineProperty(exports, "SENTIMENT_DEFAULTS", { enumerable: true, get: function () { return types_1.SENTIMENT_DEFAULTS; } });
|
|
10
|
+
Object.defineProperty(exports, "resolveSentimentLabel", { enumerable: true, get: function () { return types_1.resolveSentimentLabel; } });
|
|
11
|
+
// Compiler
|
|
12
|
+
var compiler_1 = require("./compiler");
|
|
13
|
+
Object.defineProperty(exports, "compileSentimentRuleSet", { enumerable: true, get: function () { return compiler_1.compileSentimentRuleSet; } });
|
|
14
|
+
// Strategy
|
|
15
|
+
var strategy_1 = require("./strategy");
|
|
16
|
+
Object.defineProperty(exports, "SentimentExecutor", { enumerable: true, get: function () { return strategy_1.SentimentExecutor; } });
|
|
17
|
+
Object.defineProperty(exports, "sentimentStrategy", { enumerable: true, get: function () { return strategy_1.sentimentStrategy; } });
|
|
18
|
+
// Engine
|
|
19
|
+
var engine_1 = require("./engine");
|
|
20
|
+
Object.defineProperty(exports, "SentimentEngine", { enumerable: true, get: function () { return engine_1.SentimentEngine; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engines/sentiment/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAyBH,wBAAwB;AACxB,iCAGiB;AAFf,2GAAA,kBAAkB,OAAA;AAClB,8GAAA,qBAAqB,OAAA;AAGvB,WAAW;AACX,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAEhC,WAAW;AACX,uCAAkE;AAAzD,6GAAA,iBAAiB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAE7C,SAAS;AACT,mCAA2C;AAAlC,yGAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentiment Engine Strategy
|
|
3
|
+
*
|
|
4
|
+
* Core execution logic for all sentiment strategies:
|
|
5
|
+
* - token-level: Score individual tokens in the full text
|
|
6
|
+
* - document-level: Split into sentences, score each, average compounds
|
|
7
|
+
* - aspect-based: Match sentences to aspect terms, score per aspect
|
|
8
|
+
*/
|
|
9
|
+
import type { IWorkingMemory } from '../../core';
|
|
10
|
+
import type { CompiledSentimentRuleSet, SentimentOptions, SentimentResult } from './types';
|
|
11
|
+
export declare class SentimentExecutor {
|
|
12
|
+
run(ruleSet: CompiledSentimentRuleSet, wm: IWorkingMemory, options?: SentimentOptions): SentimentResult;
|
|
13
|
+
private runTokenLevel;
|
|
14
|
+
private runDocumentLevel;
|
|
15
|
+
private runAspectBased;
|
|
16
|
+
}
|
|
17
|
+
/** Singleton instance */
|
|
18
|
+
export declare const sentimentStrategy: SentimentExecutor;
|
|
19
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/engines/sentiment/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAQ,MAAM,YAAY,CAAC;AAEvD,OAAO,KAAK,EACV,wBAAwB,EAKxB,gBAAgB,EAChB,eAAe,EAKhB,MAAM,SAAS,CAAC;AAiQjB,qBAAa,iBAAiB;IAC5B,GAAG,CACD,OAAO,EAAE,wBAAwB,EACjC,EAAE,EAAE,cAAc,EAClB,OAAO,GAAE,gBAAqB,GAC7B,eAAe;IA+BlB,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,gBAAgB;IAiExB,OAAO,CAAC,cAAc;CAoEvB;AA0BD,yBAAyB;AACzB,eAAO,MAAM,iBAAiB,mBAA0B,CAAC"}
|