Menu
Coddy logo textTech

Analyse anzeigen

Teil des Abschnitts Logik & Ablauf der Dart-Journey von Coddy — Lektion 57 von 65.

challenge icon

Aufgabe

Einfach

In dieser letzten Lektion des Text-Analyzer-Projekts erstellen Sie eine umfassende Anzeige aller Analyseergebnisse, die Sie im Laufe des Projekts gesammelt haben. In diesem Schritt werden alle Statistiken in einer klaren, professionellen Zusammenfassung formatiert und präsentiert, die die vollständige Textanalyse zeigt.

  1. Verwenden Sie alle Variablen aus Ihren vorherigen Projektschritten:
    • textToAnalyze aus Ihrem Projekt-Setup
    • totalCharacters aus Ihrem Schritt zur Zeichenzählung
    • wordList aus Ihrem Schritt zur Worttrennung
    • totalWords aus Ihrem Schritt zur Wortzählung
    • uniqueWordsSet aus Ihrem Schritt zur Zählung eindeutiger Wörter
    • uniqueWordCount aus Ihrem Schritt zur Zählung eindeutiger Wörter
    • wordFrequency aus Ihrem Schritt zum Wortfrequenzzähler
  2. Erstellen Sie einen umfassenden Abschlussbericht, der alle Analyseergebnisse anzeigt
  3. Formatieren Sie die Ausgabe so, dass sie eine vollständige Zusammenfassung der Textanalyse zeigt
  4. Fügen Sie alle Statistiken mit klaren Beschriftungen und korrekter Formatierung ein
  5. Zeigen Sie die Ergebnisse in dem unten gezeigten exakten Format an

Wenn Ihr Text-Analyzer beispielsweise mit "hello world hello" eingerichtet wurde, sollte Ihr Programm Folgendes ausgeben:

=======================================
    TEXT ANALYSIS COMPLETE REPORT    
=======================================
Original Text: "hello world hello"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 17
- Total Words: 3
- Unique Words: 2
- Most Common Word: hello (appears 2 times)
=======================================
DETAILED BREAKDOWN:
Word List: [hello, world, hello]
Unique Words Set: {hello, world}
Word Frequency Map: {hello: 2, world: 1}
=======================================
Analysis completed successfully!
Text contains 2 unique words out of 3 total words.
=======================================

Wenn Ihr Text-Analyzer mit "the cat and the dog and the bird" eingerichtet wurde, sollte Ihr Programm Folgendes ausgeben:

=======================================
    TEXT ANALYSIS COMPLETE REPORT    
=======================================
Original Text: "the cat and the dog and the bird"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 33
- Total Words: 8
- Unique Words: 5
- Most Common Word: the (appears 3 times)
=======================================
DETAILED BREAKDOWN:
Word List: [the, cat, and, the, dog, and, the, bird]
Unique Words Set: {the, cat, and, dog, bird}
Word Frequency Map: {the: 3, cat: 1, and: 2, dog: 1, bird: 1}
=======================================
Analysis completed successfully!
Text contains 5 unique words out of 8 total words.
=======================================

Wenn Ihr Text-Analyzer mit "apple banana apple cherry banana apple" eingerichtet wurde, sollte Ihr Programm Folgendes ausgeben:

=======================================
    TEXT ANALYSIS COMPLETE REPORT    
=======================================
Original Text: "apple banana apple cherry banana apple"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 38
- Total Words: 6
- Unique Words: 3
- Most Common Word: apple (appears 3 times)
=======================================
DETAILED BREAKDOWN:
Word List: [apple, banana, apple, cherry, banana, apple]
Unique Words Set: {apple, banana, cherry}
Word Frequency Map: {apple: 3, banana: 2, cherry: 1}
=======================================
Analysis completed successfully!
Text contains 3 unique words out of 6 total words.
=======================================

Ihr Programm sollte das am häufigsten vorkommende Wort ermitteln, indem es das Wort mit der höchsten Häufigkeit in der wordFrequency-Map findet. Verwenden Sie String-Interpolation, um alle gesammelten Daten in einem professionellen, leicht lesbaren Format anzuzeigen. Diese abschließende Anzeige führt alle Analysearbeiten, die Sie im Laufe des Projekts abgeschlossen haben, in einer umfassenden Zusammenfassung zusammen.

Probier es selbst

import 'dart:io';

void main() {
  String? textToAnalyze = stdin.readLineSync();
  
  int totalCharacters = textToAnalyze!.length;
  
  List<String> wordList = textToAnalyze.split(' ');
  
  int totalWords = wordList.length;
  
  Set<String> uniqueWordsSet = wordList.toSet();
  
  int uniqueWordCount = uniqueWordsSet.length;
  
  Map<String, int> wordFrequency = {};
  
  for (String word in wordList) {
    if (wordFrequency.containsKey(word)) {
      wordFrequency[word] = wordFrequency[word]! + 1;
    } else {
      wordFrequency[word] = 1;
    }
  }
  
  print('Text Analysis Tool - Word Frequency');
  print('====================================');
  print('Analyzing text: "$textToAnalyze"');
  print('Total characters: $totalCharacters');
  print('Words found: $wordList');
  print('Total words: $totalWords');
  print('Unique words: $uniqueWordsSet');
  print('Unique word count: $uniqueWordCount');
  print('====================================');
  print('Word Frequency Analysis Results:');
  print('Word frequencies: $wordFrequency');
  print('====================================');
  print('Word frequency analysis completed successfully.');
}

Alle Lektionen in Logik & Ablauf