analyze_tag_cooccurrence
Identify frequently co-occurring tags in journal entries to uncover patterns and relationships in your data. Accepts a list of tags for analysis within specified or default journals.
Instructions
Analyze which tags frequently appear together
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| journal | No | Journal name (uses current/default if not specified) | |
| tags | Yes | Tags to analyze for co-occurrence |
Implementation Reference
- src/handlers/tagHandlers.ts:41-84 (handler)Core implementation of the analyze_tag_cooccurrence tool. Computes co-occurrence counts for pairs of input tags by searching journal entries containing both tags in each pair.export async function analyzeTagCooccurrence( tags: string[], journal: string | undefined, executor: JrnlExecutor, ): Promise<{ cooccurrences: TagCooccurrence[] }> { if (tags.length < 2) { return { cooccurrences: [] }; } // For each pair of tags, find entries that contain both const cooccurrences: TagCooccurrence[] = []; for (let i = 0; i < tags.length - 1; i++) { for (let j = i + 1; j < tags.length; j++) { const tag1 = tags[i]; const tag2 = tags[j]; // Search for entries with both tags const command = buildSearchCommand({ tags: [tag1, tag2] }, journal); const result = await executor.execute(command); try { const data = JSON.parse(result); const count = data.entries ? data.entries.length : 0; if (count > 0) { cooccurrences.push({ tag1: tag1.startsWith("@") ? tag1 : `@${tag1}`, tag2: tag2.startsWith("@") ? tag2 : `@${tag2}`, count, }); } } catch (error) { // Skip this pair if there's an error // console.error(`Error analyzing cooccurrence for ${tag1} and ${tag2}: ${error}`); } } } // Sort by count descending cooccurrences.sort((a, b) => b.count - a.count); return { cooccurrences }; }
- src/index.ts:81-96 (schema)Input schema definition for the analyze_tag_cooccurrence tool, specifying required 'tags' array and optional 'journal'.inputSchema: { type: "object", properties: { tags: { type: "array", items: { type: "string" }, description: "Tags to analyze for co-occurrence", minItems: 2, }, journal: { type: "string", description: "Journal name (uses current/default if not specified)", }, }, required: ["tags"], },
- src/handlers/tagHandlers.ts:9-13 (schema)TypeScript interface defining the structure of tag co-occurrence results returned by the handler.export interface TagCooccurrence { tag1: string; tag2: string; count: number; }
- src/index.ts:78-97 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ name: "analyze_tag_cooccurrence", description: "Analyze which tags frequently appear together", inputSchema: { type: "object", properties: { tags: { type: "array", items: { type: "string" }, description: "Tags to analyze for co-occurrence", minItems: 2, }, journal: { type: "string", description: "Journal name (uses current/default if not specified)", }, }, required: ["tags"], }, },
- src/index.ts:178-194 (registration)Dispatch logic in CallToolRequest handler that invokes the analyzeTagCooccurrence function with parsed arguments.case "analyze_tag_cooccurrence": return { content: [ { type: "text", text: JSON.stringify( await analyzeTagCooccurrence( Array.isArray(args?.tags) ? args.tags : [], journal, executor, ), null, 2, ), }, ], };