Last active
August 29, 2015 14:18
-
-
Save ralfw/42b0071e49ce12c9ecd4 to your computer and use it in GitHub Desktop.
Spellchecker 20150408
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
namespace spellchecker | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
var dateipfade = InputReader.Input_Params_lesen (args); | |
var text = FileIO.Textdatei_lesen (dateipfade.Item1); | |
var lex = FileIO.Lexikon_lesen (dateipfade.Item2); | |
Spellchecker.Prüfen (text, lex, | |
UI.Fehler_ausgeben); | |
} | |
} | |
} |
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
using System; | |
namespace spellchecker | |
{ | |
class Spellchecker { | |
public static void Prüfen(string[] zeilen, Lexikon lex, Action<Fehlerzeile> beiFehler) { | |
Parsen (zeilen, | |
(Zeile, wörter) => lex.Nachschlagen(wörter, | |
fehlerhafteWörter => { | |
var fehlerzeile = new Fehlerzeile{ Zeile = Zeile, Fehler = fehlerhafteWörter }; | |
beiFehler(fehlerzeile); | |
}) | |
); | |
} | |
private static void Parsen(string[] zeilen, Action<Zeile,string[]> proZeile) { | |
for (var i = 0; i < zeilen.Length; i++) { | |
var zeile = new Zeile{ Zeilennummer = i+1, Text = zeilen[i]}; | |
var wörter = zeile.Text.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries); | |
proZeile (zeile, wörter); | |
} | |
} | |
} | |
} |
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
using System; | |
using System.IO; | |
namespace spellchecker | |
{ | |
class InputReader { | |
public static Tuple<string,string> Input_Params_lesen(string[] args) { | |
return new Tuple<string, string> (args [0], args [1]); | |
} | |
} | |
class FileIO { | |
public static string[] Textdatei_lesen(string pfad) { | |
return File.ReadAllLines (pfad); | |
} | |
public static Lexikon Lexikon_lesen(string pfad) { | |
var wörter = File.ReadAllLines (pfad); | |
return new Lexikon (wörter); | |
} | |
} | |
class UI { | |
public static void Fehler_ausgeben(Fehlerzeile fehlerzeile) { | |
Console.WriteLine ("{0} - {1}", fehlerzeile.Zeile.Zeilennummer, fehlerzeile.Zeile.Text); | |
for (var i = 0; i < fehlerzeile.Fehler.Length; i++) | |
Console.WriteLine (" {0}: {1}", i+1, fehlerzeile.Fehler [i]); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace spellchecker | |
{ | |
class Lexikon { | |
private HashSet<string> index; | |
public Lexikon(IEnumerable<string> wörter) { | |
this.index = new HashSet<string> (wörter); | |
} | |
public void Nachschlagen(IEnumerable<string> wörter, Action<string[]> beiUnbekannt) { | |
var unbekannteWörter = wörter.Where (w => !this.index.Contains (w)).ToArray (); | |
if (unbekannteWörter.Length > 0) | |
beiUnbekannt (unbekannteWörter); | |
} | |
} | |
} |
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
namespace spellchecker | |
{ | |
struct Zeile { | |
public int Zeilennummer; | |
public string Text; | |
} | |
class Fehlerzeile { | |
public Zeile Zeile; | |
public string[] Fehler; | |
} | |
} |
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
es | |
blaut | |
die | |
nacht | |
sternlein | |
blinken | |
schneeflöcklein | |
leis | |
herniedersinken | |
auf | |
edeltännleins | |
grünem | |
wipfel | |
häuft | |
sich | |
ein | |
kleiner | |
weißer | |
zipfel |
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
es blau die nacht | |
die strnlein blnken | |
schneeflöcklein leis herniedersinken | |
auf edeltaennleins grünem wipfel | |
häuft sch ein kleiner weisser tsimpfel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment