Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Auto-Complete Predictive Text Engine

This repository contains a command-line predictive text engine written in C. It suggests word completions based on a user-entered prefix. The application uses a hash table to efficiently store and retrieve a dictionary of words and their usage frequencies.

Features

  • Prefix-Based Suggestions: Provides real-time word suggestions as you type.
  • Frequency Tracking: Learns from user input by incrementing the frequency of selected words.
  • Persistent Memory: Saves word frequencies to a file, allowing learned behavior to persist across sessions.
  • Dynamic Dictionary: Automatically adds new, unrecognized words to its dictionary.
  • Efficient Data Structure: Implemented with a hash table using a polynomial rolling hash and separate chaining to handle collisions, ensuring fast lookups.

How It Works

The program's core logic is built around a hash table data structure:

  1. Initialization: A hash table is created when the program starts.
  2. Data Loading:
    • It first populates the hash table with an initial set of words from predictive_text/data/dictionary.txt.
    • Next, it loads predictive_text/data/frequency.txt to update the usage counts for words based on previous sessions.
  3. User Interaction Loop:
    • The user is prompted to enter a text prefix.
    • The program searches the entire hash table for all words that start with the entered prefix.
    • The matching words (suggestions) are displayed along with their current frequency count.
    • If the exact word typed by the user is one of the suggestions, its frequency is incremented.
    • If no suggestions are found for the prefix, the prefix is treated as a new word, added to the hash table, and its frequency is initialized.
  4. Saving State: When the user enters exit, the program writes the updated word frequencies from the hash table back into predictive_text/data/frequency.txt before terminating.

File Structure

.
└── predictive_text/
    ├── data/
    │   ├── dictionary.txt  # Base dictionary of words.
    │   └── frequency.txt   # Stores words and their usage frequencies.
    └── src/
        ├── main.c          # Main application entry point and user interaction loop.
        ├── hashtable.c     # Implementation of the hash table data structure.
        ├── hashtable.h     # Header file for the hash table.
        ├── io.c            # File I/O functions for loading/saving data.
        ├── io.h            # Header file for I/O functions.
        ├── utils.c         # Utility functions (e.g., string manipulation).
        └── utils.h         # Header file for utility functions.

Getting Started

Prerequisites

  • A C compiler, such as GCC.

Compilation

  1. Clone the repository and navigate to the source directory:
    git clone https://github.com/drv4ever/auto_complete-.git
    cd auto_complete-/predictive_text/src
  2. Compile the source files using GCC:
    gcc -o autocomplete main.c hashtable.c io.c utils.c

Running the Program

  1. From the src directory, run the executable. The program is configured to find its data files in the parent data directory.
    ./autocomplete
  2. The program will load the dictionary and frequency data, and you can begin typing.
  3. Enter a prefix and press Enter to see suggestions.
    the Dictionary and frequency data loaded
    enter a prefix (or|exit|to quit)hel
    
     Suggestions for 'hel': 
    helicopter  (freq:->) 1
    hell  (freq:->) 1
    help  (freq:->) 1
    hello  (freq:->) 4
    
  4. To close the application, type exit and press Enter. This will save the session's word frequencies before quitting.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages