scrivener-mcp 0.3.0 → 0.3.2
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 +207 -15
- package/dist/analysis/advanced-readability.d.ts +168 -0
- package/dist/analysis/advanced-readability.d.ts.map +1 -0
- package/dist/analysis/advanced-readability.js +730 -0
- package/dist/analysis/advanced-readability.js.map +1 -0
- package/dist/analysis/base-analyzer.d.ts +188 -0
- package/dist/analysis/base-analyzer.d.ts.map +1 -0
- package/dist/analysis/base-analyzer.js +846 -0
- package/dist/analysis/base-analyzer.js.map +1 -0
- package/dist/analysis/context-analyzer.d.ts +183 -0
- package/dist/analysis/context-analyzer.d.ts.map +1 -0
- package/dist/analysis/context-analyzer.js +582 -0
- package/dist/analysis/context-analyzer.js.map +1 -0
- package/dist/analysis/index.d.ts +8 -0
- package/dist/analysis/index.d.ts.map +1 -0
- package/dist/analysis/index.js +6 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/ml-word-classifier-pro.d.ts +108 -0
- package/dist/analysis/ml-word-classifier-pro.d.ts.map +1 -0
- package/dist/analysis/ml-word-classifier-pro.js +475 -0
- package/dist/analysis/ml-word-classifier-pro.js.map +1 -0
- package/dist/cli/setup-wizard.d.ts +34 -0
- package/dist/cli/setup-wizard.d.ts.map +1 -0
- package/dist/cli/setup-wizard.js +150 -0
- package/dist/cli/setup-wizard.js.map +1 -0
- package/dist/content-analyzer.d.ts +85 -1
- package/dist/content-analyzer.d.ts.map +1 -1
- package/dist/content-analyzer.js +515 -111
- package/dist/content-analyzer.js.map +1 -1
- package/dist/core/cache.d.ts +90 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +240 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/constants.d.ts +222 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +178 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/errors.d.ts +118 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +184 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/logger.d.ts +40 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +116 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/validation.d.ts +82 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +208 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/database/auto-installer.d.ts +99 -0
- package/dist/database/auto-installer.d.ts.map +1 -0
- package/dist/database/auto-installer.js +574 -0
- package/dist/database/auto-installer.js.map +1 -0
- package/dist/database/config.d.ts +29 -0
- package/dist/database/config.d.ts.map +1 -0
- package/dist/database/config.js +24 -0
- package/dist/database/config.js.map +1 -0
- package/dist/database/connection-pool.d.ts +87 -0
- package/dist/database/connection-pool.d.ts.map +1 -0
- package/dist/database/connection-pool.js +253 -0
- package/dist/database/connection-pool.js.map +1 -0
- package/dist/database/database-service.d.ts +223 -0
- package/dist/database/database-service.d.ts.map +1 -0
- package/dist/database/database-service.js +691 -0
- package/dist/database/database-service.js.map +1 -0
- package/dist/database/database-setup.d.ts +53 -0
- package/dist/database/database-setup.d.ts.map +1 -0
- package/dist/database/database-setup.js +257 -0
- package/dist/database/database-setup.js.map +1 -0
- package/dist/database/graph-analytics.d.ts +87 -0
- package/dist/database/graph-analytics.d.ts.map +1 -0
- package/dist/database/graph-analytics.js +317 -0
- package/dist/database/graph-analytics.js.map +1 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +5 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/migrations.d.ts +58 -0
- package/dist/database/migrations.d.ts.map +1 -0
- package/dist/database/migrations.js +351 -0
- package/dist/database/migrations.js.map +1 -0
- package/dist/database/neo4j-manager.d.ts +120 -0
- package/dist/database/neo4j-manager.d.ts.map +1 -0
- package/dist/database/neo4j-manager.js +450 -0
- package/dist/database/neo4j-manager.js.map +1 -0
- package/dist/database/query-builder.d.ts +87 -0
- package/dist/database/query-builder.d.ts.map +1 -0
- package/dist/database/query-builder.js +265 -0
- package/dist/database/query-builder.js.map +1 -0
- package/dist/database/search-service.d.ts +80 -0
- package/dist/database/search-service.d.ts.map +1 -0
- package/dist/database/search-service.js +343 -0
- package/dist/database/search-service.js.map +1 -0
- package/dist/database/sqlite-manager.d.ts +81 -0
- package/dist/database/sqlite-manager.d.ts.map +1 -0
- package/dist/database/sqlite-manager.js +356 -0
- package/dist/database/sqlite-manager.js.map +1 -0
- package/dist/database/story-intelligence.d.ts +88 -0
- package/dist/database/story-intelligence.d.ts.map +1 -0
- package/dist/database/story-intelligence.js +457 -0
- package/dist/database/story-intelligence.js.map +1 -0
- package/dist/database/writing-analytics.d.ts +95 -0
- package/dist/database/writing-analytics.d.ts.map +1 -0
- package/dist/database/writing-analytics.js +387 -0
- package/dist/database/writing-analytics.js.map +1 -0
- package/dist/handlers/analysis-handlers.d.ts +12 -0
- package/dist/handlers/analysis-handlers.d.ts.map +1 -0
- package/dist/handlers/analysis-handlers.js +611 -0
- package/dist/handlers/analysis-handlers.js.map +1 -0
- package/dist/handlers/compilation-handlers.d.ts +6 -0
- package/dist/handlers/compilation-handlers.d.ts.map +1 -0
- package/dist/handlers/compilation-handlers.js +141 -0
- package/dist/handlers/compilation-handlers.js.map +1 -0
- package/dist/handlers/document-handlers.d.ts +13 -0
- package/dist/handlers/document-handlers.d.ts.map +1 -0
- package/dist/handlers/document-handlers.js +353 -0
- package/dist/handlers/document-handlers.js.map +1 -0
- package/dist/handlers/index.d.ts +26 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +85 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/project-handlers.d.ts +10 -0
- package/dist/handlers/project-handlers.d.ts.map +1 -0
- package/dist/handlers/project-handlers.js +163 -0
- package/dist/handlers/project-handlers.js.map +1 -0
- package/dist/handlers/search-handlers.d.ts +8 -0
- package/dist/handlers/search-handlers.d.ts.map +1 -0
- package/dist/handlers/search-handlers.js +185 -0
- package/dist/handlers/search-handlers.js.map +1 -0
- package/dist/handlers/types.d.ts +40 -0
- package/dist/handlers/types.d.ts.map +1 -0
- package/dist/handlers/types.js +26 -0
- package/dist/handlers/types.js.map +1 -0
- package/dist/handlers/validation-schemas.d.ts +23 -0
- package/dist/handlers/validation-schemas.d.ts.map +1 -0
- package/dist/handlers/validation-schemas.js +90 -0
- package/dist/handlers/validation-schemas.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -1246
- package/dist/index.js.map +1 -1
- package/dist/memory-manager.d.ts +20 -4
- package/dist/memory-manager.d.ts.map +1 -1
- package/dist/memory-manager.js +265 -33
- package/dist/memory-manager.js.map +1 -1
- package/dist/scrivener-project.d.ts +96 -166
- package/dist/scrivener-project.d.ts.map +1 -1
- package/dist/scrivener-project.js +386 -766
- package/dist/scrivener-project.js.map +1 -1
- package/dist/services/compilation-service.d.ts +71 -0
- package/dist/services/compilation-service.d.ts.map +1 -0
- package/dist/services/compilation-service.js +438 -0
- package/dist/services/compilation-service.js.map +1 -0
- package/dist/services/document-manager.d.ts +70 -0
- package/dist/services/document-manager.d.ts.map +1 -0
- package/dist/services/document-manager.js +429 -0
- package/dist/services/document-manager.js.map +1 -0
- package/dist/{content-enhancer.d.ts → services/enhancements/content-enhancer.d.ts} +58 -19
- package/dist/services/enhancements/content-enhancer.d.ts.map +1 -0
- package/dist/services/enhancements/content-enhancer.js +1869 -0
- package/dist/services/enhancements/content-enhancer.js.map +1 -0
- package/dist/services/enhancements/filter-words.d.ts +15 -0
- package/dist/services/enhancements/filter-words.d.ts.map +1 -0
- package/dist/services/enhancements/filter-words.js +158 -0
- package/dist/services/enhancements/filter-words.js.map +1 -0
- package/dist/services/metadata-manager.d.ts +79 -0
- package/dist/services/metadata-manager.d.ts.map +1 -0
- package/dist/services/metadata-manager.js +442 -0
- package/dist/services/metadata-manager.js.map +1 -0
- package/dist/services/openai-service.d.ts +199 -0
- package/dist/services/openai-service.d.ts.map +1 -0
- package/dist/services/openai-service.js +825 -0
- package/dist/services/openai-service.js.map +1 -0
- package/dist/services/parsers/rtf-handler.d.ts.map +1 -0
- package/dist/{rtf-handler.js → services/parsers/rtf-handler.js} +3 -3
- package/dist/services/parsers/rtf-handler.js.map +1 -0
- package/dist/services/project-loader.d.ts +78 -0
- package/dist/services/project-loader.d.ts.map +1 -0
- package/dist/services/project-loader.js +344 -0
- package/dist/services/project-loader.js.map +1 -0
- package/dist/services/web-content-parser.d.ts +138 -0
- package/dist/services/web-content-parser.d.ts.map +1 -0
- package/dist/services/web-content-parser.js +516 -0
- package/dist/services/web-content-parser.js.map +1 -0
- package/dist/sync/context-sync.d.ts +116 -0
- package/dist/sync/context-sync.d.ts.map +1 -0
- package/dist/sync/context-sync.js +490 -0
- package/dist/sync/context-sync.js.map +1 -0
- package/dist/types/database.d.ts +158 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/database.js +5 -0
- package/dist/types/database.js.map +1 -0
- package/dist/types/enhancements.d.ts +74 -0
- package/dist/types/enhancements.d.ts.map +1 -0
- package/dist/types/enhancements.js +5 -0
- package/dist/types/enhancements.js.map +1 -0
- package/dist/types/index.d.ts +314 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/internal.d.ts.map +1 -1
- package/dist/types/internal.js.map +1 -1
- package/dist/utils/common.d.ts +197 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +535 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/database.d.ts +148 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js +424 -0
- package/dist/utils/database.js.map +1 -0
- package/dist/utils/scrivener-utils.d.ts +246 -0
- package/dist/utils/scrivener-utils.d.ts.map +1 -0
- package/dist/utils/scrivener-utils.js +485 -0
- package/dist/utils/scrivener-utils.js.map +1 -0
- package/package.json +34 -8
- package/scripts/config-template.json +8 -0
- package/scripts/setup.cjs +94 -0
- package/scripts/setup.js +15 -0
- package/dist/content-enhancer.d.ts.map +0 -1
- package/dist/content-enhancer.js +0 -745
- package/dist/content-enhancer.js.map +0 -1
- package/dist/rtf-handler.d.ts.map +0 -1
- package/dist/rtf-handler.js.map +0 -1
- /package/dist/{rtf-handler.d.ts → services/parsers/rtf-handler.d.ts} +0 -0
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
// import type { ScrivenerDocument } from '../scrivener-project.js';
|
|
11
|
+
import { cached, caches } from '../core/cache.js';
|
|
12
|
+
import { getLogger } from '../core/logger.js';
|
|
13
|
+
import { openaiService } from '../services/openai-service.js';
|
|
14
|
+
import { webContentParser } from '../services/web-content-parser.js';
|
|
15
|
+
import { advancedReadabilityService } from './advanced-readability.js';
|
|
16
|
+
import { classifier as wordClassifier } from './ml-word-classifier-pro.js';
|
|
17
|
+
const logger = getLogger('content-analyzer');
|
|
18
|
+
export class ContentAnalyzer {
|
|
19
|
+
// ML classifier replaces hardcoded word lists
|
|
20
|
+
classifier = wordClassifier;
|
|
21
|
+
// Keep only for backward compatibility reference
|
|
22
|
+
commonWords = new Set([
|
|
23
|
+
'the',
|
|
24
|
+
'a',
|
|
25
|
+
'an',
|
|
26
|
+
'and',
|
|
27
|
+
'or',
|
|
28
|
+
'but',
|
|
29
|
+
'in',
|
|
30
|
+
'on',
|
|
31
|
+
'at',
|
|
32
|
+
'to',
|
|
33
|
+
'for',
|
|
34
|
+
'of',
|
|
35
|
+
'with',
|
|
36
|
+
'as',
|
|
37
|
+
'by',
|
|
38
|
+
'that',
|
|
39
|
+
'this',
|
|
40
|
+
'it',
|
|
41
|
+
'is',
|
|
42
|
+
'was',
|
|
43
|
+
'are',
|
|
44
|
+
'were',
|
|
45
|
+
'be',
|
|
46
|
+
'been',
|
|
47
|
+
'being',
|
|
48
|
+
'have',
|
|
49
|
+
'has',
|
|
50
|
+
'had',
|
|
51
|
+
'do',
|
|
52
|
+
'does',
|
|
53
|
+
'did',
|
|
54
|
+
'will',
|
|
55
|
+
'would',
|
|
56
|
+
'could',
|
|
57
|
+
'should',
|
|
58
|
+
]);
|
|
59
|
+
// Filter words are now detected dynamically by ML classifier
|
|
60
|
+
// Remove unused hardcoded list
|
|
61
|
+
clichePhrases = [
|
|
62
|
+
'dark and stormy night',
|
|
63
|
+
'in the nick of time',
|
|
64
|
+
'avoid like the plague',
|
|
65
|
+
'dead as a doornail',
|
|
66
|
+
'fit as a fiddle',
|
|
67
|
+
'time will tell',
|
|
68
|
+
'only time will tell',
|
|
69
|
+
'lost track of time',
|
|
70
|
+
'all walks of life',
|
|
71
|
+
'calm before the storm',
|
|
72
|
+
'cry over spilled milk',
|
|
73
|
+
'every cloud has a silver lining',
|
|
74
|
+
];
|
|
75
|
+
async analyzeContent(content, documentId) {
|
|
76
|
+
logger.debug(`Analyzing content for document ${documentId}`);
|
|
77
|
+
const metrics = this.calculateMetrics(content);
|
|
78
|
+
const style = this.analyzeStyle(content);
|
|
79
|
+
const structure = this.analyzeStructure(content);
|
|
80
|
+
const quality = this.assessQuality(content);
|
|
81
|
+
const suggestions = this.generateSuggestions(content, metrics, style, quality);
|
|
82
|
+
const emotions = this.analyzeEmotions(content);
|
|
83
|
+
const pacing = this.analyzePacing(content);
|
|
84
|
+
return {
|
|
85
|
+
documentId,
|
|
86
|
+
timestamp: new Date().toISOString(),
|
|
87
|
+
metrics,
|
|
88
|
+
style,
|
|
89
|
+
structure,
|
|
90
|
+
quality,
|
|
91
|
+
suggestions,
|
|
92
|
+
emotions,
|
|
93
|
+
pacing,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
calculateMetrics(content) {
|
|
97
|
+
const words = content.split(/\s+/).filter((w) => w.length > 0);
|
|
98
|
+
const sentences = content.split(/[.!?]+/).filter((s) => s.trim().length > 0);
|
|
99
|
+
const paragraphs = content.split(/\n\n+/).filter((p) => p.trim().length > 0);
|
|
100
|
+
const wordCount = words.length;
|
|
101
|
+
const sentenceCount = sentences.length;
|
|
102
|
+
const paragraphCount = paragraphs.length;
|
|
103
|
+
const averageSentenceLength = sentenceCount > 0 ? wordCount / sentenceCount : 0;
|
|
104
|
+
const averageParagraphLength = paragraphCount > 0 ? wordCount / paragraphCount : 0;
|
|
105
|
+
const readingTime = Math.ceil(wordCount / 250); // Average reading speed
|
|
106
|
+
// Calculate readability scores
|
|
107
|
+
const { fleschReadingEase, fleschKincaidGrade } = this.calculateReadability(wordCount, sentenceCount, this.countSyllables(words));
|
|
108
|
+
return {
|
|
109
|
+
wordCount,
|
|
110
|
+
sentenceCount,
|
|
111
|
+
paragraphCount,
|
|
112
|
+
averageSentenceLength,
|
|
113
|
+
averageParagraphLength,
|
|
114
|
+
readingTime,
|
|
115
|
+
fleschReadingEase,
|
|
116
|
+
fleschKincaidGrade,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
analyzeStyle(content) {
|
|
120
|
+
const sentences = content.split(/[.!?]+/).filter((s) => s.trim().length > 0);
|
|
121
|
+
const words = content
|
|
122
|
+
.toLowerCase()
|
|
123
|
+
.split(/\s+/)
|
|
124
|
+
.filter((w) => w.length > 0);
|
|
125
|
+
// Sentence variety
|
|
126
|
+
const sentenceLengths = sentences.map((s) => s.split(/\s+/).length);
|
|
127
|
+
const lengthVariance = this.calculateVariance(sentenceLengths);
|
|
128
|
+
const sentenceVariety = lengthVariance > 50 ? 'high' : lengthVariance > 20 ? 'medium' : 'low';
|
|
129
|
+
// Vocabulary complexity
|
|
130
|
+
// const uniqueWords = new Set(words);
|
|
131
|
+
const complexWords = words.filter((w) => this.countSyllables([w]) > 2).length;
|
|
132
|
+
const vocabularyComplexity = complexWords / words.length > 0.3
|
|
133
|
+
? 'advanced'
|
|
134
|
+
: complexWords / words.length > 0.2
|
|
135
|
+
? 'complex'
|
|
136
|
+
: complexWords / words.length > 0.1
|
|
137
|
+
? 'moderate'
|
|
138
|
+
: 'simple';
|
|
139
|
+
// Adverb usage
|
|
140
|
+
const adverbs = words.filter((w) => w.endsWith('ly')).length;
|
|
141
|
+
const adverbUsage = adverbs / words.length > 0.05
|
|
142
|
+
? 'heavy'
|
|
143
|
+
: adverbs / words.length > 0.02
|
|
144
|
+
? 'moderate'
|
|
145
|
+
: 'minimal';
|
|
146
|
+
// Passive voice - detect using pattern-based auxiliary verb detection
|
|
147
|
+
const passiveCount = words.filter((w) => this.isPassiveIndicator(w)).length;
|
|
148
|
+
const passiveVoicePercentage = (passiveCount / sentences.length) * 100;
|
|
149
|
+
// Dialogue vs description
|
|
150
|
+
const dialogueLines = content
|
|
151
|
+
.split('\n')
|
|
152
|
+
.filter((line) => line.includes('"') || line.includes("'"));
|
|
153
|
+
const dialoguePercentage = (dialogueLines.length / content.split('\n').length) * 100;
|
|
154
|
+
const descriptionPercentage = 100 - dialoguePercentage;
|
|
155
|
+
// Most frequent words (excluding common words)
|
|
156
|
+
const wordFrequency = new Map();
|
|
157
|
+
words.forEach((word) => {
|
|
158
|
+
if (!this.commonWords.has(word) && word.length > 3) {
|
|
159
|
+
wordFrequency.set(word, (wordFrequency.get(word) || 0) + 1);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const mostFrequentWords = Array.from(wordFrequency.entries())
|
|
163
|
+
.sort((a, b) => b[1] - a[1])
|
|
164
|
+
.slice(0, 10)
|
|
165
|
+
.map(([word, count]) => ({ word, count }));
|
|
166
|
+
return {
|
|
167
|
+
sentenceVariety,
|
|
168
|
+
vocabularyComplexity,
|
|
169
|
+
adverbUsage,
|
|
170
|
+
passiveVoicePercentage,
|
|
171
|
+
dialoguePercentage,
|
|
172
|
+
descriptionPercentage,
|
|
173
|
+
mostFrequentWords,
|
|
174
|
+
styleConsistency: 85, // Simplified for now
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
analyzeStructure(content) {
|
|
178
|
+
const lines = content.split('\n');
|
|
179
|
+
const paragraphs = content.split(/\n\n+/);
|
|
180
|
+
// Scene breaks (looking for common indicators)
|
|
181
|
+
const sceneBreaks = lines.filter((line) => line.trim() === '***' || line.trim() === '* * *' || line.trim() === '#').length;
|
|
182
|
+
// Chapters (looking for chapter headings)
|
|
183
|
+
const chapters = lines.filter((line) => /^(Chapter|CHAPTER|Ch\.|Part|PART)\s+\d+/i.test(line.trim())).length;
|
|
184
|
+
const averageSceneLength = sceneBreaks > 0 ? content.length / (sceneBreaks + 1) : content.length;
|
|
185
|
+
// Opening and ending analysis
|
|
186
|
+
const firstParagraph = paragraphs[0] || '';
|
|
187
|
+
const lastParagraph = paragraphs[paragraphs.length - 1] || '';
|
|
188
|
+
const openingStrength = this.assessOpeningStrength(firstParagraph);
|
|
189
|
+
const endingStrength = this.assessEndingStrength(lastParagraph);
|
|
190
|
+
const hookPresence = this.detectHook(firstParagraph);
|
|
191
|
+
const cliffhangers = this.countCliffhangers(paragraphs);
|
|
192
|
+
return {
|
|
193
|
+
sceneBreaks,
|
|
194
|
+
chapters,
|
|
195
|
+
averageSceneLength,
|
|
196
|
+
openingStrength,
|
|
197
|
+
endingStrength,
|
|
198
|
+
hookPresence,
|
|
199
|
+
cliffhangers,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
assessQuality(content) {
|
|
203
|
+
const words = content.toLowerCase().split(/\s+/);
|
|
204
|
+
const sentences = content.split(/[.!?]+/).filter((s) => s.trim().length > 0);
|
|
205
|
+
// Repetitiveness
|
|
206
|
+
const wordPairs = new Map();
|
|
207
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
208
|
+
const pair = `${words[i]} ${words[i + 1]}`;
|
|
209
|
+
wordPairs.set(pair, (wordPairs.get(pair) || 0) + 1);
|
|
210
|
+
}
|
|
211
|
+
const repetitivePairs = Array.from(wordPairs.values()).filter((count) => count > 2).length;
|
|
212
|
+
const repetitiveness = Math.min((repetitivePairs / wordPairs.size) * 100, 100);
|
|
213
|
+
// Cliches
|
|
214
|
+
const foundClichés = this.clichePhrases.filter((cliché) => content.toLowerCase().includes(cliché));
|
|
215
|
+
// Filter words - use ML classifier instead of hardcoded list
|
|
216
|
+
const foundFilterWords = [];
|
|
217
|
+
const processedWords = new Set();
|
|
218
|
+
for (let i = 0; i < words.length; i++) {
|
|
219
|
+
const word = words[i];
|
|
220
|
+
if (!processedWords.has(word)) {
|
|
221
|
+
// Find the word's position in the original content
|
|
222
|
+
const wordIndex = content
|
|
223
|
+
.toLowerCase()
|
|
224
|
+
.indexOf(word, i > 0 ? content.toLowerCase().indexOf(words[i - 1]) : 0);
|
|
225
|
+
const classification = this.classifier.classify(word, content, wordIndex);
|
|
226
|
+
if (classification.isFilterWord && classification.confidence > 0.5) {
|
|
227
|
+
foundFilterWords.push(word);
|
|
228
|
+
processedWords.add(word);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Telling vs showing (pattern-based cognitive verb detection)
|
|
233
|
+
const tellingCount = words.filter((w) => this.isCognitiveVerb(w)).length;
|
|
234
|
+
const actionWords = words.filter((w) => w.endsWith('ed') || w.endsWith('ing')).length;
|
|
235
|
+
const tellingVsShowing = tellingCount / Math.max(actionWords, 1);
|
|
236
|
+
// Sensory details
|
|
237
|
+
const sensoryWords = [
|
|
238
|
+
'saw',
|
|
239
|
+
'heard',
|
|
240
|
+
'smelled',
|
|
241
|
+
'tasted',
|
|
242
|
+
'touched',
|
|
243
|
+
'felt',
|
|
244
|
+
'bright',
|
|
245
|
+
'dark',
|
|
246
|
+
'loud',
|
|
247
|
+
'quiet',
|
|
248
|
+
'soft',
|
|
249
|
+
'hard',
|
|
250
|
+
'sweet',
|
|
251
|
+
'bitter',
|
|
252
|
+
];
|
|
253
|
+
const sensoryCount = words.filter((w) => sensoryWords.some((s) => w.includes(s))).length;
|
|
254
|
+
const sensoryDetails = sensoryCount / sentences.length > 1
|
|
255
|
+
? 'rich'
|
|
256
|
+
: sensoryCount / sentences.length > 0.5
|
|
257
|
+
? 'adequate'
|
|
258
|
+
: 'lacking';
|
|
259
|
+
// White space
|
|
260
|
+
const paragraphs = content.split(/\n\n+/);
|
|
261
|
+
const avgParagraphLength = content.length / paragraphs.length;
|
|
262
|
+
const whiteSpace = avgParagraphLength < 200
|
|
263
|
+
? 'balanced'
|
|
264
|
+
: avgParagraphLength < 500
|
|
265
|
+
? 'balanced'
|
|
266
|
+
: avgParagraphLength < 1000
|
|
267
|
+
? 'cramped'
|
|
268
|
+
: 'cramped';
|
|
269
|
+
return {
|
|
270
|
+
repetitiveness,
|
|
271
|
+
cliches: foundClichés,
|
|
272
|
+
filterWords: foundFilterWords,
|
|
273
|
+
tellingVsShowing,
|
|
274
|
+
sensoryDetails,
|
|
275
|
+
whiteSpace,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
generateSuggestions(_content, metrics, style, quality) {
|
|
279
|
+
const suggestions = [];
|
|
280
|
+
// Sentence length suggestions
|
|
281
|
+
if (metrics.averageSentenceLength > 25) {
|
|
282
|
+
suggestions.push({
|
|
283
|
+
type: 'style',
|
|
284
|
+
severity: 'moderate',
|
|
285
|
+
issue: 'Long average sentence length',
|
|
286
|
+
suggestion: 'Consider breaking up longer sentences for better readability.',
|
|
287
|
+
example: 'Split compound sentences at conjunctions like "and" or "but".',
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
// Adverb usage
|
|
291
|
+
if (style.adverbUsage === 'heavy') {
|
|
292
|
+
suggestions.push({
|
|
293
|
+
type: 'style',
|
|
294
|
+
severity: 'minor',
|
|
295
|
+
issue: 'Heavy adverb usage',
|
|
296
|
+
suggestion: 'Replace adverbs with stronger verbs for more impactful writing.',
|
|
297
|
+
example: 'Instead of "walked quickly", use "hurried" or "rushed".',
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
// Passive voice
|
|
301
|
+
if (style.passiveVoicePercentage > 20) {
|
|
302
|
+
suggestions.push({
|
|
303
|
+
type: 'clarity',
|
|
304
|
+
severity: 'moderate',
|
|
305
|
+
issue: 'High passive voice usage',
|
|
306
|
+
suggestion: 'Convert passive constructions to active voice for more engaging prose.',
|
|
307
|
+
example: 'Change "The ball was thrown by John" to "John threw the ball".',
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
// Repetitiveness
|
|
311
|
+
if (quality.repetitiveness > 30) {
|
|
312
|
+
suggestions.push({
|
|
313
|
+
type: 'style',
|
|
314
|
+
severity: 'major',
|
|
315
|
+
issue: 'Repetitive word patterns detected',
|
|
316
|
+
suggestion: 'Vary your word choice and sentence structure to improve flow.',
|
|
317
|
+
example: 'Use synonyms and restructure similar sentences.',
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
// Filter words
|
|
321
|
+
if (quality.filterWords.length > 5) {
|
|
322
|
+
suggestions.push({
|
|
323
|
+
type: 'impact',
|
|
324
|
+
severity: 'minor',
|
|
325
|
+
issue: `Filter words weakening prose: ${quality.filterWords.slice(0, 5).join(', ')}`,
|
|
326
|
+
suggestion: 'Remove or replace filter words for more direct, impactful writing.',
|
|
327
|
+
example: 'Instead of "He thought it was strange", write "It was strange".',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// Clichés
|
|
331
|
+
if (quality.cliches.length > 0) {
|
|
332
|
+
suggestions.push({
|
|
333
|
+
type: 'style',
|
|
334
|
+
severity: 'moderate',
|
|
335
|
+
issue: `Clichés detected: ${quality.cliches.join(', ')}`,
|
|
336
|
+
suggestion: 'Replace clichés with fresh, original descriptions.',
|
|
337
|
+
example: "Create unique metaphors that fit your story's voice.",
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
// Telling vs showing
|
|
341
|
+
if (quality.tellingVsShowing > 0.3) {
|
|
342
|
+
suggestions.push({
|
|
343
|
+
type: 'impact',
|
|
344
|
+
severity: 'major',
|
|
345
|
+
issue: 'High ratio of telling vs showing',
|
|
346
|
+
suggestion: 'Show character emotions and reactions through actions and dialogue.',
|
|
347
|
+
example: 'Instead of "She was angry", write "She slammed the door, her hands trembling".',
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
// Sensory details
|
|
351
|
+
if (quality.sensoryDetails === 'lacking') {
|
|
352
|
+
suggestions.push({
|
|
353
|
+
type: 'impact',
|
|
354
|
+
severity: 'moderate',
|
|
355
|
+
issue: 'Lacking sensory details',
|
|
356
|
+
suggestion: 'Add sight, sound, smell, taste, and touch descriptions to immerse readers.',
|
|
357
|
+
example: 'Describe the environment using multiple senses.',
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
// Sentence length variation
|
|
361
|
+
const sentences = _content.split(/[.!?]+/).filter((s) => s.trim());
|
|
362
|
+
const longSentences = sentences.filter((s) => s.trim().split(/\s+/).length > 30);
|
|
363
|
+
if (metrics.averageSentenceLength > 25 || longSentences.length > 0) {
|
|
364
|
+
suggestions.push({
|
|
365
|
+
type: 'clarity',
|
|
366
|
+
severity: 'moderate',
|
|
367
|
+
issue: longSentences.length > 0
|
|
368
|
+
? 'Very long sentences detected'
|
|
369
|
+
: 'Long average sentence length',
|
|
370
|
+
suggestion: 'Break up long sentences for better readability and flow.',
|
|
371
|
+
example: 'Split complex sentences into shorter, clearer statements.',
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return suggestions;
|
|
375
|
+
}
|
|
376
|
+
analyzeEmotions(content) {
|
|
377
|
+
// Pattern-based emotion detection using semantic field analysis
|
|
378
|
+
const words = content.toLowerCase().split(/\s+/);
|
|
379
|
+
const emotionCounts = new Map();
|
|
380
|
+
const emotionAnalysis = this.analyzeEmotionPatterns(words);
|
|
381
|
+
for (const [emotion, count] of Object.entries(emotionAnalysis)) {
|
|
382
|
+
if (count > 0)
|
|
383
|
+
emotionCounts.set(emotion, count);
|
|
384
|
+
}
|
|
385
|
+
const dominantEmotion = Array.from(emotionCounts.entries()).sort((a, b) => b[1] - a[1])[0]?.[0] || 'neutral';
|
|
386
|
+
// Simplified emotional arc
|
|
387
|
+
const segments = this.splitIntoSegments(content, 5);
|
|
388
|
+
const emotionalArc = segments.map((segment, index) => {
|
|
389
|
+
const segmentEmotions = this.detectSegmentEmotion(segment);
|
|
390
|
+
return {
|
|
391
|
+
position: (index + 1) / segments.length,
|
|
392
|
+
emotion: segmentEmotions.emotion,
|
|
393
|
+
intensity: segmentEmotions.intensity,
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
// Tension level using semantic pattern detection
|
|
397
|
+
const tensionCount = words.filter((w) => this.isConflictWord(w)).length;
|
|
398
|
+
const sentenceCount = content.split(/[.!?]+/).filter((s) => s.trim().length > 0).length;
|
|
399
|
+
const tensionLevel = Math.min((tensionCount / sentenceCount) * 100, 100);
|
|
400
|
+
return {
|
|
401
|
+
dominantEmotion,
|
|
402
|
+
emotionalArc,
|
|
403
|
+
tensionLevel,
|
|
404
|
+
moodConsistency: 75, // Simplified
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
analyzePacing(content) {
|
|
408
|
+
// const paragraphs = content.split(/\n\n+/);
|
|
409
|
+
const sentences = content.split(/[.!?]+/);
|
|
410
|
+
// Analyze sentence lengths for pacing
|
|
411
|
+
const sentenceLengths = sentences.map((s) => s.split(/\s+/).length);
|
|
412
|
+
const avgLength = sentenceLengths.reduce((a, b) => a + b, 0) / sentenceLengths.length;
|
|
413
|
+
// Determine overall pacing
|
|
414
|
+
const overall = avgLength < 10
|
|
415
|
+
? 'fast'
|
|
416
|
+
: avgLength < 15
|
|
417
|
+
? 'moderate'
|
|
418
|
+
: avgLength < 20
|
|
419
|
+
? 'moderate'
|
|
420
|
+
: 'slow';
|
|
421
|
+
// Analyze sections
|
|
422
|
+
const sections = this.splitIntoSegments(content, 3).map((segment, index) => {
|
|
423
|
+
const segmentSentences = segment.split(/[.!?]+/);
|
|
424
|
+
const segmentAvg = segmentSentences.map((s) => s.split(/\s+/).length).reduce((a, b) => a + b, 0) /
|
|
425
|
+
segmentSentences.length;
|
|
426
|
+
return {
|
|
427
|
+
start: index * (100 / 3),
|
|
428
|
+
end: (index + 1) * (100 / 3),
|
|
429
|
+
pace: segmentAvg < 10
|
|
430
|
+
? 'fast'
|
|
431
|
+
: segmentAvg < 20
|
|
432
|
+
? 'moderate'
|
|
433
|
+
: 'slow',
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
// Action vs reflection using morphological pattern analysis
|
|
437
|
+
const words = content.toLowerCase().split(/\s+/);
|
|
438
|
+
const actionCount = words.filter((w) => this.isActionWord(w)).length;
|
|
439
|
+
const reflectionCount = words.filter((w) => this.isReflectionWord(w)).length;
|
|
440
|
+
const actionVsReflection = actionCount / Math.max(reflectionCount, 1);
|
|
441
|
+
// Recommendations
|
|
442
|
+
const recommendedAdjustments = [];
|
|
443
|
+
if (overall === 'slow') {
|
|
444
|
+
recommendedAdjustments.push('Consider shortening sentences and paragraphs to increase pace');
|
|
445
|
+
}
|
|
446
|
+
if (actionVsReflection < 0.5) {
|
|
447
|
+
recommendedAdjustments.push('Add more action sequences to balance reflection');
|
|
448
|
+
}
|
|
449
|
+
if (sections.every((s) => s.pace === sections[0].pace)) {
|
|
450
|
+
recommendedAdjustments.push('Vary pacing between sections for better rhythm');
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
overall: overall,
|
|
454
|
+
sections,
|
|
455
|
+
actionVsReflection,
|
|
456
|
+
recommendedAdjustments,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
// Helper methods
|
|
460
|
+
countSyllables(words) {
|
|
461
|
+
return words.reduce((count, word) => {
|
|
462
|
+
word = word.toLowerCase().replace(/[^a-z]/g, '');
|
|
463
|
+
let syllables = 0;
|
|
464
|
+
let previousWasVowel = false;
|
|
465
|
+
for (let i = 0; i < word.length; i++) {
|
|
466
|
+
const isVowel = /[aeiou]/.test(word[i]);
|
|
467
|
+
if (isVowel && !previousWasVowel)
|
|
468
|
+
syllables++;
|
|
469
|
+
previousWasVowel = isVowel;
|
|
470
|
+
}
|
|
471
|
+
// Adjustments
|
|
472
|
+
if (word.endsWith('e'))
|
|
473
|
+
syllables--;
|
|
474
|
+
if (word.endsWith('le') && word.length > 2)
|
|
475
|
+
syllables++;
|
|
476
|
+
if (syllables === 0)
|
|
477
|
+
syllables = 1;
|
|
478
|
+
return count + syllables;
|
|
479
|
+
}, 0);
|
|
480
|
+
}
|
|
481
|
+
calculateReadability(words, sentences, syllables) {
|
|
482
|
+
// Handle edge cases
|
|
483
|
+
if (words === 0 || sentences === 0) {
|
|
484
|
+
return {
|
|
485
|
+
fleschReadingEase: 0,
|
|
486
|
+
fleschKincaidGrade: 0,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const avgSyllablesPerWord = syllables / words;
|
|
490
|
+
const avgWordsPerSentence = words / sentences;
|
|
491
|
+
const fleschReadingEase = 206.835 - 1.015 * avgWordsPerSentence - 84.6 * avgSyllablesPerWord;
|
|
492
|
+
const fleschKincaidGrade = 0.39 * avgWordsPerSentence + 11.8 * avgSyllablesPerWord - 15.59;
|
|
493
|
+
return {
|
|
494
|
+
fleschReadingEase: Math.max(0, Math.min(100, fleschReadingEase)),
|
|
495
|
+
fleschKincaidGrade: Math.max(0, fleschKincaidGrade),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
calculateVariance(numbers) {
|
|
499
|
+
const mean = numbers.reduce((a, b) => a + b, 0) / numbers.length;
|
|
500
|
+
const squaredDifferences = numbers.map((n) => Math.pow(n - mean, 2));
|
|
501
|
+
return squaredDifferences.reduce((a, b) => a + b, 0) / numbers.length;
|
|
502
|
+
}
|
|
503
|
+
assessOpeningStrength(paragraph) {
|
|
504
|
+
if (!paragraph)
|
|
505
|
+
return 'weak';
|
|
506
|
+
const hasHook = this.detectHook(paragraph);
|
|
507
|
+
const hasAction = /\b(ran|jumped|crashed|exploded|screamed)\b/i.test(paragraph);
|
|
508
|
+
const hasDialogue = paragraph.includes('"') || paragraph.includes("'");
|
|
509
|
+
const isShort = paragraph.length < 200;
|
|
510
|
+
const strength = [hasHook, hasAction, hasDialogue, isShort].filter(Boolean).length;
|
|
511
|
+
return strength >= 3 ? 'strong' : strength >= 2 ? 'moderate' : 'weak';
|
|
512
|
+
}
|
|
513
|
+
assessEndingStrength(paragraph) {
|
|
514
|
+
if (!paragraph)
|
|
515
|
+
return 'weak';
|
|
516
|
+
const hasResolution = /\b(finally|resolved|ended|complete|finished)\b/i.test(paragraph);
|
|
517
|
+
const hasCliffhanger = paragraph.endsWith('?') || /\b(but|however|suddenly)\b/i.test(paragraph.slice(-50));
|
|
518
|
+
const hasImpact = paragraph.length < 150;
|
|
519
|
+
const strength = [hasResolution || hasCliffhanger, hasImpact].filter(Boolean).length;
|
|
520
|
+
return strength === 2 ? 'strong' : strength === 1 ? 'moderate' : 'weak';
|
|
521
|
+
}
|
|
522
|
+
detectHook(text) {
|
|
523
|
+
const hookPatterns = [
|
|
524
|
+
/^"[^"]+"/, // Opens with dialogue
|
|
525
|
+
/^\w+\s+(ran|jumped|crashed|fell|screamed)/i, // Opens with action
|
|
526
|
+
/^(The|A)\s+\w+\s+was\s+dead/i, // Opens with shocking statement
|
|
527
|
+
/\?$/, // Opens with question
|
|
528
|
+
];
|
|
529
|
+
return hookPatterns.some((pattern) => pattern.test(text.slice(0, 100)));
|
|
530
|
+
}
|
|
531
|
+
countCliffhangers(paragraphs) {
|
|
532
|
+
return paragraphs.filter((p) => {
|
|
533
|
+
if (!p.trim())
|
|
534
|
+
return false;
|
|
535
|
+
// Check if paragraph ends with a question
|
|
536
|
+
if (p.trim().endsWith('?'))
|
|
537
|
+
return true;
|
|
538
|
+
// Check for cliffhanger keywords at the end
|
|
539
|
+
const lastSentence = p.split(/[.!?]/).pop()?.trim() || '';
|
|
540
|
+
return /\b(but|however|suddenly|then)\b/i.test(lastSentence);
|
|
541
|
+
}).length;
|
|
542
|
+
}
|
|
543
|
+
splitIntoSegments(content, count) {
|
|
544
|
+
const segmentLength = Math.ceil(content.length / count);
|
|
545
|
+
const segments = [];
|
|
546
|
+
for (let i = 0; i < count; i++) {
|
|
547
|
+
segments.push(content.slice(i * segmentLength, (i + 1) * segmentLength));
|
|
548
|
+
}
|
|
549
|
+
return segments;
|
|
550
|
+
}
|
|
551
|
+
detectSegmentEmotion(segment) {
|
|
552
|
+
const words = segment.toLowerCase().split(/\s+/);
|
|
553
|
+
let maxEmotion = 'neutral';
|
|
554
|
+
let maxCount = 0;
|
|
555
|
+
const emotionAnalysis = this.analyzeEmotionPatterns(words);
|
|
556
|
+
for (const [emotion, count] of Object.entries(emotionAnalysis)) {
|
|
557
|
+
if (count > maxCount) {
|
|
558
|
+
maxCount = count;
|
|
559
|
+
maxEmotion = emotion;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
emotion: maxEmotion,
|
|
564
|
+
intensity: Math.min((maxCount / words.length) * 100, 100),
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
// Pattern-based helper methods to replace hardcoded word lists
|
|
568
|
+
isPassiveIndicator(word) {
|
|
569
|
+
const auxiliaryVerbs = ['was', 'were', 'been', 'being', 'be', 'is', 'are', 'am'];
|
|
570
|
+
return auxiliaryVerbs.includes(word.toLowerCase());
|
|
571
|
+
}
|
|
572
|
+
isCognitiveVerb(word) {
|
|
573
|
+
// Pattern-based detection of cognitive/mental state verbs
|
|
574
|
+
const cognitivePatterns = [
|
|
575
|
+
'felt',
|
|
576
|
+
'thought',
|
|
577
|
+
'knew',
|
|
578
|
+
'realized',
|
|
579
|
+
'understood',
|
|
580
|
+
'believed',
|
|
581
|
+
'remembered',
|
|
582
|
+
'considered',
|
|
583
|
+
'pondered',
|
|
584
|
+
'reflected',
|
|
585
|
+
];
|
|
586
|
+
return (cognitivePatterns.includes(word.toLowerCase()) ||
|
|
587
|
+
word.endsWith('ized') ||
|
|
588
|
+
word.endsWith('ought') ||
|
|
589
|
+
word.includes('think'));
|
|
590
|
+
}
|
|
591
|
+
isConflictWord(word) {
|
|
592
|
+
// Pattern-based conflict/tension detection
|
|
593
|
+
if (word.includes('fight') || word.includes('battle') || word.includes('conflict'))
|
|
594
|
+
return true;
|
|
595
|
+
if (word.includes('struggle') || word.includes('tension') || word.includes('pressure'))
|
|
596
|
+
return true;
|
|
597
|
+
if (word.includes('clash') || word.includes('dispute') || word.includes('argument'))
|
|
598
|
+
return true;
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
analyzeEmotionPatterns(words) {
|
|
602
|
+
const emotionCounts = {
|
|
603
|
+
joy: 0,
|
|
604
|
+
sadness: 0,
|
|
605
|
+
anger: 0,
|
|
606
|
+
fear: 0,
|
|
607
|
+
surprise: 0,
|
|
608
|
+
disgust: 0,
|
|
609
|
+
};
|
|
610
|
+
for (const word of words) {
|
|
611
|
+
const lowerWord = word.toLowerCase();
|
|
612
|
+
// Pattern-based emotion detection using morphological analysis
|
|
613
|
+
if (this.isJoyWord(lowerWord))
|
|
614
|
+
emotionCounts.joy++;
|
|
615
|
+
else if (this.isSadnessWord(lowerWord))
|
|
616
|
+
emotionCounts.sadness++;
|
|
617
|
+
else if (this.isAngerWord(lowerWord))
|
|
618
|
+
emotionCounts.anger++;
|
|
619
|
+
else if (this.isFearWord(lowerWord))
|
|
620
|
+
emotionCounts.fear++;
|
|
621
|
+
else if (this.isSurpriseWord(lowerWord))
|
|
622
|
+
emotionCounts.surprise++;
|
|
623
|
+
else if (this.isDisgustWord(lowerWord))
|
|
624
|
+
emotionCounts.disgust++;
|
|
625
|
+
}
|
|
626
|
+
return emotionCounts;
|
|
627
|
+
}
|
|
628
|
+
isJoyWord(word) {
|
|
629
|
+
return (word.includes('happ') ||
|
|
630
|
+
word.includes('joy') ||
|
|
631
|
+
word.includes('cheer') ||
|
|
632
|
+
word.includes('delight') ||
|
|
633
|
+
word.includes('pleas') ||
|
|
634
|
+
word.includes('excit'));
|
|
635
|
+
}
|
|
636
|
+
isSadnessWord(word) {
|
|
637
|
+
return (word.includes('sad') ||
|
|
638
|
+
word.includes('depress') ||
|
|
639
|
+
word.includes('grief') ||
|
|
640
|
+
word.includes('sorrow') ||
|
|
641
|
+
word.includes('melanchol') ||
|
|
642
|
+
word.includes('miser'));
|
|
643
|
+
}
|
|
644
|
+
isAngerWord(word) {
|
|
645
|
+
return (word.includes('ang') ||
|
|
646
|
+
word.includes('fur') ||
|
|
647
|
+
word.includes('rage') ||
|
|
648
|
+
word.includes('mad') ||
|
|
649
|
+
word.includes('irrit') ||
|
|
650
|
+
word.includes('annoy'));
|
|
651
|
+
}
|
|
652
|
+
isFearWord(word) {
|
|
653
|
+
return (word.includes('afraid') ||
|
|
654
|
+
word.includes('scar') ||
|
|
655
|
+
word.includes('terror') ||
|
|
656
|
+
word.includes('anxi') ||
|
|
657
|
+
word.includes('worr') ||
|
|
658
|
+
word.includes('nerv'));
|
|
659
|
+
}
|
|
660
|
+
isSurpriseWord(word) {
|
|
661
|
+
return (word.includes('surpris') ||
|
|
662
|
+
word.includes('shock') ||
|
|
663
|
+
word.includes('amaz') ||
|
|
664
|
+
word.includes('astonish') ||
|
|
665
|
+
word.includes('stun'));
|
|
666
|
+
}
|
|
667
|
+
isDisgustWord(word) {
|
|
668
|
+
return (word.includes('disgust') ||
|
|
669
|
+
word.includes('revol') ||
|
|
670
|
+
word.includes('repuls') ||
|
|
671
|
+
word.includes('sicken'));
|
|
672
|
+
}
|
|
673
|
+
isActionWord(word) {
|
|
674
|
+
// Pattern-based action verb detection
|
|
675
|
+
const actionPatterns = /^(ran|jumped|grabbed|pushed|pulled|struck|moved|rushed|charged|attacked|defended|fought)/i;
|
|
676
|
+
return (actionPatterns.test(word) ||
|
|
677
|
+
(word.endsWith('ed') && word.length > 4 && this.isPhysicalActionStem(word.slice(0, -2))));
|
|
678
|
+
}
|
|
679
|
+
isReflectionWord(word) {
|
|
680
|
+
return this.isCognitiveVerb(word);
|
|
681
|
+
}
|
|
682
|
+
isPhysicalActionStem(stem) {
|
|
683
|
+
// CVC pattern common in action verbs
|
|
684
|
+
const actionPattern = /^[bcdfghjklmnpqrstvwxyz][aeiou][bcdfghjklmnpqrstvwxyz]$/;
|
|
685
|
+
return actionPattern.test(stem) || stem.length <= 4;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Get advanced readability analysis using multiple algorithms
|
|
689
|
+
*/
|
|
690
|
+
async getAdvancedReadabilityAnalysis(content) {
|
|
691
|
+
return advancedReadabilityService.calculateMetrics(content);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Compare readability between two texts
|
|
695
|
+
*/
|
|
696
|
+
async compareReadability(text1, text2) {
|
|
697
|
+
return advancedReadabilityService.compareReadability(text1, text2);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Analyze readability trends across document sections
|
|
701
|
+
*/
|
|
702
|
+
async analyzeReadabilityTrends(content, segments = 10) {
|
|
703
|
+
return advancedReadabilityService.analyzeReadabilityTrends(content, segments);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Get AI-powered writing suggestions using OpenAI
|
|
707
|
+
*/
|
|
708
|
+
async getAISuggestions(content, context) {
|
|
709
|
+
if (!openaiService.isConfigured()) {
|
|
710
|
+
return [];
|
|
711
|
+
}
|
|
712
|
+
try {
|
|
713
|
+
return await openaiService.getWritingSuggestions(content, context);
|
|
714
|
+
}
|
|
715
|
+
catch (error) {
|
|
716
|
+
logger.error('AI suggestions error', { error });
|
|
717
|
+
return [];
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Analyze writing style using AI
|
|
722
|
+
*/
|
|
723
|
+
async analyzeStyleWithAI(content) {
|
|
724
|
+
if (!openaiService.isConfigured()) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
return await openaiService.analyzeStyle(content);
|
|
729
|
+
}
|
|
730
|
+
catch (error) {
|
|
731
|
+
logger.error('AI style analysis error', { error });
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Analyze characters using AI
|
|
737
|
+
*/
|
|
738
|
+
async analyzeCharactersWithAI(content, characterNames) {
|
|
739
|
+
if (!openaiService.isConfigured()) {
|
|
740
|
+
return [];
|
|
741
|
+
}
|
|
742
|
+
try {
|
|
743
|
+
return await openaiService.analyzeCharacters(content, characterNames);
|
|
744
|
+
}
|
|
745
|
+
catch (error) {
|
|
746
|
+
logger.error('AI character analysis error', { error });
|
|
747
|
+
return [];
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Analyze plot structure using AI
|
|
752
|
+
*/
|
|
753
|
+
async analyzePlotWithAI(content) {
|
|
754
|
+
if (!openaiService.isConfigured()) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
return await openaiService.analyzePlot(content);
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
logger.error('AI plot analysis error', { error });
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Parse HTML content and extract text
|
|
767
|
+
*/
|
|
768
|
+
parseWebContent(html, baseUrl, options) {
|
|
769
|
+
return webContentParser.parseHtmlContent(html, baseUrl, options);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Convert HTML to Markdown
|
|
773
|
+
*/
|
|
774
|
+
convertHtmlToMarkdown(html, options) {
|
|
775
|
+
return webContentParser.htmlToMarkdown(html, options);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Extract research data from web content
|
|
779
|
+
*/
|
|
780
|
+
extractResearchData(parsedContent, keywords) {
|
|
781
|
+
return webContentParser.extractResearchData(parsedContent, keywords);
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Configure OpenAI service
|
|
785
|
+
*/
|
|
786
|
+
configureOpenAI(config) {
|
|
787
|
+
openaiService.configure(config);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Check if OpenAI is configured
|
|
791
|
+
*/
|
|
792
|
+
isOpenAIConfigured() {
|
|
793
|
+
return openaiService.isConfigured();
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Generate writing prompts using AI
|
|
797
|
+
*/
|
|
798
|
+
async generateWritingPrompts(options = {}) {
|
|
799
|
+
if (!openaiService.isConfigured()) {
|
|
800
|
+
return {
|
|
801
|
+
prompts: [],
|
|
802
|
+
overallTheme: 'Creative Writing',
|
|
803
|
+
writingGoals: [],
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
try {
|
|
807
|
+
return await openaiService.generateWritingPrompts(options);
|
|
808
|
+
}
|
|
809
|
+
catch (error) {
|
|
810
|
+
logger.error('AI prompt generation error', { error });
|
|
811
|
+
return {
|
|
812
|
+
prompts: [],
|
|
813
|
+
overallTheme: 'Creative Writing',
|
|
814
|
+
writingGoals: [],
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Get the OpenAI service instance
|
|
820
|
+
*/
|
|
821
|
+
getOpenAIService() {
|
|
822
|
+
return openaiService;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
__decorate([
|
|
826
|
+
cached((content, documentId) => `analysis:${documentId}:${content.length}`, caches.analysis, 300_000 // Cache for 5 minutes
|
|
827
|
+
),
|
|
828
|
+
__metadata("design:type", Function),
|
|
829
|
+
__metadata("design:paramtypes", [String, String]),
|
|
830
|
+
__metadata("design:returntype", Promise)
|
|
831
|
+
], ContentAnalyzer.prototype, "analyzeContent", null);
|
|
832
|
+
__decorate([
|
|
833
|
+
cached((content) => `ai-style:${content.substring(0, 100)}:${content.length}`, caches.analysis, 600_000 // Cache for 10 minutes
|
|
834
|
+
),
|
|
835
|
+
__metadata("design:type", Function),
|
|
836
|
+
__metadata("design:paramtypes", [String]),
|
|
837
|
+
__metadata("design:returntype", Promise)
|
|
838
|
+
], ContentAnalyzer.prototype, "analyzeStyleWithAI", null);
|
|
839
|
+
__decorate([
|
|
840
|
+
cached((content) => `ai-plot:${content.substring(0, 100)}:${content.length}`, caches.analysis, 600_000 // Cache for 10 minutes
|
|
841
|
+
),
|
|
842
|
+
__metadata("design:type", Function),
|
|
843
|
+
__metadata("design:paramtypes", [String]),
|
|
844
|
+
__metadata("design:returntype", Promise)
|
|
845
|
+
], ContentAnalyzer.prototype, "analyzePlotWithAI", null);
|
|
846
|
+
//# sourceMappingURL=base-analyzer.js.map
|