Compare commits
5 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
6828768a98 | |
|
|
9b8768a75d | |
|
|
5a1ed6a026 | |
|
|
36fe58154e | |
|
|
56ba0ed661 |
|
|
@ -0,0 +1,28 @@
|
|||
AUTOMATISCHES CODE-REVIEW
|
||||
=========================
|
||||
Hinweis: Diese Befunde wurden maschinell (Checkstyle) und mit KI (lokales Sprachmodell)
|
||||
ausgewertet. Sie können Fehler enthalten und sind daher ggf. nochmals manuell zu prüfen.
|
||||
|
||||
======================================================================
|
||||
STATISCHE ANALYSE (Checkstyle)
|
||||
======================================================================
|
||||
Verstöße gesamt: 4
|
||||
|
||||
Übersicht je Regel:
|
||||
3 PackageDeclaration
|
||||
1 VisibilityModifier
|
||||
|
||||
[PackageDeclaration] (3×)
|
||||
src/TextReader.java:1 – Es fehlt eine Package-Deklaration.
|
||||
src/Main.java:1 – Es fehlt eine Package-Deklaration.
|
||||
src/Analyser.java:1 – Es fehlt eine Package-Deklaration.
|
||||
[VisibilityModifier] (1×)
|
||||
src/TextReader.java:7 – Das Feld 'isRealFile' muss als private deklariert werden und Zugriffsmethoden haben.
|
||||
|
||||
======================================================================
|
||||
BEZEICHNER (KI-Auswertung)
|
||||
======================================================================
|
||||
Geprüfte Bezeichner: 45, problematisch: 0
|
||||
Sprache der Bezeichner: englisch (fast alle Namen sind englisch)
|
||||
|
||||
Keine problematischen Bezeichner gefunden.
|
||||
Binary file not shown.
|
|
@ -1,32 +1,53 @@
|
|||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Analyser {
|
||||
|
||||
public static int countElements(ArrayList<String> list) {
|
||||
return list.size();
|
||||
public static ArrayList<Integer> countElements(ArrayList<String> uniqueWordList, ArrayList<String> allWordsList) {
|
||||
ArrayList<Integer> individualWordCount = new ArrayList<>();
|
||||
for (int i = 0; i < uniqueWordList.size(); i++) {
|
||||
individualWordCount.add(0);
|
||||
}
|
||||
|
||||
public static HashMap<String, Integer> individualWordCount(ArrayList<String> words) {
|
||||
HashMap<String, Integer> individualWordsCount = new HashMap<>();
|
||||
|
||||
for (String word : words) {
|
||||
if (individualWordsCount.containsKey(word)) {
|
||||
int currentCount = individualWordsCount.get(word);
|
||||
individualWordsCount.put(word, currentCount+1);
|
||||
} else {
|
||||
individualWordsCount.put(word,1);
|
||||
for (String word : allWordsList) {
|
||||
int wordCount = individualWordCount.get(uniqueWordList.indexOf(word));
|
||||
individualWordCount.set(uniqueWordList.indexOf(word), ++wordCount);
|
||||
}
|
||||
}
|
||||
return individualWordsCount;
|
||||
return individualWordCount;
|
||||
}
|
||||
|
||||
public static String[] frequentWords(ArrayList<String> uniqueWordList, ArrayList<Integer> wordCounts) {
|
||||
ArrayList<String> wordsCopy = new ArrayList<>(uniqueWordList);
|
||||
ArrayList<Integer> countsCopy = new ArrayList<>(wordCounts);
|
||||
|
||||
public static ArrayList< Map.Entry< String, Integer > > sortWordsByFrequency(HashMap< String, Integer > wordCounts) {
|
||||
ArrayList< Map.Entry< String, Integer > > sortedList = new ArrayList<>(wordCounts.entrySet());
|
||||
sortedList.sort((a, b) -> b.getValue().compareTo(a.getValue()));
|
||||
return sortedList;
|
||||
String[] frequentWords = new String[10];
|
||||
|
||||
for (int i = 0; i < frequentWords.length; i++) {
|
||||
if (wordsCopy.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
int highestFrequency = 0;
|
||||
int highestIndex = 0;
|
||||
|
||||
for (int j = 0; j < wordsCopy.size(); j++) {
|
||||
if (countsCopy.get(j) > highestFrequency) {
|
||||
highestFrequency = countsCopy.get(j);
|
||||
highestIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
frequentWords[i] = wordsCopy.get(highestIndex);
|
||||
countsCopy.remove(highestIndex);
|
||||
wordsCopy.remove(highestIndex);
|
||||
}
|
||||
return frequentWords;
|
||||
}
|
||||
|
||||
public static int searchWord(ArrayList<String> uniqueWordList, ArrayList<Integer> wordCounts, String target) {
|
||||
int index = uniqueWordList.indexOf(target);
|
||||
if (index != -1) {
|
||||
return wordCounts.get(index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1,13 +1,65 @@
|
|||
void main() {
|
||||
import java.util.ArrayList;
|
||||
|
||||
String filePath = "C:\\Users\\Toni G\\IdeaProjects\\GitPeerGroup\\src\\BeeMovieScript.txt";
|
||||
|
||||
ArrayList<String> fileLines = TextReader.readFileLines(filePath);
|
||||
ArrayList<String> fileWords = TextReader.linesToWords(fileLines);
|
||||
HashMap<String, Integer> wordCounts = Analyser.individualWordCount(fileWords);
|
||||
ArrayList< Map.Entry< String, Integer > > sortedList = Analyser.sortWordsByFrequency(wordCounts);
|
||||
IO.println(wordCounts);
|
||||
IO.println(sortedList);
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArrayList<String> fileLines = null;
|
||||
|
||||
while (!TextReader.isRealFile) {
|
||||
String file = IO.readln("Enter the name of the file: ");
|
||||
final String filePath = "C:\\Users\\Toni G\\IdeaProjects\\GitPeerGroup\\src\\Textfiles\\" + file;
|
||||
fileLines = TextReader.readFileLines(filePath);
|
||||
}
|
||||
|
||||
ArrayList<String> fileWords = TextReader.linesToWords(fileLines);
|
||||
ArrayList<String> uniqueWords = TextReader.uniqueWordList(fileWords);
|
||||
ArrayList<Integer> wordCounts = Analyser.countElements(uniqueWords, fileWords);
|
||||
|
||||
boolean running = true;
|
||||
|
||||
while (running) {
|
||||
IO.println("\nText Viewer ");
|
||||
IO.println("1: Total Word Count");
|
||||
IO.println("2: All Words and their Frequency");
|
||||
IO.println("3: Top 10 Words");
|
||||
IO.println("4: Look up Word:");
|
||||
IO.println("5: Exit");
|
||||
|
||||
String choice = IO.readln("Pick a Number [1. |2. |3. |4. |5. ]");
|
||||
|
||||
switch (choice) {
|
||||
case "1" -> {
|
||||
IO.println("Woerter gesamt: " + fileWords.size());
|
||||
IO.println("Unterschiedliche Woerter: " + uniqueWords.size());
|
||||
}
|
||||
case "2" -> printWords(uniqueWords, wordCounts);
|
||||
case "3" -> {
|
||||
String[] frequentWords = Analyser.frequentWords(uniqueWords, wordCounts);
|
||||
printFrequentWords(frequentWords);
|
||||
}
|
||||
|
||||
case "4" -> {
|
||||
String neededWord = IO.readln("Which Word do you want to look up?:");
|
||||
int foundWordCount = Analyser.searchWord(uniqueWords, wordCounts, neededWord);
|
||||
IO.println("The word " + neededWord + " appeared " + foundWordCount + " Times");
|
||||
}
|
||||
case "5" -> running = false;
|
||||
default -> IO.println("Ungueltige Eingabe.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void printWords(ArrayList<String> uniqueWords, ArrayList<Integer> wordCounts) {
|
||||
for (String word : uniqueWords) {
|
||||
System.out.println(word + " = " + wordCounts.get(uniqueWords.indexOf(word)));
|
||||
}
|
||||
}
|
||||
|
||||
static void printFrequentWords(String[] frequentWords) {
|
||||
for (int i = 0; i < frequentWords.length; i++) {
|
||||
if (frequentWords[i] != null) {
|
||||
System.out.println((i + 1) + ". " + frequentWords[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1,17 +1,17 @@
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TextReader {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
static boolean isRealFile = false;
|
||||
|
||||
public static ArrayList<String> readFileLines(String filePath) {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
File file = new File(filePath);
|
||||
|
||||
try (Scanner scanner = new Scanner(file)) {
|
||||
isRealFile = true;
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
lines.add(line);
|
||||
|
|
@ -25,7 +25,6 @@ public class TextReader {
|
|||
public static ArrayList<String> linesToWords(ArrayList<String> lines) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
for (String line : lines) {
|
||||
|
||||
String[] currentLine = line.split(" ");
|
||||
|
||||
for (String word : currentLine) {
|
||||
|
|
@ -35,11 +34,20 @@ public class TextReader {
|
|||
.replace("!", "")
|
||||
.replace("?", "")
|
||||
.replace("\"", "");
|
||||
|
||||
}
|
||||
words.add(word);
|
||||
}
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
public static ArrayList<String> uniqueWordList(ArrayList<String> wordList) {
|
||||
ArrayList<String> uniqueWords = new ArrayList<>();
|
||||
for (String word : wordList) {
|
||||
if (!uniqueWords.contains(word)) {
|
||||
uniqueWords.add(word);
|
||||
}
|
||||
}
|
||||
return uniqueWords;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue