Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace SMS_Analyse
- {
- public enum Worttyp
- {
- Nomen,
- Verb,
- Adjektiv,
- Artikel
- }
- public static class Wortliste
- {
- public static IEnumerable<string> ReadFromFile(string path) {
- try {
- return File.ReadAllLines(path);
- } catch (Exception) {
- throw;
- }
- }
- }
- sealed class Matrix
- {
- private static Matrix INSTANCE = null;
- public static Matrix Instance {
- get {
- if (INSTANCE == null)
- INSTANCE = new Matrix();
- return INSTANCE;
- }
- }
- private readonly Dictionary<Worttyp, Dictionary<Worttyp, bool>> _matrix;
- private Matrix()
- {
- _matrix = new Dictionary<Worttyp, Dictionary<Worttyp, bool>>();
- Initialize();
- }
- private void Initialize()
- {
- var values = (Worttyp[])Enum.GetValues(typeof(Worttyp));
- foreach (Worttyp outer in values)
- {
- _matrix.Add(outer, new Dictionary<Worttyp, bool>());
- foreach (Worttyp inner in values)
- {
- _matrix[outer].Add(inner, false);
- }
- }
- }
- public bool this[Worttyp von, Worttyp nach] {
- get {
- return _matrix[von][nach];
- }
- set {
- _matrix[von][nach] = value;
- }
- }
- }
- class Program
- {
- static readonly Dictionary<string, Worttyp> DIC = new Dictionary<string, Worttyp>();
- static void AddRange(IEnumerable<string> wörter, Worttyp typ)
- {
- foreach (string wort in wörter)
- {
- DIC[wort] = typ;
- }
- }
- static void AddRange(string path, Worttyp typ)
- {
- AddRange(Wortliste.ReadFromFile(path), typ);
- }
- static void Main(string[] args)
- {
- var am = Matrix.Instance;
- am[Worttyp.Artikel, Worttyp.Nomen] = true;
- am[Worttyp.Artikel, Worttyp.Adjektiv] = true;
- am[Worttyp.Nomen, Worttyp.Verb] = true;
- am[Worttyp.Nomen, Worttyp.Nomen] = true;
- am[Worttyp.Adjektiv, Worttyp.Adjektiv] = true;
- am[Worttyp.Adjektiv, Worttyp.Verb] = true;
- am[Worttyp.Verb, Worttyp.Nomen] = true;
- AddRange(@"Listen\Nomen.lst", Worttyp.Nomen);
- AddRange(@"Listen\Adjektive.lst", Worttyp.Adjektiv);
- AddRange(@"Listen\Verben.lst", Worttyp.Verb);
- AddRange(@"Listen\Artikel.lst", Worttyp.Artikel);
- string satz = "Blau, blau, blau blüht der Enzian";
- //string satz = "Der Blau der Grün Enzian, rote Rosen";
- satz = satz.Replace(",", "");
- var satzArr = satz.Split(' ');
- var test = new List<Worttyp>();
- satzArr.ToList().ForEach(w => test.Add(DIC[w]));
- var ergebnis = new bool[test.Count() - 1];
- for (int i = 0; i < ergebnis.Length; i++)
- {
- ergebnis[i] = am[test[i], test[i + 1]];
- }
- bool found = false;
- for (int i = 0; i < ergebnis.Length; i++) {
- if (ergebnis[i] &&
- (DIC[satzArr[i]] == Worttyp.Nomen ||
- DIC[satzArr[i + 1]] == Worttyp.Nomen)) {
- found = true;
- Console.WriteLine("{0} {1}", satzArr[i], satzArr[i + 1]);
- }
- }
- if (!found) {
- foreach (var w in satzArr) {
- if (DIC[w] == Worttyp.Nomen) {
- Console.WriteLine(w);
- }
- }
- }
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement