@nahisaho/katashiro 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. package/AGENTS.md +285 -205
  2. package/CLAUDE.md +214 -147
  3. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -1,265 +1,345 @@
1
1
  # KATASHIRO - AI Coding Agent Guide
2
2
 
3
- > **AI Coding Agent向け**: このファイルはAIエージェント(GitHub Copilot、Claude等)がKATASHIROライブラリを利用するためのガイドです。
3
+ > **AI Coding Agent向け**: このファイルを読み込んだAIエージェントは、ユーザーの課題を解決するためにKATASHIROライブラリの機能を自動的に活用できます。
4
4
 
5
- ## 🎯 KATASHIROでできること
5
+ ## 🎯 このガイドの目的
6
6
 
7
- KATASHIROは情報収集・分析・生成のためのTypeScriptライブラリです。
8
-
9
- | 機能 | 説明 |
10
- |------|------|
11
- | **Web収集** | Webスクレイピング、検索、RSSフィード取得 |
12
- | **テキスト分析** | キーワード抽出、複雑度分析、構造解析 |
13
- | **エンティティ抽出** | 人名・組織名・地名などの固有表現抽出 |
14
- | **レポート生成** | Markdown/HTMLレポート、要約、引用生成 |
15
- | **知識グラフ** | エンティティ・関係の保存・検索・可視化 |
16
- | **フィードバック学習** | パターン検出、適応的推薦 |
7
+ ユーザーが自然言語で入力した課題に対して、KATASHIROの機能を適切に組み合わせて解決策を提供します。
17
8
 
18
9
  ---
19
10
 
20
- ## 📦 インストール
11
+ ## 📋 課題タイプ別の解決アプローチ
21
12
 
22
- \`\`\`bash
23
- npm install @nahisaho/katashiro
24
- \`\`\`
13
+ ### 課題タイプの判定
14
+
15
+ ユーザーの入力から以下のタイプを判定してください:
16
+
17
+ | 課題タイプ | キーワード例 | 使用する機能 |
18
+ |-----------|-------------|-------------|
19
+ | **調査・リサーチ** | 調べて、検索、情報収集、〜について | Collector → Analyzer → Generator |
20
+ | **分析・解析** | 分析して、解析、キーワード、傾向 | Analyzer |
21
+ | **要約・まとめ** | 要約、まとめて、短くして | Generator (SummaryGenerator) |
22
+ | **レポート作成** | レポート、報告書、文書化 | Generator (ReportGenerator) |
23
+ | **データ抽出** | 抽出、取り出して、リストアップ | Analyzer (EntityExtractor) |
24
+ | **知識管理** | 保存、記録、覚えておいて | Knowledge |
25
+ | **比較・評価** | 比較、評価、どちらが | Collector → Analyzer → Generator |
25
26
 
26
27
  ---
27
28
 
28
- ## 🔧 基本的な使い方
29
+ ## 🔄 課題解決ワークフロー
30
+
31
+ ### ステップ1: 課題の分析
32
+
33
+ ```typescript
34
+ // ユーザー入力から課題タイプを判定
35
+ function analyzeProblem(userInput: string): ProblemType {
36
+ const keywords = {
37
+ research: ['調べ', '検索', '情報', 'について', '知りたい'],
38
+ analyze: ['分析', '解析', 'キーワード', '傾向', '特徴'],
39
+ summarize: ['要約', 'まとめ', '短く', '簡潔'],
40
+ report: ['レポート', '報告', '文書', 'ドキュメント'],
41
+ extract: ['抽出', '取り出', 'リスト', '一覧'],
42
+ knowledge: ['保存', '記録', '覚え', '登録'],
43
+ compare: ['比較', '評価', 'どちら', '違い'],
44
+ };
45
+ // キーワードマッチングで判定
46
+ }
47
+ ```
48
+
49
+ ### ステップ2: 必要な機能の選択
29
50
 
30
- ### インポート
51
+ 課題タイプに応じて以下のクラスを使用:
31
52
 
32
- \`\`\`typescript
53
+ ```typescript
33
54
  import {
34
- // Collector - 情報収集
35
- WebScraper,
36
- WebSearchClient,
37
- FeedReader,
38
- ApiClient,
55
+ // 情報収集(URLや検索クエリがある場合)
56
+ WebScraper, // URL指定のページ取得
57
+ WebSearchClient, // キーワード検索
58
+ FeedReader, // RSSフィード
59
+ ApiClient, // API呼び出し
39
60
 
40
- // Analyzer - テキスト分析
41
- TextAnalyzer,
42
- EntityExtractor,
43
- TopicModeler,
61
+ // テキスト分析(テキストデータがある場合)
62
+ TextAnalyzer, // キーワード・複雑度分析
63
+ EntityExtractor, // 人名・組織名抽出
64
+ TopicModeler, // トピック分類
65
+ StructureAnalyzer, // 文書構造解析
66
+ QualityScorer, // 品質スコアリング
44
67
 
45
- // Generator - コンテンツ生成
46
- ReportGenerator,
47
- SummaryGenerator,
48
- CitationGenerator,
68
+ // コンテンツ生成(出力が必要な場合)
69
+ ReportGenerator, // レポート生成
70
+ SummaryGenerator, // 要約生成
71
+ CitationGenerator, // 引用生成
72
+ TemplateEngine, // テンプレート処理
49
73
 
50
- // Knowledge - 知識グラフ
51
- KnowledgeGraph,
52
- GraphQuery,
53
- GraphPersistence,
74
+ // 知識管理(情報を蓄積・検索する場合)
75
+ KnowledgeGraph, // グラフ管理
76
+ GraphQuery, // 検索
77
+ GraphPersistence, // 永続化
54
78
 
55
- // Core - ユーティリティ
79
+ // ユーティリティ
56
80
  ok, err, isOk, isErr,
57
81
  } from '@nahisaho/katashiro';
58
- \`\`\`
82
+ ```
59
83
 
60
84
  ---
61
85
 
62
- ## 📝 ユースケース別コード例
63
-
64
- ### 1. Webページの取得と分析
86
+ ## 📝 課題タイプ別の実装パターン
65
87
 
66
- \`\`\`typescript
67
- import { WebScraper, TextAnalyzer, EntityExtractor, isOk } from '@nahisaho/katashiro';
88
+ ### パターンA: 調査・リサーチ課題
68
89
 
69
- // Webページを取得
70
- const scraper = new WebScraper();
71
- const pageResult = await scraper.scrape('https://example.com/article');
90
+ **ユーザー例**: 「〇〇について調べてまとめて」
72
91
 
73
- if (isOk(pageResult)) {
74
- const { content, title } = pageResult.value;
92
+ ```typescript
93
+ async function solveResearchProblem(topic: string) {
94
+ // 1. 情報収集
95
+ const searchClient = new WebSearchClient();
96
+ const results = await searchClient.search(topic, { maxResults: 10 });
97
+
98
+ // 2. ページ取得
99
+ const scraper = new WebScraper();
100
+ const contents: string[] = [];
101
+ for (const result of results.slice(0, 5)) {
102
+ const page = await scraper.scrape(result.url);
103
+ if (isOk(page)) contents.push(page.value.content);
104
+ }
75
105
 
76
- // テキスト分析
106
+ // 3. 分析
77
107
  const analyzer = new TextAnalyzer();
78
- const analysis = await analyzer.analyze(content);
79
- console.log('Keywords:', analysis.keywords);
80
- console.log('Complexity:', analysis.complexity);
108
+ const analyses = await Promise.all(contents.map(c => analyzer.analyze(c)));
81
109
 
82
- // エンティティ抽出
110
+ // 4. エンティティ抽出
83
111
  const extractor = new EntityExtractor();
84
- const entities = await extractor.extract(content);
85
- console.log('People:', entities.filter(e => e.type === 'PERSON'));
86
- console.log('Organizations:', entities.filter(e => e.type === 'ORGANIZATION'));
112
+ const allEntities = [];
113
+ for (const content of contents) {
114
+ const entities = await extractor.extract(content);
115
+ allEntities.push(...entities);
116
+ }
117
+
118
+ // 5. 要約生成
119
+ const summarizer = new SummaryGenerator();
120
+ const summary = await summarizer.generate(contents.join('\n\n'), { maxLength: 500 });
121
+
122
+ // 6. レポート生成
123
+ const reportGen = new ReportGenerator();
124
+ const report = await reportGen.generate({
125
+ title: `${topic} 調査レポート`,
126
+ sections: [
127
+ { heading: '概要', content: summary },
128
+ { heading: 'キーワード', content: analyses.flatMap(a => a.keywords).join(', ') },
129
+ { heading: '関連エンティティ', content: [...new Set(allEntities.map(e => e.text))].join(', ') },
130
+ { heading: '参考URL', content: results.map(r => `- ${r.url}`).join('\n') },
131
+ ],
132
+ format: 'markdown',
133
+ });
134
+
135
+ return report;
87
136
  }
88
- \`\`\`
89
-
90
- ### 2. Web検索と情報収集
137
+ ```
91
138
 
92
- \`\`\`typescript
93
- import { WebSearchClient, WebScraper, isOk } from '@nahisaho/katashiro';
139
+ ### パターンB: 分析課題
94
140
 
95
- // 検索実行
96
- const searchClient = new WebSearchClient({ apiKey: process.env.SEARCH_API_KEY });
97
- const results = await searchClient.search('TypeScript best practices', { maxResults: 5 });
141
+ **ユーザー例**: 「このテキストを分析して特徴を教えて」
98
142
 
99
- // 上位結果のページを取得
100
- const scraper = new WebScraper();
101
- for (const result of results) {
102
- const page = await scraper.scrape(result.url);
103
- if (isOk(page)) {
104
- console.log(\`Title: \${page.value.title}\`);
105
- console.log(\`Content: \${page.value.content.slice(0, 200)}...\`);
106
- }
143
+ ```typescript
144
+ async function solveAnalysisProblem(text: string) {
145
+ // 1. テキスト分析
146
+ const analyzer = new TextAnalyzer();
147
+ const analysis = await analyzer.analyze(text);
148
+
149
+ // 2. 構造分析
150
+ const structAnalyzer = new StructureAnalyzer();
151
+ const structure = await structAnalyzer.analyze(text);
152
+
153
+ // 3. エンティティ抽出
154
+ const extractor = new EntityExtractor();
155
+ const entities = await extractor.extract(text);
156
+
157
+ // 4. 品質スコアリング
158
+ const scorer = new QualityScorer();
159
+ const quality = await scorer.score(text);
160
+
161
+ return {
162
+ keywords: analysis.keywords,
163
+ complexity: analysis.complexity,
164
+ sentiment: analysis.sentiment,
165
+ structure: structure,
166
+ entities: entities,
167
+ qualityScore: quality,
168
+ };
107
169
  }
108
- \`\`\`
170
+ ```
109
171
 
110
- ### 3. レポート生成
172
+ ### パターンC: 要約課題
111
173
 
112
- \`\`\`typescript
113
- import { ReportGenerator, SummaryGenerator } from '@nahisaho/katashiro';
174
+ **ユーザー例**: 「この長文を300文字でまとめて」
114
175
 
115
- // 要約生成
116
- const summarizer = new SummaryGenerator();
117
- const summary = await summarizer.generate(longText, { maxLength: 300 });
176
+ ```typescript
177
+ async function solveSummaryProblem(text: string, maxLength: number = 300) {
178
+ const summarizer = new SummaryGenerator();
179
+ const summary = await summarizer.generate(text, {
180
+ maxLength,
181
+ style: 'paragraph' // または 'bullets', 'headline'
182
+ });
183
+ return summary;
184
+ }
185
+ ```
186
+
187
+ ### パターンD: レポート作成課題
188
+
189
+ **ユーザー例**: 「分析結果をレポートにまとめて」
190
+
191
+ ```typescript
192
+ async function solveReportProblem(data: any, title: string) {
193
+ const reportGen = new ReportGenerator();
194
+ const report = await reportGen.generate({
195
+ title,
196
+ sections: [
197
+ { heading: '概要', content: data.summary },
198
+ { heading: '詳細分析', content: data.details },
199
+ { heading: '結論', content: data.conclusion },
200
+ ],
201
+ format: 'markdown',
202
+ metadata: { author: 'KATASHIRO', date: new Date().toISOString() },
203
+ });
204
+ return report;
205
+ }
206
+ ```
118
207
 
119
- // レポート生成
120
- const reportGen = new ReportGenerator();
121
- const report = await reportGen.generate({
122
- title: '調査レポート',
123
- sections: [
124
- { heading: '概要', content: summary },
125
- { heading: '詳細分析', content: analysisText },
126
- { heading: '結論', content: conclusionText },
127
- ],
128
- format: 'markdown',
129
- });
208
+ ### パターンE: データ抽出課題
130
209
 
131
- console.log(report);
132
- \`\`\`
210
+ **ユーザー例**: 「この文章から人名と組織名を抽出して」
133
211
 
134
- ### 4. 知識グラフの操作
212
+ ```typescript
213
+ async function solveExtractionProblem(text: string, types: string[] = ['PERSON', 'ORGANIZATION']) {
214
+ const extractor = new EntityExtractor();
215
+ const entities = await extractor.extract(text);
216
+
217
+ const filtered = entities.filter(e => types.includes(e.type));
218
+ const grouped = types.reduce((acc, type) => {
219
+ acc[type] = filtered.filter(e => e.type === type).map(e => e.text);
220
+ return acc;
221
+ }, {} as Record<string, string[]>);
222
+
223
+ return grouped;
224
+ }
225
+ ```
135
226
 
136
- \`\`\`typescript
137
- import { KnowledgeGraph, GraphQuery, GraphPersistence } from '@nahisaho/katashiro';
227
+ ### パターンF: 知識管理課題
138
228
 
139
- // 知識グラフを作成
140
- const kg = new KnowledgeGraph();
229
+ **ユーザー例**: 「この情報を保存しておいて」「〇〇に関連する情報を探して」
141
230
 
142
- // ノードを追加
143
- kg.addNode({ id: 'company-1', type: 'Organization', properties: { name: 'TechCorp' } });
144
- kg.addNode({ id: 'person-1', type: 'Person', properties: { name: '山田太郎' } });
231
+ ```typescript
232
+ async function solveKnowledgeProblem(action: 'save' | 'search', data: any) {
233
+ const kg = new KnowledgeGraph();
234
+ const persistence = new GraphPersistence();
235
+
236
+ // 既存のグラフを読み込み
237
+ try {
238
+ const loaded = await persistence.load('./knowledge-graph.json');
239
+ Object.assign(kg, loaded);
240
+ } catch { /* 新規作成 */ }
241
+
242
+ if (action === 'save') {
243
+ // エンティティを抽出してノード追加
244
+ const extractor = new EntityExtractor();
245
+ const entities = await extractor.extract(data.text);
246
+
247
+ for (const entity of entities) {
248
+ kg.addNode({
249
+ id: `entity-${Date.now()}-${Math.random().toString(36).slice(2)}`,
250
+ type: entity.type,
251
+ properties: { name: entity.text, source: data.source },
252
+ });
253
+ }
254
+
255
+ await persistence.save(kg, './knowledge-graph.json');
256
+ return { saved: entities.length };
257
+ } else {
258
+ // 検索
259
+ const query = new GraphQuery(kg);
260
+ const results = query.search(data.query);
261
+ return results;
262
+ }
263
+ }
264
+ ```
145
265
 
146
- // エッジ(関係)を追加
147
- kg.addEdge({ source: 'person-1', target: 'company-1', type: 'WORKS_FOR' });
266
+ ### パターンG: 比較・評価課題
148
267
 
149
- // クエリ実行
150
- const query = new GraphQuery(kg);
151
- const employees = query.findByRelation('company-1', 'WORKS_FOR', 'incoming');
268
+ **ユーザー例**: 「AとBを比較して」
152
269
 
153
- // 永続化
154
- const persistence = new GraphPersistence();
155
- await persistence.save(kg, './knowledge-graph.json');
270
+ ```typescript
271
+ async function solveComparisonProblem(itemA: string, itemB: string) {
272
+ const searchClient = new WebSearchClient();
273
+ const scraper = new WebScraper();
274
+ const analyzer = new TextAnalyzer();
275
+
276
+ // 両方の情報を収集
277
+ const [resultsA, resultsB] = await Promise.all([
278
+ searchClient.search(itemA, { maxResults: 5 }),
279
+ searchClient.search(itemB, { maxResults: 5 }),
280
+ ]);
281
+
282
+ // 分析
283
+ const analysisA = await analyzeResults(resultsA, scraper, analyzer);
284
+ const analysisB = await analyzeResults(resultsB, scraper, analyzer);
285
+
286
+ // 比較レポート生成
287
+ const reportGen = new ReportGenerator();
288
+ return reportGen.generate({
289
+ title: `${itemA} vs ${itemB} 比較レポート`,
290
+ sections: [
291
+ { heading: itemA, content: formatAnalysis(analysisA) },
292
+ { heading: itemB, content: formatAnalysis(analysisB) },
293
+ { heading: '比較まとめ', content: generateComparison(analysisA, analysisB) },
294
+ ],
295
+ format: 'markdown',
296
+ });
297
+ }
298
+ ```
156
299
 
157
- // 読み込み
158
- const loadedKg = await persistence.load('./knowledge-graph.json');
159
- \`\`\`
300
+ ---
160
301
 
161
- ### 5. RSSフィードの購読
302
+ ## 🚀 統合ソルバー
162
303
 
163
- \`\`\`typescript
164
- import { FeedReader, isOk } from '@nahisaho/katashiro';
304
+ ユーザーの課題を自動判定して解決:
165
305
 
166
- const reader = new FeedReader();
167
- const feed = await reader.read('https://blog.example.com/rss.xml');
306
+ ```typescript
307
+ import * as katashiro from '@nahisaho/katashiro';
168
308
 
169
- if (isOk(feed)) {
170
- for (const item of feed.value.items) {
171
- console.log(\`\${item.title} - \${item.pubDate}\`);
172
- console.log(\` \${item.description}\`);
309
+ async function solveProblem(userInput: string, context?: any) {
310
+ // 課題タイプを判定
311
+ const problemType = detectProblemType(userInput);
312
+
313
+ switch (problemType) {
314
+ case 'research':
315
+ return solveResearchProblem(extractTopic(userInput));
316
+ case 'analyze':
317
+ return solveAnalysisProblem(context?.text || userInput);
318
+ case 'summarize':
319
+ return solveSummaryProblem(context?.text || userInput, extractMaxLength(userInput));
320
+ case 'report':
321
+ return solveReportProblem(context?.data, extractTitle(userInput));
322
+ case 'extract':
323
+ return solveExtractionProblem(context?.text || userInput, extractEntityTypes(userInput));
324
+ case 'knowledge':
325
+ return solveKnowledgeProblem(detectKnowledgeAction(userInput), context);
326
+ case 'compare':
327
+ const [itemA, itemB] = extractComparisonItems(userInput);
328
+ return solveComparisonProblem(itemA, itemB);
329
+ default:
330
+ // 汎用的なリサーチとして処理
331
+ return solveResearchProblem(userInput);
173
332
  }
174
333
  }
175
- \`\`\`
176
-
177
- ### 6. 引用生成
178
-
179
- \`\`\`typescript
180
- import { CitationGenerator } from '@nahisaho/katashiro';
181
-
182
- const citationGen = new CitationGenerator();
183
- const citation = citationGen.generate({
184
- title: 'TypeScript Best Practices',
185
- author: 'John Doe',
186
- url: 'https://example.com/article',
187
- date: '2026-01-10',
188
- }, { style: 'APA' });
189
-
190
- console.log(citation);
191
- // Doe, J. (2026). TypeScript Best Practices. Retrieved from https://example.com/article
192
- \`\`\`
193
-
194
- ---
195
-
196
- ## 📚 モジュール一覧
197
-
198
- ### Collector(情報収集)
199
-
200
- | クラス | 機能 |
201
- |--------|------|
202
- | \`WebScraper\` | Webページのスクレイピング |
203
- | \`WebSearchClient\` | Web検索API連携 |
204
- | \`FeedReader\` | RSS/Atomフィード読み込み |
205
- | \`ApiClient\` | REST API呼び出し |
206
- | \`MediaExtractor\` | 画像・動画URL抽出 |
207
- | \`YouTubeTranscript\` | YouTube字幕取得 |
208
-
209
- ### Analyzer(テキスト分析)
210
-
211
- | クラス | 機能 |
212
- |--------|------|
213
- | \`TextAnalyzer\` | キーワード・複雑度・感情分析 |
214
- | \`EntityExtractor\` | 固有表現抽出(人名・組織名・地名) |
215
- | \`TopicModeler\` | トピック分類 |
216
- | \`StructureAnalyzer\` | 文書構造解析 |
217
- | \`RelationAnalyzer\` | エンティティ間関係分析 |
218
- | \`QualityScorer\` | テキスト品質スコアリング |
219
-
220
- ### Generator(コンテンツ生成)
221
-
222
- | クラス | 機能 |
223
- |--------|------|
224
- | \`ReportGenerator\` | Markdown/HTMLレポート生成 |
225
- | \`SummaryGenerator\` | テキスト要約 |
226
- | \`CitationGenerator\` | 引用生成(APA/MLA/Chicago) |
227
- | \`PresentationGenerator\` | プレゼン資料生成 |
228
- | \`TemplateEngine\` | テンプレートベース生成 |
229
- | \`ExportService\` | 各種フォーマットへのエクスポート |
230
-
231
- ### Knowledge(知識グラフ)
232
-
233
- | クラス | 機能 |
234
- |--------|------|
235
- | \`KnowledgeGraph\` | グラフ構造の管理 |
236
- | \`GraphQuery\` | グラフ検索・クエリ |
237
- | \`GraphPersistence\` | JSON/SQLite永続化 |
238
- | \`GraphSync\` | グラフ同期 |
239
- | \`GraphVisualization\` | D3.js/Mermaid可視化 |
240
-
241
- ### Core(ユーティリティ)
242
-
243
- | 関数/クラス | 機能 |
244
- |-------------|------|
245
- | \`ok()\`, \`err()\` | Result型の生成 |
246
- | \`isOk()\`, \`isErr()\` | Result型の判定 |
247
- | \`Logger\` | ログ出力 |
248
- | \`generateId()\` | ユニークID生成 |
334
+ ```
249
335
 
250
336
  ---
251
337
 
252
- ## 🏗️ プロジェクト構造
338
+ ## 📦 インストール
253
339
 
254
- \`\`\`
255
- @nahisaho/katashiro
256
- ├── Collector # 情報収集モジュール
257
- ├── Analyzer # テキスト分析モジュール
258
- ├── Generator # コンテンツ生成モジュール
259
- ├── Knowledge # 知識グラフモジュール
260
- ├── Feedback # フィードバック学習モジュール
261
- └── Core # ユーティリティ
262
- \`\`\`
340
+ ```bash
341
+ npm install @nahisaho/katashiro
342
+ ```
263
343
 
264
344
  ---
265
345
 
@@ -273,4 +353,4 @@ console.log(citation);
273
353
  **Project**: KATASHIRO
274
354
  **npm**: @nahisaho/katashiro
275
355
  **Last Updated**: 2026-01-10
276
- **Version**: 0.1.3
356
+ **Version**: 0.1.5
package/CLAUDE.md CHANGED
@@ -1,200 +1,267 @@
1
- # KATASHIRO - Claude向けガイド
1
+ # KATASHIRO - Claude向け課題解決ガイド
2
2
 
3
- > このファイルはClaude(Claude Code、Claude Desktop等)向けのKATASHIROライブラリ利用ガイドです。
3
+ > このファイルを読み込んだClaudeは、ユーザーの課題を解決するためにKATASHIROライブラリの機能を自動的に活用できます。
4
4
 
5
- ## 🎯 概要
5
+ ## 🎯 基本動作
6
6
 
7
- KATASHIROは情報収集・分析・生成のためのTypeScriptライブラリです。
8
- ユーザーからの調査・分析リクエストに対して、適切なモジュールを使用してタスクを実行できます。
7
+ **ユーザーが課題を入力したら、以下の手順で解決してください:**
8
+
9
+ 1. 課題タイプを判定
10
+ 2. 適切なKATASHIRO機能を選択
11
+ 3. コードを生成して実行
12
+ 4. 結果をユーザーに提示
9
13
 
10
14
  ---
11
15
 
12
- ## 📦 インストール
16
+ ## 📋 課題タイプ判定表
17
+
18
+ | ユーザーの言葉 | 課題タイプ | 使用機能 |
19
+ |---------------|-----------|----------|
20
+ | 「〜について調べて」「検索して」「情報を集めて」 | 調査 | WebSearchClient → WebScraper → TextAnalyzer → ReportGenerator |
21
+ | 「このテキストを分析して」「特徴を教えて」 | 分析 | TextAnalyzer + EntityExtractor + StructureAnalyzer |
22
+ | 「要約して」「まとめて」「短くして」 | 要約 | SummaryGenerator |
23
+ | 「レポートを作成して」「報告書にして」 | レポート | ReportGenerator |
24
+ | 「人名を抽出して」「組織名を取り出して」 | 抽出 | EntityExtractor |
25
+ | 「保存して」「覚えておいて」「記録して」 | 保存 | KnowledgeGraph + GraphPersistence |
26
+ | 「〜を探して」「検索して」(保存済みデータ) | 検索 | GraphQuery |
27
+ | 「AとBを比較して」「違いを教えて」 | 比較 | 複合(調査×2 → 分析 → レポート) |
28
+ | 「このURLの内容を取得して」 | 取得 | WebScraper |
29
+ | 「RSSフィードを読んで」 | フィード | FeedReader |
13
30
 
14
- ```bash
15
- npm install @nahisaho/katashiro
31
+ ---
32
+
33
+ ## 🔧 機能別クイックリファレンス
34
+
35
+ ### 情報収集
36
+
37
+ ```typescript
38
+ import { WebScraper, WebSearchClient, FeedReader } from '@nahisaho/katashiro';
39
+
40
+ // URL取得
41
+ const scraper = new WebScraper();
42
+ const page = await scraper.scrape('https://example.com');
43
+
44
+ // Web検索
45
+ const search = new WebSearchClient();
46
+ const results = await search.search('キーワード', { maxResults: 10 });
47
+
48
+ // RSSフィード
49
+ const reader = new FeedReader();
50
+ const feed = await reader.read('https://example.com/rss.xml');
16
51
  ```
17
52
 
18
- ---
53
+ ### テキスト分析
54
+
55
+ ```typescript
56
+ import { TextAnalyzer, EntityExtractor, TopicModeler, StructureAnalyzer, QualityScorer } from '@nahisaho/katashiro';
57
+
58
+ // 基本分析
59
+ const analyzer = new TextAnalyzer();
60
+ const { keywords, complexity, sentiment } = await analyzer.analyze(text);
61
+
62
+ // エンティティ抽出
63
+ const extractor = new EntityExtractor();
64
+ const entities = await extractor.extract(text);
65
+ // entities: [{ type: 'PERSON', text: '山田太郎' }, { type: 'ORGANIZATION', text: '〇〇株式会社' }]
66
+
67
+ // トピック分析
68
+ const modeler = new TopicModeler();
69
+ const topics = await modeler.model(documents, { numTopics: 5 });
70
+
71
+ // 構造分析
72
+ const structAnalyzer = new StructureAnalyzer();
73
+ const structure = await structAnalyzer.analyze(text);
19
74
 
20
- ## 🔧 モジュール対応表
21
-
22
- | ユーザーのリクエスト | 使用するモジュール | クラス |
23
- |---------------------|-------------------|--------|
24
- | 「URLの内容を取得して」 | Collector | `WebScraper` |
25
- | 「〜について検索して」 | Collector | `WebSearchClient` |
26
- | 「RSSフィードを読んで」 | Collector | `FeedReader` |
27
- | 「テキストを分析して」 | Analyzer | `TextAnalyzer` |
28
- | 「人名・組織名を抽出して」 | Analyzer | `EntityExtractor` |
29
- | 「トピックを分類して」 | Analyzer | `TopicModeler` |
30
- | 「レポートを作成して」 | Generator | `ReportGenerator` |
31
- | 「要約して」 | Generator | `SummaryGenerator` |
32
- | 「引用を生成して」 | Generator | `CitationGenerator` |
33
- | 「知識グラフに追加して」 | Knowledge | `KnowledgeGraph` |
34
- | 「関連情報を検索して」 | Knowledge | `GraphQuery` |
75
+ // 品質スコア
76
+ const scorer = new QualityScorer();
77
+ const score = await scorer.score(text);
78
+ ```
79
+
80
+ ### コンテンツ生成
81
+
82
+ ```typescript
83
+ import { ReportGenerator, SummaryGenerator, CitationGenerator } from '@nahisaho/katashiro';
84
+
85
+ // 要約
86
+ const summarizer = new SummaryGenerator();
87
+ const summary = await summarizer.generate(longText, { maxLength: 300, style: 'paragraph' });
88
+
89
+ // レポート
90
+ const reportGen = new ReportGenerator();
91
+ const report = await reportGen.generate({
92
+ title: 'タイトル',
93
+ sections: [
94
+ { heading: 'セクション1', content: '内容1' },
95
+ { heading: 'セクション2', content: '内容2' },
96
+ ],
97
+ format: 'markdown',
98
+ });
99
+
100
+ // 引用
101
+ const citationGen = new CitationGenerator();
102
+ const citation = citationGen.generate(source, { style: 'APA' });
103
+ ```
104
+
105
+ ### 知識グラフ
106
+
107
+ ```typescript
108
+ import { KnowledgeGraph, GraphQuery, GraphPersistence } from '@nahisaho/katashiro';
109
+
110
+ const kg = new KnowledgeGraph();
111
+ const persistence = new GraphPersistence();
112
+ const query = new GraphQuery(kg);
113
+
114
+ // 保存
115
+ kg.addNode({ id: 'node-1', type: 'Person', properties: { name: '山田太郎' } });
116
+ await persistence.save(kg, './knowledge.json');
117
+
118
+ // 読み込み
119
+ const loaded = await persistence.load('./knowledge.json');
120
+
121
+ // 検索
122
+ const results = query.findByType('Person');
123
+ ```
35
124
 
36
125
  ---
37
126
 
38
- ## 📝 実装パターン
127
+ ## 📝 課題解決テンプレート
39
128
 
40
- ### パターン1: Webページ取得→分析→レポート
129
+ ### テンプレート1: 調査タスク
41
130
 
42
131
  ```typescript
43
- import {
44
- WebScraper,
45
- TextAnalyzer,
46
- EntityExtractor,
47
- ReportGenerator,
48
- isOk
49
- } from '@nahisaho/katashiro';
50
-
51
- async function analyzeWebPage(url: string) {
52
- // 1. Webページ取得
53
- const scraper = new WebScraper();
54
- const pageResult = await scraper.scrape(url);
132
+ // ユーザー: 「〇〇について調べてまとめて」
133
+ import { WebSearchClient, WebScraper, TextAnalyzer, EntityExtractor, SummaryGenerator, ReportGenerator, isOk } from '@nahisaho/katashiro';
134
+
135
+ async function research(topic: string) {
136
+ // 1. 検索
137
+ const search = new WebSearchClient();
138
+ const results = await search.search(topic, { maxResults: 10 });
55
139
 
56
- if (!isOk(pageResult)) {
57
- return { error: 'Failed to scrape page' };
140
+ // 2. ページ取得
141
+ const scraper = new WebScraper();
142
+ const contents: string[] = [];
143
+ for (const r of results.slice(0, 5)) {
144
+ const page = await scraper.scrape(r.url);
145
+ if (isOk(page)) contents.push(page.value.content);
58
146
  }
59
147
 
60
- const { content, title } = pageResult.value;
61
-
62
- // 2. テキスト分析
148
+ // 3. 分析
63
149
  const analyzer = new TextAnalyzer();
64
- const analysis = await analyzer.analyze(content);
150
+ const keywords = new Set<string>();
151
+ for (const c of contents) {
152
+ const a = await analyzer.analyze(c);
153
+ a.keywords.forEach(k => keywords.add(k));
154
+ }
65
155
 
66
- // 3. エンティティ抽出
156
+ // 4. エンティティ抽出
67
157
  const extractor = new EntityExtractor();
68
- const entities = await extractor.extract(content);
158
+ const entities = new Set<string>();
159
+ for (const c of contents) {
160
+ const e = await extractor.extract(c);
161
+ e.forEach(ent => entities.add(ent.text));
162
+ }
163
+
164
+ // 5. 要約
165
+ const summarizer = new SummaryGenerator();
166
+ const summary = await summarizer.generate(contents.join('\n\n'), { maxLength: 500 });
69
167
 
70
- // 4. レポート生成
168
+ // 6. レポート生成
71
169
  const reportGen = new ReportGenerator();
72
- const report = await reportGen.generate({
73
- title: `Analysis: ${title}`,
170
+ return reportGen.generate({
171
+ title: `${topic} 調査レポート`,
74
172
  sections: [
75
- { heading: 'Summary', content: analysis.summary },
76
- { heading: 'Keywords', content: analysis.keywords.join(', ') },
77
- { heading: 'Entities', content: entities.map(e => e.text).join(', ') },
173
+ { heading: '概要', content: summary },
174
+ { heading: 'キーワード', content: [...keywords].join(', ') },
175
+ { heading: '関連エンティティ', content: [...entities].join(', ') },
176
+ { heading: '参考URL', content: results.map(r => `- ${r.url}`).join('\n') },
78
177
  ],
79
178
  format: 'markdown',
80
179
  });
81
-
82
- return { report, analysis, entities };
83
180
  }
84
181
  ```
85
182
 
86
- ### パターン2: 検索→収集→要約
183
+ ### テンプレート2: 分析タスク
87
184
 
88
185
  ```typescript
89
- import {
90
- WebSearchClient,
91
- WebScraper,
92
- SummaryGenerator,
93
- isOk
94
- } from '@nahisaho/katashiro';
95
-
96
- async function researchTopic(topic: string) {
97
- // 1. 検索
98
- const searchClient = new WebSearchClient({ apiKey: process.env.SEARCH_API_KEY });
99
- const results = await searchClient.search(topic, { maxResults: 5 });
100
-
101
- // 2. 上位結果を収集
102
- const scraper = new WebScraper();
103
- const contents: string[] = [];
186
+ // ユーザー: 「このテキストを分析して」
187
+ import { TextAnalyzer, EntityExtractor, StructureAnalyzer, QualityScorer } from '@nahisaho/katashiro';
188
+
189
+ async function analyze(text: string) {
190
+ const [analysis, entities, structure, quality] = await Promise.all([
191
+ new TextAnalyzer().analyze(text),
192
+ new EntityExtractor().extract(text),
193
+ new StructureAnalyzer().analyze(text),
194
+ new QualityScorer().score(text),
195
+ ]);
104
196
 
105
- for (const result of results) {
106
- const page = await scraper.scrape(result.url);
107
- if (isOk(page)) {
108
- contents.push(page.value.content);
109
- }
110
- }
111
-
112
- // 3. 全体を要約
113
- const summarizer = new SummaryGenerator();
114
- const combinedText = contents.join('\n\n---\n\n');
115
- const summary = await summarizer.generate(combinedText, { maxLength: 500 });
116
-
117
- return { summary, sources: results };
197
+ return {
198
+ keywords: analysis.keywords,
199
+ complexity: analysis.complexity,
200
+ sentiment: analysis.sentiment,
201
+ entities: entities.map(e => ({ type: e.type, text: e.text })),
202
+ structure,
203
+ qualityScore: quality,
204
+ };
118
205
  }
119
206
  ```
120
207
 
121
- ### パターン3: 知識グラフ構築
208
+ ### テンプレート3: 比較タスク
122
209
 
123
210
  ```typescript
124
- import {
125
- KnowledgeGraph,
126
- GraphQuery,
127
- GraphPersistence,
128
- EntityExtractor
129
- } from '@nahisaho/katashiro';
130
-
131
- async function buildKnowledgeGraph(texts: string[]) {
132
- const kg = new KnowledgeGraph();
133
- const extractor = new EntityExtractor();
211
+ // ユーザー: 「AとBを比較して」
212
+ import { WebSearchClient, WebScraper, TextAnalyzer, ReportGenerator, isOk } from '@nahisaho/katashiro';
213
+
214
+ async function compare(itemA: string, itemB: string) {
215
+ const search = new WebSearchClient();
216
+ const scraper = new WebScraper();
217
+ const analyzer = new TextAnalyzer();
134
218
 
135
- for (const text of texts) {
136
- // エンティティ抽出
137
- const entities = await extractor.extract(text);
138
-
139
- // ノード追加
140
- for (const entity of entities) {
141
- kg.addNode({
142
- id: `entity-${entity.text.toLowerCase().replace(/\s+/g, '-')}`,
143
- type: entity.type,
144
- properties: { name: entity.text },
145
- });
219
+ async function gatherInfo(item: string) {
220
+ const results = await search.search(item, { maxResults: 5 });
221
+ const contents: string[] = [];
222
+ for (const r of results) {
223
+ const page = await scraper.scrape(r.url);
224
+ if (isOk(page)) contents.push(page.value.content);
146
225
  }
226
+ const analysis = await analyzer.analyze(contents.join('\n'));
227
+ return { item, analysis, sources: results };
147
228
  }
148
229
 
149
- // 永続化
150
- const persistence = new GraphPersistence();
151
- await persistence.save(kg, './knowledge-graph.json');
152
-
153
- // クエリ
154
- const query = new GraphQuery(kg);
155
- const allNodes = query.getAllNodes();
230
+ const [infoA, infoB] = await Promise.all([gatherInfo(itemA), gatherInfo(itemB)]);
156
231
 
157
- return { nodeCount: allNodes.length, nodes: allNodes };
232
+ const reportGen = new ReportGenerator();
233
+ return reportGen.generate({
234
+ title: `${itemA} vs ${itemB} 比較`,
235
+ sections: [
236
+ { heading: itemA, content: `キーワード: ${infoA.analysis.keywords.join(', ')}` },
237
+ { heading: itemB, content: `キーワード: ${infoB.analysis.keywords.join(', ')}` },
238
+ { heading: '比較まとめ', content: '(AIが分析結果を基に比較コメントを生成)' },
239
+ ],
240
+ format: 'markdown',
241
+ });
158
242
  }
159
243
  ```
160
244
 
161
245
  ---
162
246
 
163
- ## 📚 クラスリファレンス
164
-
165
- ### Collector
166
-
167
- | クラス | メソッド | 説明 |
168
- |--------|---------|------|
169
- | `WebScraper` | `scrape(url)` | URLからコンテンツを取得 |
170
- | `WebSearchClient` | `search(query, options)` | Web検索を実行 |
171
- | `FeedReader` | `read(url)` | RSS/Atomフィードを読み込み |
172
- | `ApiClient` | `get(url)`, `post(url, data)` | REST API呼び出し |
247
+ ## クイックスタート
173
248
 
174
- ### Analyzer
175
-
176
- | クラス | メソッド | 説明 |
177
- |--------|---------|------|
178
- | `TextAnalyzer` | `analyze(text)` | キーワード、複雑度、感情を分析 |
179
- | `EntityExtractor` | `extract(text)` | 固有表現を抽出 |
180
- | `TopicModeler` | `model(documents)` | トピックを分類 |
181
- | `StructureAnalyzer` | `analyze(text)` | 文書構造を解析 |
182
-
183
- ### Generator
184
-
185
- | クラス | メソッド | 説明 |
186
- |--------|---------|------|
187
- | `ReportGenerator` | `generate(options)` | レポートを生成 |
188
- | `SummaryGenerator` | `generate(text, options)` | 要約を生成 |
189
- | `CitationGenerator` | `generate(source, options)` | 引用を生成 |
190
-
191
- ### Knowledge
249
+ ```bash
250
+ npm install @nahisaho/katashiro
251
+ ```
192
252
 
193
- | クラス | メソッド | 説明 |
194
- |--------|---------|------|
195
- | `KnowledgeGraph` | `addNode()`, `addEdge()` | グラフを構築 |
196
- | `GraphQuery` | `find()`, `findByRelation()` | グラフを検索 |
197
- | `GraphPersistence` | `save()`, `load()` | 永続化 |
253
+ ```typescript
254
+ import * as katashiro from '@nahisaho/katashiro';
255
+
256
+ // すべての機能にアクセス可能
257
+ const {
258
+ WebScraper, WebSearchClient, FeedReader,
259
+ TextAnalyzer, EntityExtractor, TopicModeler,
260
+ ReportGenerator, SummaryGenerator, CitationGenerator,
261
+ KnowledgeGraph, GraphQuery, GraphPersistence,
262
+ isOk, isErr
263
+ } = katashiro;
264
+ ```
198
265
 
199
266
  ---
200
267
 
@@ -208,4 +275,4 @@ async function buildKnowledgeGraph(texts: string[]) {
208
275
  **Project**: KATASHIRO
209
276
  **npm**: @nahisaho/katashiro
210
277
  **Last Updated**: 2026-01-10
211
- **Version**: 0.1.3
278
+ **Version**: 0.1.5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nahisaho/katashiro",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "KATASHIRO - VS Code Agent Mode向け情報収集・分析・生成システム(オールインワンパッケージ)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",