index and get Methode in text.java done
This commit is contained in:
parent
2d71212b05
commit
812ec1d388
|
@ -0,0 +1 @@
|
||||||
|
/out
|
|
@ -2,16 +2,18 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Text {
|
public class Text {
|
||||||
|
|
||||||
private ArrayList<String> text = new ArrayList<>();
|
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 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<>();
|
private HashMap<String, ArrayList<Integer>> wordbook = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to check if a specific Paragraph exists
|
* Method to check if a specific Paragraph exists
|
||||||
|
*
|
||||||
* @param paragraphNumber the number of the paragraph which should be checked
|
* @param paragraphNumber the number of the paragraph which should be checked
|
||||||
* @return returns true if the paragraph exists
|
* @return returns true if the paragraph exists
|
||||||
*/
|
*/
|
||||||
|
@ -21,12 +23,13 @@ public class Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add a paragraph at a specific position.
|
* Method to add a paragraph at a specific position.
|
||||||
|
*
|
||||||
* @param paragraphNumber number of paragraph where the new text should be added
|
* @param paragraphNumber number of paragraph where the new text should be added
|
||||||
* @param text the Text which should be added.
|
* @param text the Text which should be added.
|
||||||
* @return returns true if the given paragraph exists and is added successfully
|
* @return returns true if the given paragraph exists and is added successfully
|
||||||
*/
|
*/
|
||||||
public boolean add(int paragraphNumber, String text) {
|
public boolean add(int paragraphNumber, String text) {
|
||||||
if(paragraphExists(paragraphNumber)) {
|
if (paragraphExists(paragraphNumber)) {
|
||||||
this.text.add((paragraphNumber - 1), text);
|
this.text.add((paragraphNumber - 1), text);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +38,7 @@ public class Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add a paragraph at the end of the existing text.
|
* Method to add a paragraph at the end of the existing text.
|
||||||
|
*
|
||||||
* @param text the Text which should be added.
|
* @param text the Text which should be added.
|
||||||
* @return returns true if the paragraph is added successfully
|
* @return returns true if the paragraph is added successfully
|
||||||
*/
|
*/
|
||||||
|
@ -43,8 +47,13 @@ public class Text {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add a dummy text paragraph at a specific position.
|
* Method to add a dummy text paragraph at a specific position.
|
||||||
|
*
|
||||||
* @param paragraphNumber number of paragraph where the dummy text should be added
|
* @param paragraphNumber number of paragraph where the dummy text should be added
|
||||||
* @return returns true if the given paragraph exists and is added successfully
|
* @return returns true if the given paragraph exists and is added successfully
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +63,7 @@ public class Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add a dummy text paragraph at the end of the existing text.
|
* Method to add a dummy text paragraph at the end of the existing text.
|
||||||
|
*
|
||||||
* @return returns true if the paragraph is added successfully
|
* @return returns true if the paragraph is added successfully
|
||||||
*/
|
*/
|
||||||
public boolean dummy() {
|
public boolean dummy() {
|
||||||
|
@ -62,13 +72,14 @@ public class Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to replace characters in a specific paragraph
|
* Method to replace characters in a specific paragraph
|
||||||
|
*
|
||||||
* @param paragraphNumber number of paragraph which should be changed.
|
* @param paragraphNumber number of paragraph which should be changed.
|
||||||
* @param oldChar the old character.
|
* @param oldChar the old character.
|
||||||
* @param newChar the new character.
|
* @param newChar the new character.
|
||||||
* @return returns true if the given paragraph exists and is changed successfully
|
* @return returns true if the given paragraph exists and is changed successfully
|
||||||
*/
|
*/
|
||||||
public boolean replace(int paragraphNumber, String oldChar, String newChar) {
|
public boolean replace(int paragraphNumber, String oldChar, String newChar) {
|
||||||
if(paragraphExists(paragraphNumber)) {
|
if (paragraphExists(paragraphNumber)) {
|
||||||
text.set((paragraphNumber - 1), text.get(paragraphNumber - 1).replace(oldChar, newChar));
|
text.set((paragraphNumber - 1), text.get(paragraphNumber - 1).replace(oldChar, newChar));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -77,6 +88,7 @@ public class Text {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to replace characters in the last paragraph
|
* Method to replace characters in the last paragraph
|
||||||
|
*
|
||||||
* @param oldChar the old character.
|
* @param oldChar the old character.
|
||||||
* @param newChar the new character.
|
* @param newChar the new character.
|
||||||
* @return returns true if the paragraph is changed successfully
|
* @return returns true if the paragraph is changed successfully
|
||||||
|
@ -88,43 +100,59 @@ public class Text {
|
||||||
|
|
||||||
|
|
||||||
public boolean del(int paragraphNumber) {
|
public boolean del(int paragraphNumber) {
|
||||||
if(paragraphExists(paragraphNumber)) {
|
if (paragraphExists(paragraphNumber)) {
|
||||||
text.remove(paragraphNumber-1);
|
text.remove(paragraphNumber - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean del() {
|
public boolean del() {
|
||||||
text.remove(text.size()-1);
|
text.remove(text.size() - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String,ArrayList<Integer>> index(ArrayList<String> text) {
|
public ArrayList<String> index() {
|
||||||
for (int i = 0;i < text.size();i++) {
|
wordbook = createWordlist();
|
||||||
String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><\'/]+");
|
ArrayList<String> output = new ArrayList<>();
|
||||||
for (String wort: woerter) {
|
for (Map.Entry<String, ArrayList<Integer>> entry : wordbook.entrySet()) {
|
||||||
ArrayList<Integer> zahlenListe;
|
String key = entry.getKey();
|
||||||
if(wordbook.containsKey(wort)) {
|
ArrayList<Integer> values = entry.getValue();
|
||||||
zahlenListe = wordbook.get(wort);
|
if (values.get(0) >= 3) {
|
||||||
zahlenListe.add(0, zahlenListe.get(0)+1);
|
output.add(key);
|
||||||
if(zahlenListe.size()<i++){
|
for (int value : values) {
|
||||||
zahlenListe.add(i++);
|
output.add(String.valueOf(value));
|
||||||
}
|
|
||||||
wordbook.put(wort,zahlenListe);
|
|
||||||
}else{
|
|
||||||
zahlenListe = new ArrayList<>();
|
|
||||||
zahlenListe.add(1);
|
|
||||||
zahlenListe.add(i++);
|
|
||||||
wordbook.put(wort,zahlenListe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, ArrayList<Integer>> createWordlist() {
|
||||||
|
for (int i = 0; i < text.size(); i++) {
|
||||||
|
String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><\'/]+");
|
||||||
|
for (String wort : woerter) {
|
||||||
|
ArrayList<Integer> zahlenListe;
|
||||||
|
int zähler = 1;
|
||||||
|
if (wordbook.containsKey(wort)) {
|
||||||
|
zahlenListe = wordbook.get(wort);
|
||||||
|
zähler = zahlenListe.get(0);
|
||||||
|
zahlenListe.remove(0);
|
||||||
|
zahlenListe.add(0, zähler + 1);
|
||||||
|
|
||||||
|
if (zahlenListe.get(zahlenListe.size() - 1) < i + 1) {
|
||||||
|
zahlenListe.add(i + 1);
|
||||||
|
}
|
||||||
|
wordbook.put(wort, zahlenListe);
|
||||||
|
} else {
|
||||||
|
zahlenListe = new ArrayList<>();
|
||||||
|
zahlenListe.add(1);
|
||||||
|
zahlenListe.add(zähler);
|
||||||
|
wordbook.put(wort, zahlenListe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return wordbook;
|
return wordbook;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWordbook() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,5 @@ public class TextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void indexTest() {
|
void indexTest() {
|
||||||
hMap = txt.index(sListe);
|
|
||||||
for(Map.Entry<String,ArrayList<Integer>> entry : hMap.entrySet()) {
|
|
||||||
System.out.println("Key: " + entry.getKey() + " Value: " + entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue