Comprehensive natural language processing library with tokenization, stemming, classification, sentiment analysis, phonetics, distance algorithms, and WordNet integration.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Additional utility classes and functions for specialized data structures, storage, and graph algorithms.
A trie data structure for efficient string storage and retrieval.
/**
* Trie data structure for string storage
*/
class Trie {
constructor();
/** Add a string to the trie */
addString(string: string): void;
/** Check if string exists in trie */
contains(string: string): boolean;
/** Find all strings with given prefix */
findPrefix(prefix: string): string[];
/** Get all strings in trie */
allPrefixes(): string[];
}Implementation of shortest path tree algorithms for graph traversal.
/**
* Shortest path tree implementation
*/
class ShortestPathTree {
constructor(graph: EdgeWeightedDigraph, source: number);
/** Get distance to vertex */
distTo(vertex: number): number;
/** Check if path exists to vertex */
hasPathTo(vertex: number): boolean;
/** Get path to vertex */
pathTo(vertex: number): DirectedEdge[];
}Implementation of longest path algorithms for DAGs.
/**
* Longest path tree implementation
*/
class LongestPathTree {
constructor(graph: EdgeWeightedDigraph, source: number);
/** Get distance to vertex */
distTo(vertex: number): number;
/** Check if path exists to vertex */
hasPathTo(vertex: number): boolean;
/** Get path to vertex */
pathTo(vertex: number): DirectedEdge[];
}Supporting classes for graph algorithms.
/**
* Directed edge with weight
*/
class DirectedEdge {
constructor(from: number, to: number, weight: number);
/** Get source vertex */
from(): number;
/** Get destination vertex */
to(): number;
/** Get edge weight */
weight(): number;
}
/**
* Edge-weighted directed graph
*/
class EdgeWeightedDigraph {
constructor(vertices: number);
/** Add directed edge */
addEdge(edge: DirectedEdge): void;
/** Get edges from vertex */
adj(vertex: number): DirectedEdge[];
/** Get all edges */
edges(): DirectedEdge[];
/** Get vertex count */
V(): number;
/** Get edge count */
E(): number;
}
/**
* Topological sort for DAGs
*/
class Topological {
constructor(graph: EdgeWeightedDigraph);
/** Get topological order */
order(): number[];
/** Check if graph is DAG */
isDAG(): boolean;
/** Check if vertex comes before another in topological order */
rank(vertex: number): number;
}Generic storage interface for classifiers and other persistent data.
/**
* Storage backend interface
*/
class StorageBackend {
constructor();
/** Store data with key */
put(key: string, data: any): void;
/** Retrieve data by key */
get(key: string): any;
/** Check if key exists */
exists(key: string): boolean;
/** Delete data by key */
delete(key: string): void;
/** Get all keys */
keys(): string[];
}Common text processing resources and utilities.
/**
* English stopwords list
*/
const stopwords: string[];
/**
* Known abbreviations for sentence tokenization
*/
const abbreviations: string[];Basic spell checking functionality.
/**
* Spell checker with correction suggestions
*/
class Spellcheck {
constructor();
/** Check if word is spelled correctly */
isCorrect(word: string): boolean;
/** Get spelling suggestions for word */
getCorrections(word: string): string[];
}const { Trie } = require('natural');
const trie = new Trie();
// Add words
trie.addString('hello');
trie.addString('help');
trie.addString('helicopter');
// Check existence
console.log(trie.contains('hello')); // true
console.log(trie.contains('world')); // false
// Find with prefix
const words = trie.findPrefix('hel');
console.log(words); // ['hello', 'help', 'helicopter']const { EdgeWeightedDigraph, DirectedEdge, ShortestPathTree } = require('natural');
// Create graph
const graph = new EdgeWeightedDigraph(5);
// Add edges
graph.addEdge(new DirectedEdge(0, 1, 2.0));
graph.addEdge(new DirectedEdge(0, 2, 1.0));
graph.addEdge(new DirectedEdge(1, 3, 3.0));
graph.addEdge(new DirectedEdge(2, 3, 1.0));
// Find shortest paths
const spt = new ShortestPathTree(graph, 0);
console.log(spt.distTo(3)); // Shortest distance to vertex 3
console.log(spt.pathTo(3)); // Path to vertex 3const { StorageBackend } = require('natural');
const storage = new StorageBackend();
// Store data
storage.put('classifier_data', {
vocabulary: ['word1', 'word2'],
labels: ['positive', 'negative']
});
// Retrieve data
const data = storage.get('classifier_data');
console.log(data.vocabulary);
// Check existence
if (storage.exists('classifier_data')) {
console.log('Data exists');
}const { Spellcheck } = require('natural');
const spellcheck = new Spellcheck();
// Check spelling
console.log(spellcheck.isCorrect('hello')); // true
console.log(spellcheck.isCorrect('helo')); // false
// Get corrections
const corrections = spellcheck.getCorrections('helo');
console.log(corrections); // ['hello', 'help', ...]