Commit 32c7e09d authored by Maria Barbatei's avatar Maria Barbatei

Adding AbsatzSplitter erste Version

parent fd0008c1
package Ueb6;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AbsatzSplitter {
public static final String PATH = "/Users/mariabarbatei/Desktop/Arztbrief1.txt";
public static void main(String[] args) throws IOException {
FileReader arztBrief = new FileReader(PATH);
StringBuilder arztBriefAsStringBuilder = new StringBuilder();
String zeile = "";
String arztBriefAsString = "";
@SuppressWarnings("resource")
BufferedReader buffer = new BufferedReader(arztBrief);
while((zeile = buffer.readLine()) != null) {
if(zeile.isEmpty()) {
arztBriefAsStringBuilder.append(System.getProperty("line.separator"));
} else {
arztBriefAsStringBuilder.append(zeile);
}
}
//brief wird in einem String umgewandelt
arztBriefAsString = arztBriefAsStringBuilder.toString();
//System.out.println(arztBriefAsString);
//patter fuer die Identifizierung der Diagnosen (key's im map)
Pattern pattern1 = Pattern.compile(".*[:]");
//pattern fuer die Identifizierung der entsprechenden Absatze (values's im map)
Pattern pattern2 = Pattern.compile("[:]+.*");
// [A-Z|a-z| |.|,|ä|ö|ü|Ä|Ü|Ö|ß|\\d|{|}|[|]|
//matcher fuer erste pattern
Matcher m1 = pattern1.matcher(arztBriefAsString);
//matcher fuer zweite pattern
Matcher m2 = pattern2.matcher(arztBriefAsString);
Map<String, String> map = new HashMap<String, String>();
while (m1.find() && m2.find()) {
System.out.println("Key: " + m1.group());
System.out.println("Value: " + m2.group());
map.put(m1.group(), m2.group());
}
for(Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment