50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlubbFish.Iot.Snips.DataInputs;
|
|
using BlubbFish.Utils.IoT.Connector;
|
|
using LitJson;
|
|
|
|
namespace BlubbFish.Iot.Snips.Intents {
|
|
abstract public class AEspIntent : AIntent {
|
|
protected readonly Dictionary<String, EnvEsp8266> esps;
|
|
protected String espid = null;
|
|
|
|
protected AEspIntent(JsonData data, ABackend snips, Dictionary<String, EnvEsp8266> esps) : base(data, snips) => this.esps = esps;
|
|
|
|
public override void Parse() {
|
|
String ort = this.slots["ort"];
|
|
String mort = "ESP8266-" + ort;
|
|
Dictionary<String, Double> goal = new Dictionary<String, Double>();
|
|
foreach(KeyValuePair<String, EnvEsp8266> item in this.esps) {
|
|
goal.Add(item.Key, Helper.Texthelper.CalculateSimilarity(mort.ToLower(), item.Key.ToLower()));
|
|
}
|
|
if(goal.Count > 0) {
|
|
KeyValuePair<String, Double> t = goal.First();
|
|
foreach(KeyValuePair<String, Double> move in goal) {
|
|
if(move.Value > t.Value) {
|
|
t = move;
|
|
}
|
|
}
|
|
this.espid = t.Key;
|
|
}
|
|
}
|
|
|
|
protected String GetSpeakName(String name) {
|
|
String ort = name.Substring(8);
|
|
switch(ort) {
|
|
case "Bad":
|
|
case "Dach":
|
|
return "im " + ort;
|
|
case "Arbeit":
|
|
return "im " + ort + "szimmer";
|
|
case "Wohn":
|
|
return "im " + ort + "zimmer";
|
|
case "Kueche":
|
|
return "in der Küche";
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
}
|