A modern TypeScript implementation of Avro Phonetic, a phonetic parser that converts Roman characters to Bengali script.
Input Text (English/Roman)
↓
+------------------+
| AvroPhonetic | ← Main entry point
+------------------+
↓
+------------------+
| SuggestionBuilder| ← Manages suggestions and caching
+------------------+
↙ ↘
+---------+ +------------+
|Phonetic | | Database | ← Pattern matching & dictionary lookup
|Processor| | Search |
+---------+ +------------+
↓ ↓
Bengali suggestions
↓
Selected output saved
to candidate cache
The main entry point class that users interact with.
const avro = new AvroPhonetic();
const suggestions = avro.suggest("ami"); // Get suggestions
avro.commit("ami", "আমি"); // Commit selectionFlow:
User Input → suggest() → SuggestionBuilder
↪ Returns suggestions array
Selected word → commit() → Updates cache
Heart of the suggestion system, coordinates between different components.
Features:
- Manages suggestion cache
- Handles dictionary lookups
- Applies phonetic rules
- Maintains user's previous selections
Flow:
Input Text
↓
1. Split into parts (begin/middle/end)
↓
2. Get phonetic conversion
↓
3. Search dictionary
↓
4. Apply suffix rules
↓
5. Sort suggestions
↓
6. Return result with prev selection
Handles core phonetic pattern matching and conversion.
Rules example:
Input: "bhl" Input: "aa"
↓ ↓
Check patterns Check patterns
↓ ↓
Output: "ভ্ল" Output: "আ"
Pattern matching flow:
Input character
↓
+----------------+
| Match patterns |←→ Pattern database
+----------------+
↓
Apply rules
↓
Return Bengali chars
Manages dictionary lookups and word suggestions.
Flow:
Input word
↓
1. Get candidates by first char
↓
2. Convert to regex pattern
↓
3. Search in word tables
↓
4. Return matching words
Handles complex pattern matching using regular expressions.
Features:
- Complex character combinations
- Special character handling
- Contextual matches
Input text
↓
+------------------+
| Process patterns |←→ Regex patterns
+------------------+
↓
Apply transformations
↓
Return regex string
Utils (utils.ts)
- String manipulation
- Levenshtein distance calculation
- Unicode conversion
- Special character detection
Dictionaries (dictionaries.ts)
+-------------------+
| Dictionary |
+-------------------+
| - Word tables |
| - Suffix rules |
| - Autocorrect |
+-------------------+
User types "amar"
↓
AvroPhonetic.suggest()
↓
SuggestionBuilder
↙ ↓ ↘
Phonetic Database RegexProcessor
Processor Search
↓ ↓ ↓
Parse Find Generate
patterns matches patterns
↓ ↓ ↓
→ Combine results ←
↓
Apply suffix rules
↓
Sort suggestions
↓
Return ["আমার", ...]
↓
User selects "আমার"
↓
AvroPhonetic.commit()
↓
Update cache & save
import { AvroPhonetic } from './avrolib';
// Initialize
const avro = new AvroPhonetic({
loadCandidateSelectionsFromFile: () => loadFromStorage(),
saveCandidateSelectionsToFile: (data) => saveToStorage(data)
});
// Get suggestions
const result = avro.suggest("amar");
// result = { words: ["আমার", ...], prevSelection: 0 }
// Commit selection
avro.commit("amar", "আমার");User Input ("amar")
↓
AvroPhonetic
↓
SuggestionBuilder
↙ ↓ ↘
PP DS RP [Components]
↓ ↓ ↓
phonetic dict regex [Processing]
↓ ↓ ↓
suggestions merged [Combination]
↓
sorted by relevance [Ranking]
↓
returned to user [Output]
Where:
- PP: PhoneticProcessor
- DS: DatabaseSearch
- RP: RegexProcessor
This modular architecture allows for:
- Easy maintenance
- Clear separation of concerns
- Extensible components
- Testable units
- Efficient caching
- Type safety
Each component can be used independently or as part of the full system, making the library flexible for different use cases.