Test add index and del

This commit is contained in:
Andrin Fassbind 2021-11-05 09:18:35 +01:00
parent ccfe9668c0
commit 2d71212b05
1 changed files with 31 additions and 3 deletions

View File

@ -1,13 +1,14 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class Text {
private ArrayList<String> text = new ArrayList<>();
private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";
private HashMap<String,ArrayList<Integer>> wordbook = new HashMap<>();
/**
* Method to check if a specific Paragraph exists
@ -88,15 +89,42 @@ public class Text {
public boolean del(int paragraphNumber) {
if(paragraphExists(paragraphNumber)) {
//paragraph hier löschen.
text.remove(paragraphNumber-1);
return true;
}
return false;
}
public boolean del() {
//letzter paragraph hier löschen.
text.remove(text.size()-1);
return true;
}
public HashMap<String,ArrayList<Integer>> index(ArrayList<String> text) {
for (int i = 0;i < text.size();i++) {
String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><\'/]+");
for (String wort: woerter) {
ArrayList<Integer> zahlenListe;
if(wordbook.containsKey(wort)) {
zahlenListe = wordbook.get(wort);
zahlenListe.add(0, zahlenListe.get(0)+1);
if(zahlenListe.size()<i++){
zahlenListe.add(i++);
}
wordbook.put(wort,zahlenListe);
}else{
zahlenListe = new ArrayList<>();
zahlenListe.add(1);
zahlenListe.add(i++);
wordbook.put(wort,zahlenListe);
}
}
}
return wordbook;
}
private void updateWordbook() {
}
}