Commit cbfed25a authored by Julia Fischer's avatar Julia Fischer

Splitter2

parent 4258ac85
Pipeline #2492 skipped
package Ueb6;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AbsatzSplitter2 {
public static final String PATH = "Arztbrief2.txt";
public static void main(String[] args) throws IOException {
// brief wird in einem String umgewandelt
String arztBriefAsString = new String(Files.readAllBytes(Paths.get(PATH)));
// System.out.println(arztBriefAsString);
Map<String, String> map = new HashMap<String, String>();
// patter fuer die Identifizierung der Diagnosen (key's im map)
Pattern pattern1 = Pattern.compile("\n+.*[:]");
String[] splittedLetter = arztBriefAsString.split("(?=\n+.*[:])");
for (String retval : splittedLetter) {
Matcher m1 = pattern1.matcher(retval);
String da[] = retval.split(":", 2);
while (m1.find()) {
System.out.println("Key: " + da[0]);
System.out.println("Value: " + da[1]);
map.put(da[0], da[1]);
}
}
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