| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace System.Speech {
- public class SpeechFormat {
- public static string Pronounce(string s) {
- // TODO
- s = s.Replace("0815", "0 8 15");
- return s;
- }
- public static string Regex_PersonReplace(Match m) {
- // TODO
- return "Unbekannt";
- }
- public static string Format(string s) {
- if (s.Contains("{now.")) {
- s = s.Replace("{now.hour}", DateTime.Now.Hour.ToString());
- s = s.Replace("{now.h}", DateTime.Now.Hour.ToString());
- s = s.Replace("{now.minute}", DateTime.Now.Minute.ToString());
- s = s.Replace("{now.i}", DateTime.Now.Minute.ToString());
- s = s.Replace("{now.second}", DateTime.Now.Second.ToString());
- s = s.Replace("{now.s}", DateTime.Now.Second.ToString());
- s = s.Replace("{now.day}", DateTime.Now.Day.ToString());
- s = s.Replace("{now.d}", DateTime.Now.Day.ToString());
- s = s.Replace("{now.month}", DateTime.Now.Month.ToString());
- s = s.Replace("{now.monthname}", getMonthName(DateTime.Now.Month));
- s = s.Replace("{now.m}", DateTime.Now.Month.ToString());
- s = s.Replace("{now.M}", getMonthName(DateTime.Now.Month));
- s = s.Replace("{now.year}", DateTime.Now.Year.ToString());
- s = s.Replace("{now.y}", DateTime.Now.Year.ToString());
- s = s.Replace("{now.w}", DayOfWeek(DateTime.Now.DayOfWeek));
- s = s.Replace("{now.datetime}", DayOfWeek(DateTime.Now.DayOfWeek)+", den " + DateTime.Now.Day.ToString() + "ten "+ getMonthName(DateTime.Now.Month)+" "+ DateTime.Now.Year.ToString() + " " + TimeFormat(DateTime.Now));
- s = s.Replace("{now.time}", TimeFormat(DateTime.Now));
- s = s.Replace("{now.date}", DayOfWeek(DateTime.Now.DayOfWeek) + ", den " + DateTime.Now.Day.ToString() + "ten " + getMonthName(DateTime.Now.Month) + " " + DateTime.Now.Year.ToString());
- }
- if (s.Contains("{person.")) {
- // TODO: Connect to addressbook, fetch data of person.(.+) and replace
- // Schema: {person.Patrick.phone}, {person.Patrick.Name}, ...
- s = Regex.Replace(s, "\\{person\\.(?<arg1>[.+?]+)\\.(?<arg2>.+?)(?:\\.(?<arg3>.+?))?\\}", Regex_PersonReplace);
- }
- if (s.Contains("{web")) {
- // TODO: Fetch web Data and return the value of a tag/id/class
- // Schema: To be decided
- }
- if (s.Contains("{system.")) {
- // TODO: System Variablen
- }
- if(s.Contains(":")) {
- s = System.Text.RegularExpressions.Regex.Replace(s, "(?<h>(?:0|1|2)?[0-9])\\:(?<m>[0-5][0-9])(?:\\:(?<s>[0-5][0-9]))?[\\s\\t\\n\\r]*(h|uhr)", "${h} Uhr ${m}", Text.RegularExpressions.RegexOptions.IgnoreCase | Text.RegularExpressions.RegexOptions.ExplicitCapture);
- s = System.Text.RegularExpressions.Regex.Replace(s, "(?<v1>[0-9]+)\\:(?<v2>[0-9]+)", "${v1} zu ${v2}", Text.RegularExpressions.RegexOptions.ExplicitCapture);
- }
- return s;
- }
- public static string getMonthName(int m) {
- switch (m) {
- case 1: return "Januar";
- case 2: return "Februar";
- case 3: return "März";
- case 4: return "April";
- case 5: return "Mai";
- case 6: return "Juni";
- case 7: return "Juli";
- case 8: return "August";
- case 9: return "September";
- case 10: return "Oktober";
- case 11: return "November";
- case 12: return "Dezember";
- }
- return "";
- }
- public static string DayOfWeek(DayOfWeek d) {
- switch (d) {
- case System.DayOfWeek.Monday: return "Montag";
- case System.DayOfWeek.Tuesday: return "Dienstag";
- case System.DayOfWeek.Wednesday: return "Mittwoch";
- case System.DayOfWeek.Thursday: return "Donnerstag";
- case System.DayOfWeek.Friday: return "Freitag";
- case System.DayOfWeek.Saturday: return "Samstag";
- case System.DayOfWeek.Sunday: return "Sonntag";
- }
- return "";
- }
- public static string TimeFormat(DateTime dt) {
- int m = dt.Minute;
- switch (m) {
- case 0: return "Punkt " + dt.Hour + " Uhr";
- case 1: return dt.Hour + " Uhr";
- case 15: return "Viertel nach " + dt.Hour;
- case 30:
- if (dt.Hour == 11 || dt.Hour == 23) {
- return "Halb zwölf";
- } else {
- return "Halb " + ((dt.Hour % 12) + 1);
- }
- case 45:
- return "Viertel vor " + ((dt.Hour % 12) + 1);
- case 50:
- return "Zehn vor " + ((dt.Hour % 12) + 1);
- case 55:
- return "Fünf vor " + ((dt.Hour % 12) + 1);
- case 58:
- case 59:
- return "Kurz vor " + ((dt.Hour % 12) + 1);
- default:
- if (m <= 10) {
- return dt.Minute + " nach " + dt.Hour;
- }
- if(m>=50){
- return (60 - dt.Minute) + " vor " + ((dt.Hour % 12) + 1);
- }
- return dt.Hour + " Uhr " + dt.Minute;
- }
- }
- }
- }
|