Created
March 26, 2017 23:11
-
-
Save jexp/8657188a3f714e63c9d0f83581fc3b74 to your computer and use it in GitHub Desktop.
MUD MorgenGrauen Konverter für Umlaute und Reformat auf breitere Spalten für ESpeak -> http://mg.mud.de
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| import java.io.*; | |
| public class MgEspeak { | |
| private static String[] umlaute = {"Ae", "Ä", "AE", "Ä", "ae", "ä", "Oe", "Ö", "OE", "Ö", "oe", "ö", "UE", "Ü", "Ue", "Ü", "ue", "ü" }; | |
| public static void main(String[] args) throws Exception { | |
| int spalten = args.length > 0 ? Integer.parseInt(args[0]) : 130; | |
| Set<String> ausnahmen = new HashSet(Arrays.asList("feuer","mauer")); | |
| File f = new File("ausnahmen.txt"); | |
| if (f.exists()) try (Scanner s = new Scanner(f)) { while(s.hasNext()) { ausnahmen.add(s.next().toLowerCase());}}; | |
| Scanner eingabe = new Scanner(System.in); | |
| int aktuell = 0; | |
| while (eingabe.hasNextLine()) { | |
| String zeile = eingabe.nextLine(); | |
| if (zeile == null || zeile.trim().isEmpty()) { System.out.println(); continue; } | |
| String[] woerter = zeile.split("((?<=\\W+)|(?=\\W+))"); | |
| int laenge = zeile.length(); | |
| for (int w=0;w<woerter.length;w+=2) { | |
| String wort = woerter[w]; | |
| if (!ausnahmen.contains(wort.toLowerCase())) { | |
| for (int i=0;i<umlaute.length;i+=2) wort = wort.replaceAll(umlaute[i],umlaute[i+1]); | |
| woerter[w] = wort; | |
| } | |
| } | |
| for(String wort : woerter) { | |
| if (aktuell + wort.length() > spalten) { aktuell=0;System.out.println(); } | |
| System.out.print(wort); aktuell += wort.length(); | |
| } | |
| if (woerter.length < 6 || laenge < 60 || woerter[0].charAt(0)=='[' || woerter[woerter.length-1].matches("[.!?]")) { aktuell=0;System.out.println(); } | |
| else { System.out.print(" "); aktuell++;} | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment