Compare commits

..

No commits in common. "main" and "mainn" have entirely different histories.
main ... mainn

8 changed files with 45 additions and 154 deletions

View File

@ -1,28 +0,0 @@
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.

View File

@ -1,53 +1,32 @@
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Analyser { public class Analyser {
public static ArrayList<Integer> countElements(ArrayList<String> uniqueWordList, ArrayList<String> allWordsList) { public static int countElements(ArrayList<String> list) {
ArrayList<Integer> individualWordCount = new ArrayList<>(); return list.size();
for (int i = 0; i < uniqueWordList.size(); i++) {
individualWordCount.add(0);
} }
for (String word : allWordsList) { public static HashMap<String, Integer> individualWordCount(ArrayList<String> words) {
int wordCount = individualWordCount.get(uniqueWordList.indexOf(word)); HashMap<String, Integer> individualWordsCount = new HashMap<>();
individualWordCount.set(uniqueWordList.indexOf(word), ++wordCount);
for (String word : words) {
if (individualWordsCount.containsKey(word)) {
int currentCount = individualWordsCount.get(word);
individualWordsCount.put(word, currentCount+1);
} else {
individualWordsCount.put(word,1);
} }
return individualWordCount; }
return individualWordsCount;
} }
public static String[] frequentWords(ArrayList<String> uniqueWordList, ArrayList<Integer> wordCounts) {
ArrayList<String> wordsCopy = new ArrayList<>(uniqueWordList);
ArrayList<Integer> countsCopy = new ArrayList<>(wordCounts);
String[] frequentWords = new String[10]; public static ArrayList< Map.Entry< String, Integer > > sortWordsByFrequency(HashMap< String, Integer > wordCounts) {
ArrayList< Map.Entry< String, Integer > > sortedList = new ArrayList<>(wordCounts.entrySet());
for (int i = 0; i < frequentWords.length; i++) { sortedList.sort((a, b) -> b.getValue().compareTo(a.getValue()));
if (wordsCopy.isEmpty()) { return sortedList;
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.

View File

@ -1,65 +1,13 @@
import java.util.ArrayList; void main() {
public class Main { String filePath = "C:\\Users\\Toni G\\IdeaProjects\\GitPeerGroup\\src\\BeeMovieScript.txt";
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> fileLines = TextReader.readFileLines(filePath);
ArrayList<String> fileWords = TextReader.linesToWords(fileLines); ArrayList<String> fileWords = TextReader.linesToWords(fileLines);
ArrayList<String> uniqueWords = TextReader.uniqueWordList(fileWords); HashMap<String, Integer> wordCounts = Analyser.individualWordCount(fileWords);
ArrayList<Integer> wordCounts = Analyser.countElements(uniqueWords, fileWords); ArrayList< Map.Entry< String, Integer > > sortedList = Analyser.sortWordsByFrequency(wordCounts);
IO.println(wordCounts);
IO.println(sortedList);
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.

View File

@ -1,17 +1,17 @@
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import java.util.ArrayList;
public class TextReader { public class TextReader {
static boolean isRealFile = false;
Scanner sc = new Scanner(System.in);
public static ArrayList<String> readFileLines(String filePath) { public static ArrayList<String> readFileLines(String filePath) {
ArrayList<String> lines = new ArrayList<>(); ArrayList<String> lines = new ArrayList<>();
File file = new File (filePath); File file = new File (filePath);
try (Scanner scanner = new Scanner(file)) { try (Scanner scanner = new Scanner(file)) {
isRealFile = true;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
lines.add(line); lines.add(line);
@ -25,6 +25,7 @@ public class TextReader {
public static ArrayList<String> linesToWords(ArrayList<String> lines) { public static ArrayList<String> linesToWords(ArrayList<String> lines) {
ArrayList<String> words = new ArrayList<>(); ArrayList<String> words = new ArrayList<>();
for (String line : lines) { for (String line : lines) {
String[] currentLine = line.split(" "); String[] currentLine = line.split(" ");
for (String word : currentLine) { for (String word : currentLine) {
@ -34,20 +35,11 @@ public class TextReader {
.replace("!", "") .replace("!", "")
.replace("?", "") .replace("?", "")
.replace("\"", ""); .replace("\"", "");
} }
words.add(word); words.add(word);
} }
} }
return words; 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;
}
} }