Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

عد الكلمات الفريدة

جزء من قسم Logic & Flow في رحلة Dart على Coddy — الدرس 55 من 65.

challenge icon

التحدي

سهل

استمراراً لمشروع محلل النصوص الخاص بك، ستقوم الآن بتنفيذ وظيفة عد الكلمات الفريدة. ستحدد هذه الخطوة عدد الكلمات المتميزة التي تظهر في نصك باستخدام Set لإزالة التكرارات تلقائياً من قائمة الكلمات الخاصة بك.

  1. استخدم المتغير textToAnalyze من إعدادك السابق
  2. استخدم المتغير totalCharacters من خطوة عد الأحرف
  3. استخدم المتغير wordList من خطوة تقسيم الكلمات
  4. استخدم المتغير totalWords من خطوة عد الكلمات
  5. قم بتحويل قائمة الكلمات إلى Set باستخدام Set.from() لإزالة الكلمات المكررة تلقائياً
  6. قم بتخزين الـ Set الناتجة في متغير يسمى uniqueWordsSet
  7. قم بعد الكلمات الفريدة باستخدام خاصية .length في الـ Set
  8. قم بتخزين عدد الكلمات الفريدة في متغير يسمى uniqueWordCount
  9. اعرض نتائج تحليل الكلمات الفريدة بالتنسيق الدقيق الموضح أدناه
  10. أظهر النص الأصلي، وعدد الأحرف، وقائمة الكلمات، وإجمالي الكلمات، ومجموعة الكلمات الفريدة، وعدد الكلمات الفريدة مع التنسيق المناسب

على سبيل المثال، إذا تم إعداد محلل النصوص الخاص بك بـ "Hello world hello"، فيجب أن يخرج برنامجك ما يلي:

Text Analysis Tool - Unique Words
====================================
Analyzing text: "Hello world hello"
Total characters: 17
Words found: [Hello, world, hello]
Total words: 3
====================================
Unique Word Analysis Results:
Unique words: {Hello, world, hello}
Unique word count: 3
====================================
Unique word analysis completed successfully.

إذا تم إعداد محلل النصوص الخاص بك بـ "The cat and the dog"، فيجب أن يخرج برنامجك ما يلي:

Text Analysis Tool - Unique Words
====================================
Analyzing text: "The cat and the dog"
Total characters: 19
Words found: [The, cat, and, the, dog]
Total words: 5
====================================
Unique Word Analysis Results:
Unique words: {The, cat, and, the, dog}
Unique word count: 4
====================================
Unique word analysis completed successfully.

إذا تم إعداد محلل النصوص الخاص بك بـ "apple banana apple cherry banana"، فيجب أن يخرج برنامجك ما يلي:

Text Analysis Tool - Unique Words
====================================
Analyzing text: "apple banana apple cherry banana"
Total characters: 33
Words found: [apple, banana, apple, cherry, banana]
Total words: 5
====================================
Unique Word Analysis Results:
Unique words: {apple, banana, cherry}
Unique word count: 3
====================================
Unique word analysis completed successfully.

يجب أن يستخدم برنامجك Set.from() لتحويل قائمة الكلمات إلى Set، مما يؤدي تلقائياً إلى إزالة الكلمات المكررة مع الحفاظ على الكلمات الفريدة. ستعطيك خاصية .length في الـ Set عدد الكلمات الفريدة. سيساعد هذا التحليل في تحديد ثراء المفردات في النص وسيتم استخدامه جنباً إلى جنب مع مقاييس أخرى في الدروس القادمة.

جرّب بنفسك

import 'dart:io';

void main() {
  String? textToAnalyze = stdin.readLineSync();
  int totalCharacters = textToAnalyze!.length;
  List<String> wordList = textToAnalyze.split(' ');
  int totalWords = wordList.length;
  
  print('Text Analysis Tool - Word Count');
  print('====================================');
  print('Analyzing text: "$textToAnalyze"');
  print('Total characters: $totalCharacters');
  print('Words found: $wordList');
  print('====================================');
  print('Word Count Results:');
  print('Total words: $totalWords');
  print('====================================');
  print('Word counting completed successfully.');
}

جميع دروس Logic & Flow