Menu
Coddy logo textTech

解析結果の表示

CoddyのDartジャーニー「論理とフロー」セクションの一部 — レッスン 57/65。

challenge icon

チャレンジ

簡単

テキストアナライザープロジェクトのこの最終レッスンでは、プロジェクト全体を通じて収集したすべての分析結果を包括的に表示します。このステップでは、すべての統計を明確でプロフェッショナルなサマリーとしてフォーマットし、テキスト分析の全容を提示します。

  1. これまでのプロジェクトステップで使用したすべての変数を使用してください:
    • プロジェクトセットアップからの textToAnalyze
    • 文字数カウントステップからの totalCharacters
    • 単語分割ステップからの wordList
    • 単語数カウントステップからの totalWords
    • ユニーク単語数カウントステップからの uniqueWordsSet
    • ユニーク単語数カウントステップからの uniqueWordCount
    • 単語頻度カウンターステップからの wordFrequency
  2. すべての分析結果を表示する包括的な最終レポートを作成してください
  3. テキスト分析の完全なサマリーを示すように出力をフォーマットしてください
  4. 明確なラベルと適切なフォーマットですべての統計を含めてください
  5. 以下に示す正確な形式で結果を表示してください

例えば、テキストアナライザーが "hello world hello" でセットアップされている場合、プログラムは次のように出力する必要があります:

=======================================
    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.
=======================================

テキストアナライザーが "the cat and the dog and the bird" でセットアップされている場合、プログラムは次のように出力する必要があります:

=======================================
    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.
=======================================

テキストアナライザーが "apple banana apple cherry banana apple" でセットアップされている場合、プログラムは次のように出力する必要があります:

=======================================
    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.
=======================================

プログラムは、wordFrequency マップ内で最も高い頻度カウントを持つ単語を見つけることで、最も一般的な単語を特定する必要があります。文字列補間(string interpolation)を使用して、収集したすべてのデータをプロフェッショナルで読みやすい形式で表示してください。この最終的な表示により、プロジェクト全体で完了したすべての分析作業が1つの包括的なサマリーにまとめられます。

自分で試してみよう

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.');
}

論理とフローのすべてのレッスン