chore: enforce consistent coding style and semicolon removal
- Update ESLint configuration to enforce no semicolons (`semi: ['error', 'never']`) - Fix all instances of semicolons in `*.ts` files to align with style rules - Adjust related ESLint rules for `no-extra-semi` - Simplify unnecessary semicolon patterns in global variable assignments
This commit is contained in:
parent
cfd74adcb3
commit
797839c135
5 changed files with 207 additions and 207 deletions
|
|
@ -38,12 +38,12 @@ export default [
|
||||||
argsIgnorePattern: '^_'
|
argsIgnorePattern: '^_'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// Semi rule removed - not available in v9
|
// Semicolon rules - enforce no semicolons
|
||||||
|
'semi': ['error', 'never'],
|
||||||
|
|
||||||
// General rules
|
// General rules
|
||||||
'no-unused-vars': 'off', // Using TypeScript rule instead
|
'no-unused-vars': 'off', // Using TypeScript rule instead
|
||||||
'no-extra-semi': 'off',
|
'no-extra-semi': 'error',
|
||||||
'semi': 'off', // Using TypeScript rule instead
|
|
||||||
'no-undef': 'off', // TypeScript handles this
|
'no-undef': 'off', // TypeScript handles this
|
||||||
'no-redeclare': 'off', // TypeScript handles this
|
'no-redeclare': 'off', // TypeScript handles this
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
* CLI interface for semantic similarity, clustering, and neural operations
|
* CLI interface for semantic similarity, clustering, and neural operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer'
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk'
|
||||||
import ora from 'ora';
|
import ora from 'ora'
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs'
|
||||||
import path from 'node:path';
|
import path from 'node:path'
|
||||||
import { Brainy } from '../../brainyData.js';
|
import { Brainy } from '../../brainyData.js'
|
||||||
import { NeuralAPI } from '../../neural/neuralAPI.js';
|
import { NeuralAPI } from '../../neural/neuralAPI.js'
|
||||||
|
|
||||||
interface CommandArguments {
|
interface CommandArguments {
|
||||||
action?: string;
|
action?: string;
|
||||||
|
|
@ -90,52 +90,52 @@ export const neuralCommand = {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
alias: 'e'
|
alias: 'e'
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
handler: async (argv: CommandArguments) => {
|
handler: async (argv: CommandArguments) => {
|
||||||
console.log(chalk.cyan('\n🧠 NEURAL SIMILARITY API'));
|
console.log(chalk.cyan('\n🧠 NEURAL SIMILARITY API'))
|
||||||
console.log(chalk.gray('━'.repeat(50)));
|
console.log(chalk.gray('━'.repeat(50)))
|
||||||
|
|
||||||
// Initialize Brainy and Neural API
|
// Initialize Brainy and Neural API
|
||||||
const brain = new Brainy();
|
const brain = new Brainy()
|
||||||
const neural = new NeuralAPI(brain);
|
const neural = new NeuralAPI(brain)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const action = argv.action || await promptForAction();
|
const action = argv.action || await promptForAction()
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'similar':
|
case 'similar':
|
||||||
await handleSimilarCommand(neural, argv);
|
await handleSimilarCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'clusters':
|
case 'clusters':
|
||||||
await handleClustersCommand(neural, argv);
|
await handleClustersCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'hierarchy':
|
case 'hierarchy':
|
||||||
await handleHierarchyCommand(neural, argv);
|
await handleHierarchyCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'neighbors':
|
case 'neighbors':
|
||||||
await handleNeighborsCommand(neural, argv);
|
await handleNeighborsCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'path':
|
case 'path':
|
||||||
await handlePathCommand(neural, argv);
|
await handlePathCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'outliers':
|
case 'outliers':
|
||||||
await handleOutliersCommand(neural, argv);
|
await handleOutliersCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
case 'visualize':
|
case 'visualize':
|
||||||
await handleVisualizeCommand(neural, argv);
|
await handleVisualizeCommand(neural, argv)
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
console.log(chalk.red(`❌ Unknown action: ${action}`));
|
console.log(chalk.red(`❌ Unknown action: ${action}`))
|
||||||
showHelp();
|
showHelp()
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red('💥 Error:'), error instanceof Error ? error.message : error);
|
console.error(chalk.red('💥 Error:'), error instanceof Error ? error.message : error)
|
||||||
process.exit(1);
|
process.exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
async function promptForAction(): Promise<string> {
|
async function promptForAction(): Promise<string> {
|
||||||
const answer = await inquirer.prompt([{
|
const answer = await inquirer.prompt([{
|
||||||
|
|
@ -151,25 +151,25 @@ async function promptForAction(): Promise<string> {
|
||||||
{ name: '🚨 Detect outliers', value: 'outliers' },
|
{ name: '🚨 Detect outliers', value: 'outliers' },
|
||||||
{ name: '📊 Generate visualization data', value: 'visualize' }
|
{ name: '📊 Generate visualization data', value: 'visualize' }
|
||||||
]
|
]
|
||||||
}]);
|
}])
|
||||||
|
|
||||||
return answer.action;
|
return answer.action
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSimilarCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleSimilarCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🧠 Calculating semantic similarity...').start();
|
const spinner = ora('🧠 Calculating semantic similarity...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let itemA: string, itemB: string;
|
let itemA: string, itemB: string
|
||||||
|
|
||||||
if (argv.id && argv.query) {
|
if (argv.id && argv.query) {
|
||||||
itemA = argv.id;
|
itemA = argv.id
|
||||||
itemB = argv.query;
|
itemB = argv.query
|
||||||
} else if (argv._ && argv._.length >= 3) {
|
} else if (argv._ && argv._.length >= 3) {
|
||||||
itemA = argv._[1];
|
itemA = argv._[1]
|
||||||
itemB = argv._[2];
|
itemB = argv._[2]
|
||||||
} else {
|
} else {
|
||||||
spinner.stop();
|
spinner.stop()
|
||||||
const answers = await inquirer.prompt([
|
const answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
|
|
@ -183,179 +183,179 @@ async function handleSimilarCommand(neural: NeuralAPI, argv: CommandArguments):
|
||||||
message: 'Second item (ID or text):',
|
message: 'Second item (ID or text):',
|
||||||
validate: (input: string) => input.length > 0
|
validate: (input: string) => input.length > 0
|
||||||
}
|
}
|
||||||
]);
|
])
|
||||||
itemA = answers.itemA;
|
itemA = answers.itemA
|
||||||
itemB = answers.itemB;
|
itemB = answers.itemB
|
||||||
spinner.start();
|
spinner.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await neural.similar(itemA, itemB, {
|
const result = await neural.similar(itemA, itemB, {
|
||||||
explain: argv.explain,
|
explain: argv.explain,
|
||||||
includeBreakdown: argv.explain
|
includeBreakdown: argv.explain
|
||||||
});
|
})
|
||||||
|
|
||||||
spinner.succeed('✅ Similarity calculated');
|
spinner.succeed('✅ Similarity calculated')
|
||||||
|
|
||||||
if (typeof result === 'number') {
|
if (typeof result === 'number') {
|
||||||
console.log(`\n🔗 Similarity: ${chalk.cyan((result * 100).toFixed(1))}%`);
|
console.log(`\n🔗 Similarity: ${chalk.cyan((result * 100).toFixed(1))}%`)
|
||||||
} else {
|
} else {
|
||||||
console.log(`\n🔗 Similarity: ${chalk.cyan((result.score * 100).toFixed(1))}%`);
|
console.log(`\n🔗 Similarity: ${chalk.cyan((result.score * 100).toFixed(1))}%`)
|
||||||
if (result.explanation) {
|
if (result.explanation) {
|
||||||
console.log(`💭 Explanation: ${result.explanation}`);
|
console.log(`💭 Explanation: ${result.explanation}`)
|
||||||
}
|
}
|
||||||
if (result.breakdown) {
|
if (result.breakdown) {
|
||||||
console.log('\n📊 Breakdown:');
|
console.log('\n📊 Breakdown:')
|
||||||
console.log(` Semantic: ${chalk.yellow((result.breakdown.semantic! * 100).toFixed(1))}%`);
|
console.log(` Semantic: ${chalk.yellow((result.breakdown.semantic! * 100).toFixed(1))}%`)
|
||||||
if (result.breakdown.taxonomic !== undefined) {
|
if (result.breakdown.taxonomic !== undefined) {
|
||||||
console.log(` Taxonomic: ${chalk.yellow((result.breakdown.taxonomic * 100).toFixed(1))}%`);
|
console.log(` Taxonomic: ${chalk.yellow((result.breakdown.taxonomic * 100).toFixed(1))}%`)
|
||||||
}
|
}
|
||||||
if (result.breakdown.contextual !== undefined) {
|
if (result.breakdown.contextual !== undefined) {
|
||||||
console.log(` Contextual: ${chalk.yellow((result.breakdown.contextual * 100).toFixed(1))}%`);
|
console.log(` Contextual: ${chalk.yellow((result.breakdown.contextual * 100).toFixed(1))}%`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result.hierarchy) {
|
if (result.hierarchy) {
|
||||||
console.log(`\n🌳 Hierarchy: ${result.hierarchy.sharedParent ?
|
console.log(`\n🌳 Hierarchy: ${result.hierarchy.sharedParent ?
|
||||||
`Shared parent at distance ${result.hierarchy.distance}` :
|
`Shared parent at distance ${result.hierarchy.distance}` :
|
||||||
'No shared parent found'}`);
|
'No shared parent found'}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, result, argv.format!);
|
await saveToFile(argv.output, result, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to calculate similarity');
|
spinner.fail('💥 Failed to calculate similarity')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleClustersCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleClustersCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🎯 Finding semantic clusters...').start();
|
const spinner = ora('🎯 Finding semantic clusters...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
algorithm: argv.algorithm as any,
|
algorithm: argv.algorithm as any,
|
||||||
threshold: argv.threshold,
|
threshold: argv.threshold,
|
||||||
maxClusters: argv.limit
|
maxClusters: argv.limit
|
||||||
};
|
}
|
||||||
|
|
||||||
const clusters = await neural.clusters(argv.query || options);
|
const clusters = await neural.clusters(argv.query || options)
|
||||||
|
|
||||||
spinner.succeed(`✅ Found ${clusters.length} clusters`);
|
spinner.succeed(`✅ Found ${clusters.length} clusters`)
|
||||||
|
|
||||||
if (argv.format === 'json') {
|
if (argv.format === 'json') {
|
||||||
console.log(JSON.stringify(clusters, null, 2));
|
console.log(JSON.stringify(clusters, null, 2))
|
||||||
} else {
|
} else {
|
||||||
console.log(`\n🎯 ${chalk.cyan(clusters.length)} Semantic Clusters:\n`);
|
console.log(`\n🎯 ${chalk.cyan(clusters.length)} Semantic Clusters:\n`)
|
||||||
|
|
||||||
clusters.forEach((cluster, index) => {
|
clusters.forEach((cluster, index) => {
|
||||||
console.log(`${chalk.yellow(`Cluster ${index + 1}:`)} ${cluster.label || cluster.id}`);
|
console.log(`${chalk.yellow(`Cluster ${index + 1}:`)} ${cluster.label || cluster.id}`)
|
||||||
console.log(` 📊 Confidence: ${chalk.green((cluster.confidence * 100).toFixed(1))}%`);
|
console.log(` 📊 Confidence: ${chalk.green((cluster.confidence * 100).toFixed(1))}%`)
|
||||||
console.log(` 👥 Members: ${cluster.members.length}`);
|
console.log(` 👥 Members: ${cluster.members.length}`)
|
||||||
if (cluster.members.length <= 5) {
|
if (cluster.members.length <= 5) {
|
||||||
cluster.members.forEach(member => {
|
cluster.members.forEach(member => {
|
||||||
console.log(` • ${member}`);
|
console.log(` • ${member}`)
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
cluster.members.slice(0, 3).forEach(member => {
|
cluster.members.slice(0, 3).forEach(member => {
|
||||||
console.log(` • ${member}`);
|
console.log(` • ${member}`)
|
||||||
});
|
})
|
||||||
console.log(` ... and ${cluster.members.length - 3} more`);
|
console.log(` ... and ${cluster.members.length - 3} more`)
|
||||||
}
|
}
|
||||||
console.log();
|
console.log()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, clusters, argv.format!);
|
await saveToFile(argv.output, clusters, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to find clusters');
|
spinner.fail('💥 Failed to find clusters')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleHierarchyCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleHierarchyCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🌳 Building semantic hierarchy...').start();
|
const spinner = ora('🌳 Building semantic hierarchy...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id = argv.id || argv._[1];
|
const id = argv.id || argv._[1]
|
||||||
if (!id) {
|
if (!id) {
|
||||||
spinner.stop();
|
spinner.stop()
|
||||||
const answer = await inquirer.prompt([{
|
const answer = await inquirer.prompt([{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'id',
|
name: 'id',
|
||||||
message: 'Enter item ID:',
|
message: 'Enter item ID:',
|
||||||
validate: (input: string) => input.length > 0
|
validate: (input: string) => input.length > 0
|
||||||
}]);
|
}])
|
||||||
spinner.start();
|
spinner.start()
|
||||||
const hierarchy = await neural.hierarchy(answer.id);
|
const hierarchy = await neural.hierarchy(answer.id)
|
||||||
displayHierarchy(hierarchy);
|
displayHierarchy(hierarchy)
|
||||||
} else {
|
} else {
|
||||||
const hierarchy = await neural.hierarchy(id);
|
const hierarchy = await neural.hierarchy(id)
|
||||||
spinner.succeed('✅ Hierarchy built');
|
spinner.succeed('✅ Hierarchy built')
|
||||||
displayHierarchy(hierarchy);
|
displayHierarchy(hierarchy)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
const hierarchy = await neural.hierarchy(id || argv._[1]);
|
const hierarchy = await neural.hierarchy(id || argv._[1])
|
||||||
await saveToFile(argv.output, hierarchy, argv.format!);
|
await saveToFile(argv.output, hierarchy, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to build hierarchy');
|
spinner.fail('💥 Failed to build hierarchy')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayHierarchy(hierarchy: any): void {
|
function displayHierarchy(hierarchy: any): void {
|
||||||
console.log(`\n🌳 Semantic Hierarchy for ${chalk.cyan(hierarchy.self.id)}:`);
|
console.log(`\n🌳 Semantic Hierarchy for ${chalk.cyan(hierarchy.self.id)}:`)
|
||||||
|
|
||||||
if (hierarchy.root) {
|
if (hierarchy.root) {
|
||||||
console.log(`🔝 Root: ${hierarchy.root.id} (${(hierarchy.root.similarity * 100).toFixed(1)}%)`);
|
console.log(`🔝 Root: ${hierarchy.root.id} (${(hierarchy.root.similarity * 100).toFixed(1)}%)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hierarchy.grandparent) {
|
if (hierarchy.grandparent) {
|
||||||
console.log(`👴 Grandparent: ${hierarchy.grandparent.id} (${(hierarchy.grandparent.similarity * 100).toFixed(1)}%)`);
|
console.log(`👴 Grandparent: ${hierarchy.grandparent.id} (${(hierarchy.grandparent.similarity * 100).toFixed(1)}%)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hierarchy.parent) {
|
if (hierarchy.parent) {
|
||||||
console.log(`👨 Parent: ${hierarchy.parent.id} (${(hierarchy.parent.similarity * 100).toFixed(1)}%)`);
|
console.log(`👨 Parent: ${hierarchy.parent.id} (${(hierarchy.parent.similarity * 100).toFixed(1)}%)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🎯 ${chalk.bold('Self:')} ${hierarchy.self.id}`);
|
console.log(`🎯 ${chalk.bold('Self:')} ${hierarchy.self.id}`)
|
||||||
|
|
||||||
if (hierarchy.siblings && hierarchy.siblings.length > 0) {
|
if (hierarchy.siblings && hierarchy.siblings.length > 0) {
|
||||||
console.log(`👥 Siblings: ${hierarchy.siblings.length}`);
|
console.log(`👥 Siblings: ${hierarchy.siblings.length}`)
|
||||||
hierarchy.siblings.forEach((sibling: any) => {
|
hierarchy.siblings.forEach((sibling: any) => {
|
||||||
console.log(` • ${sibling.id} (${(sibling.similarity * 100).toFixed(1)}%)`);
|
console.log(` • ${sibling.id} (${(sibling.similarity * 100).toFixed(1)}%)`)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hierarchy.children && hierarchy.children.length > 0) {
|
if (hierarchy.children && hierarchy.children.length > 0) {
|
||||||
console.log(`👶 Children: ${hierarchy.children.length}`);
|
console.log(`👶 Children: ${hierarchy.children.length}`)
|
||||||
hierarchy.children.forEach((child: any) => {
|
hierarchy.children.forEach((child: any) => {
|
||||||
console.log(` • ${child.id} (${(child.similarity * 100).toFixed(1)}%)`);
|
console.log(` • ${child.id} (${(child.similarity * 100).toFixed(1)}%)`)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleNeighborsCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleNeighborsCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🕸️ Finding semantic neighbors...').start();
|
const spinner = ora('🕸️ Finding semantic neighbors...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id = argv.id || argv._[1];
|
const id = argv.id || argv._[1]
|
||||||
if (!id) {
|
if (!id) {
|
||||||
spinner.stop();
|
spinner.stop()
|
||||||
const answer = await inquirer.prompt([{
|
const answer = await inquirer.prompt([{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'id',
|
name: 'id',
|
||||||
message: 'Enter item ID:',
|
message: 'Enter item ID:',
|
||||||
validate: (input: string) => input.length > 0
|
validate: (input: string) => input.length > 0
|
||||||
}]);
|
}])
|
||||||
spinner.start();
|
spinner.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetId = id || (await inquirer.prompt([{
|
const targetId = id || (await inquirer.prompt([{
|
||||||
|
|
@ -363,52 +363,52 @@ async function handleNeighborsCommand(neural: NeuralAPI, argv: CommandArguments)
|
||||||
name: 'id',
|
name: 'id',
|
||||||
message: 'Enter item ID:',
|
message: 'Enter item ID:',
|
||||||
validate: (input: string) => input.length > 0
|
validate: (input: string) => input.length > 0
|
||||||
}])).id;
|
}])).id
|
||||||
|
|
||||||
const graph = await neural.neighbors(targetId, {
|
const graph = await neural.neighbors(targetId, {
|
||||||
limit: argv.limit,
|
limit: argv.limit,
|
||||||
includeEdges: true
|
includeEdges: true
|
||||||
});
|
})
|
||||||
|
|
||||||
spinner.succeed(`✅ Found ${graph.neighbors.length} neighbors`);
|
spinner.succeed(`✅ Found ${graph.neighbors.length} neighbors`)
|
||||||
|
|
||||||
console.log(`\n🕸️ Neighbors of ${chalk.cyan(graph.center)}:`);
|
console.log(`\n🕸️ Neighbors of ${chalk.cyan(graph.center)}:`)
|
||||||
|
|
||||||
graph.neighbors.forEach((neighbor, index) => {
|
graph.neighbors.forEach((neighbor, index) => {
|
||||||
console.log(`${index + 1}. ${neighbor.id} (${(neighbor.similarity * 100).toFixed(1)}%)`);
|
console.log(`${index + 1}. ${neighbor.id} (${(neighbor.similarity * 100).toFixed(1)}%)`)
|
||||||
if (neighbor.type) {
|
if (neighbor.type) {
|
||||||
console.log(` Type: ${neighbor.type}`);
|
console.log(` Type: ${neighbor.type}`)
|
||||||
}
|
}
|
||||||
if (neighbor.connections) {
|
if (neighbor.connections) {
|
||||||
console.log(` Connections: ${neighbor.connections}`);
|
console.log(` Connections: ${neighbor.connections}`)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if (graph.edges && graph.edges.length > 0) {
|
if (graph.edges && graph.edges.length > 0) {
|
||||||
console.log(`\n🔗 ${graph.edges.length} semantic connections found`);
|
console.log(`\n🔗 ${graph.edges.length} semantic connections found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, graph, argv.format!);
|
await saveToFile(argv.output, graph, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to find neighbors');
|
spinner.fail('💥 Failed to find neighbors')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handlePathCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handlePathCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🛣️ Finding semantic path...').start();
|
const spinner = ora('🛣️ Finding semantic path...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fromId: string, toId: string;
|
let fromId: string, toId: string
|
||||||
|
|
||||||
if (argv._ && argv._.length >= 3) {
|
if (argv._ && argv._.length >= 3) {
|
||||||
fromId = argv._[1];
|
fromId = argv._[1]
|
||||||
toId = argv._[2];
|
toId = argv._[2]
|
||||||
} else {
|
} else {
|
||||||
spinner.stop();
|
spinner.stop()
|
||||||
const answers = await inquirer.prompt([
|
const answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
|
|
@ -422,156 +422,156 @@ async function handlePathCommand(neural: NeuralAPI, argv: CommandArguments): Pro
|
||||||
message: 'To item ID:',
|
message: 'To item ID:',
|
||||||
validate: (input: string) => input.length > 0
|
validate: (input: string) => input.length > 0
|
||||||
}
|
}
|
||||||
]);
|
])
|
||||||
fromId = answers.from;
|
fromId = answers.from
|
||||||
toId = answers.to;
|
toId = answers.to
|
||||||
spinner.start();
|
spinner.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = await neural.semanticPath(fromId, toId);
|
const path = await neural.semanticPath(fromId, toId)
|
||||||
|
|
||||||
if (path.length === 0) {
|
if (path.length === 0) {
|
||||||
spinner.warn('🚫 No semantic path found');
|
spinner.warn('🚫 No semantic path found')
|
||||||
console.log(`No path found between ${chalk.cyan(fromId)} and ${chalk.cyan(toId)}`);
|
console.log(`No path found between ${chalk.cyan(fromId)} and ${chalk.cyan(toId)}`)
|
||||||
} else {
|
} else {
|
||||||
spinner.succeed(`✅ Found path with ${path.length} hops`);
|
spinner.succeed(`✅ Found path with ${path.length} hops`)
|
||||||
|
|
||||||
console.log(`\n🛣️ Semantic Path from ${chalk.cyan(fromId)} to ${chalk.cyan(toId)}:`);
|
console.log(`\n🛣️ Semantic Path from ${chalk.cyan(fromId)} to ${chalk.cyan(toId)}:`)
|
||||||
console.log(`${chalk.cyan(fromId)} (start)`);
|
console.log(`${chalk.cyan(fromId)} (start)`)
|
||||||
|
|
||||||
path.forEach((hop, index) => {
|
path.forEach((hop, index) => {
|
||||||
console.log(`${' '.repeat(index + 1)}↓ ${(hop.similarity * 100).toFixed(1)}%`);
|
console.log(`${' '.repeat(index + 1)}↓ ${(hop.similarity * 100).toFixed(1)}%`)
|
||||||
console.log(`${' '.repeat(index + 1)}${hop.id} (hop ${hop.hop})`);
|
console.log(`${' '.repeat(index + 1)}${hop.id} (hop ${hop.hop})`)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, path, argv.format!);
|
await saveToFile(argv.output, path, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to find path');
|
spinner.fail('💥 Failed to find path')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleOutliersCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleOutliersCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('🚨 Detecting semantic outliers...').start();
|
const spinner = ora('🚨 Detecting semantic outliers...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const outliers = await neural.outliers(argv.threshold);
|
const outliers = await neural.outliers(argv.threshold)
|
||||||
|
|
||||||
spinner.succeed(`✅ Found ${outliers.length} outliers`);
|
spinner.succeed(`✅ Found ${outliers.length} outliers`)
|
||||||
|
|
||||||
if (outliers.length === 0) {
|
if (outliers.length === 0) {
|
||||||
console.log('\n🎉 No outliers detected - all items are well connected!');
|
console.log('\n🎉 No outliers detected - all items are well connected!')
|
||||||
} else {
|
} else {
|
||||||
console.log(`\n🚨 ${chalk.red(outliers.length)} Semantic Outliers:`);
|
console.log(`\n🚨 ${chalk.red(outliers.length)} Semantic Outliers:`)
|
||||||
outliers.forEach((outlier, index) => {
|
outliers.forEach((outlier, index) => {
|
||||||
console.log(`${index + 1}. ${outlier}`);
|
console.log(`${index + 1}. ${outlier}`)
|
||||||
});
|
})
|
||||||
|
|
||||||
console.log(`\n💡 These items have similarity < ${argv.threshold} to their nearest neighbors`);
|
console.log(`\n💡 These items have similarity < ${argv.threshold} to their nearest neighbors`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, outliers, argv.format!);
|
await saveToFile(argv.output, outliers, argv.format!)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to detect outliers');
|
spinner.fail('💥 Failed to detect outliers')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleVisualizeCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
async function handleVisualizeCommand(neural: NeuralAPI, argv: CommandArguments): Promise<void> {
|
||||||
const spinner = ora('📊 Generating visualization data...').start();
|
const spinner = ora('📊 Generating visualization data...').start()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const vizData = await neural.visualize({
|
const vizData = await neural.visualize({
|
||||||
dimensions: argv.dimensions as 2 | 3,
|
dimensions: argv.dimensions as 2 | 3,
|
||||||
maxNodes: argv.limit
|
maxNodes: argv.limit
|
||||||
});
|
})
|
||||||
|
|
||||||
spinner.succeed('✅ Visualization data generated');
|
spinner.succeed('✅ Visualization data generated')
|
||||||
|
|
||||||
console.log(`\n📊 Visualization Data (${vizData.format} layout):`);
|
console.log(`\n📊 Visualization Data (${vizData.format} layout):`)
|
||||||
console.log(`📍 Nodes: ${vizData.nodes.length}`);
|
console.log(`📍 Nodes: ${vizData.nodes.length}`)
|
||||||
console.log(`🔗 Edges: ${vizData.edges.length}`);
|
console.log(`🔗 Edges: ${vizData.edges.length}`)
|
||||||
console.log(`🎯 Clusters: ${vizData.clusters?.length || 0}`);
|
console.log(`🎯 Clusters: ${vizData.clusters?.length || 0}`)
|
||||||
console.log(`📐 Dimensions: ${vizData.layout?.dimensions}D`);
|
console.log(`📐 Dimensions: ${vizData.layout?.dimensions}D`)
|
||||||
|
|
||||||
if (argv.format === 'json') {
|
if (argv.format === 'json') {
|
||||||
console.log('\nData:');
|
console.log('\nData:')
|
||||||
console.log(JSON.stringify(vizData, null, 2));
|
console.log(JSON.stringify(vizData, null, 2))
|
||||||
} else {
|
} else {
|
||||||
console.log('\n🎨 Style Settings:');
|
console.log('\n🎨 Style Settings:')
|
||||||
console.log(` Node Colors: ${vizData.style?.nodeColors}`);
|
console.log(` Node Colors: ${vizData.style?.nodeColors}`)
|
||||||
console.log(` Edge Width: ${vizData.style?.edgeWidth}`);
|
console.log(` Edge Width: ${vizData.style?.edgeWidth}`)
|
||||||
console.log(` Labels: ${vizData.style?.labels}`);
|
console.log(` Labels: ${vizData.style?.labels}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.output) {
|
if (argv.output) {
|
||||||
await saveToFile(argv.output, vizData, 'json');
|
await saveToFile(argv.output, vizData, 'json')
|
||||||
console.log(`\n💾 Visualization data saved to: ${chalk.green(argv.output)}`);
|
console.log(`\n💾 Visualization data saved to: ${chalk.green(argv.output)}`)
|
||||||
} else {
|
} else {
|
||||||
console.log(`\n💡 Use --output to save visualization data for external tools`);
|
console.log(`\n💡 Use --output to save visualization data for external tools`)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail('💥 Failed to generate visualization');
|
spinner.fail('💥 Failed to generate visualization')
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveToFile(filepath: string, data: any, format: string): Promise<void> {
|
async function saveToFile(filepath: string, data: any, format: string): Promise<void> {
|
||||||
const dir = path.dirname(filepath);
|
const dir = path.dirname(filepath)
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
let output: string;
|
let output: string
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 'json':
|
case 'json':
|
||||||
output = JSON.stringify(data, null, 2);
|
output = JSON.stringify(data, null, 2)
|
||||||
break;
|
break
|
||||||
case 'table':
|
case 'table':
|
||||||
output = formatAsTable(data);
|
output = formatAsTable(data)
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
output = JSON.stringify(data, null, 2);
|
output = JSON.stringify(data, null, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(filepath, output, 'utf8');
|
fs.writeFileSync(filepath, output, 'utf8')
|
||||||
console.log(`💾 Saved to: ${chalk.green(filepath)}`);
|
console.log(`💾 Saved to: ${chalk.green(filepath)}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatAsTable(data: any): string {
|
function formatAsTable(data: any): string {
|
||||||
// Simple table formatting - could be enhanced with a table library
|
// Simple table formatting - could be enhanced with a table library
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
return data.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n');
|
return data.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n')
|
||||||
}
|
}
|
||||||
return JSON.stringify(data, null, 2);
|
return JSON.stringify(data, null, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHelp(): void {
|
function showHelp(): void {
|
||||||
console.log('\n🧠 Neural Similarity API Commands:');
|
console.log('\n🧠 Neural Similarity API Commands:')
|
||||||
console.log('');
|
console.log('')
|
||||||
console.log(' brainy neural similar <item1> <item2> Calculate similarity');
|
console.log(' brainy neural similar <item1> <item2> Calculate similarity')
|
||||||
console.log(' brainy neural clusters Find semantic clusters');
|
console.log(' brainy neural clusters Find semantic clusters')
|
||||||
console.log(' brainy neural hierarchy <id> Show item hierarchy');
|
console.log(' brainy neural hierarchy <id> Show item hierarchy')
|
||||||
console.log(' brainy neural neighbors <id> Find semantic neighbors');
|
console.log(' brainy neural neighbors <id> Find semantic neighbors')
|
||||||
console.log(' brainy neural path <from> <to> Find semantic path');
|
console.log(' brainy neural path <from> <to> Find semantic path')
|
||||||
console.log(' brainy neural outliers Detect outliers');
|
console.log(' brainy neural outliers Detect outliers')
|
||||||
console.log(' brainy neural visualize Generate visualization data');
|
console.log(' brainy neural visualize Generate visualization data')
|
||||||
console.log('');
|
console.log('')
|
||||||
console.log('Options:');
|
console.log('Options:')
|
||||||
console.log(' --threshold, -t Similarity threshold (0-1)');
|
console.log(' --threshold, -t Similarity threshold (0-1)')
|
||||||
console.log(' --format, -f Output format (json|table|tree|graph)');
|
console.log(' --format, -f Output format (json|table|tree|graph)')
|
||||||
console.log(' --output, -o Save to file');
|
console.log(' --output, -o Save to file')
|
||||||
console.log(' --limit, -l Maximum results');
|
console.log(' --limit, -l Maximum results')
|
||||||
console.log(' --explain, -e Include explanations');
|
console.log(' --explain, -e Include explanations')
|
||||||
console.log('');
|
console.log('')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default neuralCommand;
|
export default neuralCommand
|
||||||
|
|
@ -1279,7 +1279,7 @@ export class NaturalLanguageProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.includeMetadata) {
|
if (options?.includeMetadata) {
|
||||||
;(entity as any).metadata = {
|
(entity as any).metadata = {
|
||||||
pattern: pattern.source,
|
pattern: pattern.source,
|
||||||
contextBefore: text.substring(Math.max(0, match.index - 20), match.index),
|
contextBefore: text.substring(Math.max(0, match.index - 20), match.index),
|
||||||
contextAfter: text.substring(match.index + match[0].length, Math.min(text.length, match.index + match[0].length + 20))
|
contextAfter: text.substring(match.index + match[0].length, Math.min(text.length, match.index + match[0].length + 20))
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ if (globalObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create special global constructors for library compatibility
|
// Create special global constructors for library compatibility
|
||||||
;(globalObj as any).__TextEncoder__ = TextEncoder
|
(globalObj as any).__TextEncoder__ = TextEncoder
|
||||||
;(globalObj as any).__TextDecoder__ = TextDecoder
|
;(globalObj as any).__TextDecoder__ = TextDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ export const environment = {
|
||||||
|
|
||||||
// Make environment information available globally
|
// Make environment information available globally
|
||||||
if (typeof globalThis !== 'undefined') {
|
if (typeof globalThis !== 'undefined') {
|
||||||
;(globalThis as any).__ENV__ = environment
|
(globalThis as any).__ENV__ = environment
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the detected environment
|
// Log the detected environment
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue