- Name: Muhammad Sarim Shah
- Roll Number: 22K4299
- Course: Software for Mobile Devices
This project demonstrates a simple Dart program designed to analyze sentences and calculate word frequency. The program identifies how many times each word appears and determines the most frequent word in each sentence.
The purpose of this task is to practice:
- Basic Dart Programming: Syntax and structure.
- Data Structures: Working with Lists and loops.
- String Manipulation: Cleaning and splitting text.
- Algorithms: Basic frequency counting logic.
The program processes a list of sentences through the following logical steps:
- Normalization: Converts the sentence to lowercase for case-insensitive comparison.
- Tokenization: Splits the sentence into individual words.
- Iteration: Loops through each word to count occurrences.
- Deduplication: Stores unique words to avoid redundant counting.
- Analytics: Displays the frequency of each word and identifies the most frequent one.
this is a test this ishello hello worlddart is fun fun fun
Sentence:
this is a test this is
- 'this' -> 2
- 'is' -> 2
- 'a' -> 1
- 'test' -> 1
Result: Most frequent word: 'this' with count = 2
| Concept | Application |
|---|---|
| Dart List | To store the collection of sentences and word tokens. |
| For Loops | To iterate through the words for counting. |
| String Functions | toLowerCase(), split(), and trim(). |
| Conditional Statements | To compare counts and find the maximum frequency. |
- Install Dart: Ensure you have the Dart SDK or Flutter environment installed.
- Create File: Copy the source code into a file named
main.dart. - Run: Execute the following command in your terminal:
dart run main.dart
This class work demonstrates how to process text in Dart and compute word frequencies using simple loops and lists. It helps in understanding basic data processing techniques commonly used in applications such as text analysis and search engines.