|
9 | 9 |
|
10 | 10 | </div> |
11 | 11 |
|
12 | | -Sophisticated NLP library for comprehensive text processing, tokenization, and analysis with LLM integration. |
| 12 | +Qirrel is a TypeScript NLP library for tokenization, rule-based entity extraction, optional LLM enrichment, and pipeline orchestration. |
13 | 13 |
|
14 | 14 | [GitHub](https://github.com/dev-dami/qirrel) | [NPM](https://www.npmjs.com/package/qirrel) | Author: [Damilare Osibanjo](https://github.com/dev-dami) |
15 | 15 |
|
16 | | -## Quick Start |
| 16 | +## Install |
17 | 17 |
|
18 | 18 | ```bash |
19 | | -npm install qirrel |
| 19 | +bun add qirrel |
20 | 20 | ``` |
21 | 21 |
|
22 | | -### Extract Multiple Entity Types |
| 22 | +## Quick Start |
23 | 23 |
|
24 | 24 | ```ts |
25 | 25 | import { processText } from 'qirrel'; |
26 | | -const result = await processText('Contact John at john@example.com or call +1-555-123-4567'); |
| 26 | + |
| 27 | +const result = await processText('Contact John at john@example.com or call +1 415 555 2671'); |
27 | 28 | console.log(result.data?.entities); |
28 | | -// [ |
29 | | -// { type: 'email', value: 'john@example.com', ... }, |
30 | | -// { type: 'phone', value: '+1-555-123-4567', ... } |
31 | | -// ] |
32 | 29 | ``` |
33 | 30 |
|
34 | | -### Extract URLs and Numbers |
| 31 | +## Batch Processing |
35 | 32 |
|
36 | 33 | ```ts |
37 | | -import { processText } from 'qirrel'; |
38 | | -const result = await processText('Visit https://example.com for more info. Price: $29.99'); |
39 | | -console.log(result.data?.entities); |
40 | | -// [ |
41 | | -// { type: 'url', value: 'https://example.com', ... }, |
42 | | -// { type: 'number', value: '29.99', ... } |
43 | | -// ] |
44 | | -``` |
| 34 | +import { processTexts, Pipeline } from 'qirrel'; |
45 | 35 |
|
46 | | -### Advanced Pipeline Usage |
| 36 | +const results = await processTexts(['first input', 'second input'], undefined, { concurrency: 2 }); |
47 | 37 |
|
48 | | -```ts |
49 | | -import { Pipeline } from 'qirrel'; |
50 | 38 | const pipeline = new Pipeline(); |
51 | | -const result = await pipeline.process('Check out https://github.com and email support@example.com'); |
52 | | -console.log(result.data?.entities); |
| 39 | +const ordered = await pipeline.processBatch(['a', 'b', 'c'], { concurrency: 3 }); |
53 | 40 | ``` |
54 | 41 |
|
55 | 42 | ## LLM Integration |
56 | 43 |
|
57 | | -Connect to large language models for enhanced text analysis: |
58 | | - |
59 | 44 | ```ts |
60 | 45 | import { Pipeline } from 'qirrel'; |
61 | 46 |
|
62 | | -// Enable LLM in your config |
63 | 47 | const pipeline = new Pipeline('./config-with-llm.yaml'); |
64 | | -const llmAdapter = pipeline.getLLMAdapter(); |
| 48 | +await pipeline.init(); |
65 | 49 |
|
| 50 | +const llmAdapter = pipeline.getLLMAdapter(); |
66 | 51 | if (llmAdapter) { |
67 | | - // Use LLM for advanced analysis |
68 | | - const response = await llmAdapter.generateContent('Analyze this text...'); |
69 | | - console.log(response); |
| 52 | + const response = await llmAdapter.generate('Summarize this text: Hello world'); |
| 53 | + console.log(response.content); |
70 | 54 | } |
71 | 55 | ``` |
72 | 56 |
|
73 | 57 | ## Caching |
74 | 58 |
|
75 | | -Qirrel includes built-in caching functionality to improve performance by storing frequently accessed results: |
76 | | - |
77 | 59 | ```ts |
78 | | -import { Pipeline, LruCacheManager } from 'qirrel'; |
| 60 | +import { Pipeline } from 'qirrel'; |
79 | 61 |
|
80 | | -// The pipeline automatically uses caching based on configuration |
81 | 62 | const pipeline = new Pipeline(); |
82 | 63 |
|
83 | | -// Access the cache manager directly if needed |
84 | | -const cacheManager = pipeline.getCacheManager(); |
85 | | - |
86 | | -// Custom cache usage |
87 | | -const cache = new LruCacheManager({ |
88 | | - maxEntries: 1000, // Maximum number of cached items |
89 | | - ttl: 300000 // Time-to-live in milliseconds (5 minutes) |
90 | | -}); |
91 | | - |
92 | | -// Check if a result is already cached |
93 | 64 | if (pipeline.isCached('some text')) { |
94 | | - const cachedResult = pipeline.getCached('some text'); |
95 | | - console.log('Using cached result'); |
| 65 | + console.log(pipeline.getCached('some text')); |
96 | 66 | } else { |
97 | 67 | const result = await pipeline.process('some text'); |
98 | | - console.log('Processing new text'); |
| 68 | + console.log(result.data?.entities); |
99 | 69 | } |
100 | 70 | ``` |
101 | 71 |
|
102 | | -## Pipeline Lifecycle Events |
103 | | - |
104 | | -Monitor and react to pipeline execution with comprehensive lifecycle events: |
105 | | - |
106 | | -```ts |
107 | | -import { Pipeline, PipelineEvent } from 'qirrel'; |
108 | | - |
109 | | -const pipeline = new Pipeline(); |
110 | | - |
111 | | -// Subscribe to pipeline events |
112 | | -pipeline.on(PipelineEvent.RunStart, (payload) => { |
113 | | - console.log('Pipeline started:', payload.context.meta?.requestId); |
114 | | -}); |
115 | | - |
116 | | -pipeline.on(PipelineEvent.ProcessorEnd, (payload) => { |
117 | | - console.log(`Processor ${payload.processorName} completed in ${payload.duration}ms`); |
118 | | -}); |
119 | | - |
120 | | -pipeline.on(PipelineEvent.RunEnd, (payload) => { |
121 | | - console.log('Pipeline completed in', payload.duration, 'ms'); |
122 | | -}); |
123 | | - |
124 | | -const result = await pipeline.process('Your text here'); |
125 | | -``` |
126 | | - |
127 | | -## Use Cases |
128 | | - |
129 | | -Qirrel is perfect for developers building solutions for: |
130 | | - |
131 | | -- **Business Applications**: Extract customer contact details, lead generation from documents, document processing for legal/medical/financial use cases |
132 | | -- **Social Media Analysis**: Process social content for mentions, hashtags, links, and user-generated content patterns |
133 | | -- **Research & Content**: Extract structured data from academic papers, news articles, or documentation |
134 | | -- **Data Processing**: Unstructured data extraction, log file analysis, preprocessing for ML pipelines |
135 | | -- **Communication Tools**: Email processing, chat applications, content moderation |
136 | | - |
137 | 72 | ## Documentation |
| 73 | + |
138 | 74 | - [API Reference](./docs/api.md) |
139 | 75 | - [Configuration Guide](./docs/configuration.md) |
140 | 76 | - [Usage Examples](./docs/examples.md) |
141 | | -- [Code Walkthrough](./docs/walkthrough.md) |
142 | 77 | - [Basic Usage](./docs/usage/basic.md) |
143 | | -- [Advanced Usage](./docs/usage/advanced.md) |
144 | 78 | - [LLM Integration](./docs/integrations/llm.md) |
145 | 79 | - [Pipeline Events](./docs/events.md) |
146 | 80 | - [Caching](./docs/usage/caching.md) |
147 | 81 |
|
148 | 82 | ## Contributing |
149 | | -We welcome contributions from the community! Please read our [Contributing Guide](./docs/contributing.md) for more information. |
| 83 | + |
| 84 | +See [CONTRIBUTING.md](./CONTRIBUTING.md). |
150 | 85 |
|
151 | 86 | ## License |
152 | | -This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details. |
| 87 | + |
| 88 | +MIT. See [LICENSE](./LICENSE). |
0 commit comments