public LuisClass.Response GenerateText(LuisClass.RootObject lc, string SetTopic) { LuisClass.Response ResponseClass = new LuisClass.Response(); Said s = new Said(); s.DateTime = System.DateTime.Today.Date; s.PrimaryTopic = SetTopic; s.GoogleSpeechText = lc.query; s.AnswerIntent = lc.topScoringIntent.intent; db.Saids.Add(s); db.SaveChanges(); if (lc.topScoringIntent.intent == "Gengi" || lc.topScoringIntent.intent == "Stadan") { Bankinn bankinn = new Bankinn(); ResponseClass = bankinn.BankiTextResult(lc); ResponseClass.SetTopic = "Banki"; } if (lc.topScoringIntent.intent == "Fyrirsagnir" || lc.topScoringIntent.intent == "Lesa") { FrettirController frettir = new FrettirController(); ResponseClass = frettir.FrettirTextResult(lc, SetTopic); } if (lc.topScoringIntent.intent == "None") { ResponseClass.SetTopic = SetTopic; ResponseClass.TextResponse = "Geturðu tala skýrar eða endurorðað spurninguna."; } return(ResponseClass); }
private LuisClass.Response Millifaersla(LuisClass.RootObject lc) { LuisClass.Response ResponseClass = new LuisClass.Response(); try { string fornafn = ""; string eftirnafn = ""; string fjarhaed = ""; foreach (var item in lc.entities) { if (item.type == "Viðtakandi::First Name") { fornafn = item.entity; } if (item.type == "Viðtakandi::Last Name") { eftirnafn = item.entity; } if (item.type == "Fjöldi" || item.type == "Upphæð") { fjarhaed = item.entity; } } if (fornafn != "" && eftirnafn != "" && fjarhaed != "") { ResponseClass.TextResponse = "Viltu millifæra " + fjarhaed + " krónur á " + fornafn + " " + eftirnafn + "."; } else { if (fornafn == "") { ResponseClass.TextResponse = "Ég náði ekki fornafni, geturðu endurtekið beiðnina"; } if (eftirnafn == "") { ResponseClass.TextResponse = "Ég náði ekki eftirnafni, geturðu endurtekið beiðnina"; } if (fjarhaed == "") { ResponseClass.TextResponse = "Ég náði ekki fjárhæðinni, geturðu endurtekið beiðnina"; } } } catch { ResponseClass.TextResponse = "Ég náði ekki því sem þú sagðir, geturðu endurtekið spurninguna."; } ResponseClass.SetTopic = "Banki"; return(ResponseClass); }
private LuisClass.Response Gengiskallhb(LuisClass.RootObject lc) { LuisClass.Response ResponseClass = new LuisClass.Response(); try { Service1Client sc = new Service1Client(); string bref = lc.entities[0].resolution.values[0].ToString(); ResponseClass.TextResponse = GengiHlutabrefa(bref); ResponseClass.SetTopic = "Banki"; } catch { ResponseClass.TextResponse = "Geturðu endurtekið spurninguna ég náði ekki félaginu"; } return(ResponseClass); }
public LuisClass.Response Gengiskall(LuisClass.RootObject lc) { LuisClass.Response ResponseClass = new LuisClass.Response(); try { string mynt = lc.entities[0].resolution.values[0].ToString(); ResponseClass.TextResponse = GetData(mynt); ResponseClass.SetTopic = "Banki"; } catch { ResponseClass.TextResponse = "Geturðu endurtekið spurninguna ég náði ekki myntinni."; } return(ResponseClass); }
public LuisClass.Response Stadan(LuisClass.RootObject lc) { LuisClass.Response ResponseClass = new LuisClass.Response(); try { if (lc.entities[0].resolution.values[0].ToString() == "Aukakrónur") { ResponseClass.TextResponse = "Staðan á aukakrónum þínum er 2.346 krónur."; } if (lc.entities[0].resolution.values[0].ToString() == "Innlán") { ResponseClass.TextResponse = "Heildarstaða innlána er 234.239 krónur."; } if (lc.entities[0].resolution.values[0].ToString() == "Kreditkort") { ResponseClass.TextResponse = "Til ráðstöfunar á kreditkorti þínu eru 234.234 krónur."; } if (lc.entities[0].resolution.values[0].ToString() == "Veltureikningur") { ResponseClass.TextResponse = "Til ráðstöfunar á tékkareikningi er 23.320 krónur"; } if (lc.entities[0].resolution.values[0].ToString() == "Íbúðalán") { ResponseClass.TextResponse = "Heildarstaða íbúðalána þinna eru 23.323.456 krónur."; } if (lc.entities[0].resolution.values[0].ToString() == "Lífeyrissjóði") { ResponseClass.TextResponse = "Heildarstaða í Íslenska lífeyrissjóðinum er 8.963.659 krónur."; } if (lc.entities[0].resolution.values[0].ToString() == "Ógreiddir reikningar") { ResponseClass.TextResponse = "Heildarstaða ógreiddra reikninga eru 23.320 krónur."; } } catch { ResponseClass.TextResponse = "Geturðu talað skýrar eða endurorðað spurninguna."; } ResponseClass.SetTopic = "Banki"; return(ResponseClass); }
public JsonResult GetData(string GoogleText, string SetIntent) { string url = ""; string SetTopic = ""; SetTopic = SetIntent; //http://localhost:7013/Saids/GetData?GoogleText="Lestu þrjár fréttir á mbl"&SetIntent="" GoogleText = Regex.Replace(GoogleText, "\"", ""); SetTopic = Regex.Replace(SetTopic, "\"", ""); //virðist ekki vera að notfæra mér topicið. Allt í einni gervigreind. url = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/c08df70d-b17c-4619-be57-784dc9f83aac?subscription-key=ac9e91b3940344369648a914cdaa05ce&timezoneOffset=-360&q=" + GoogleText; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = WebRequestMethods.Http.Get; httpWebRequest.ContentType = "application/json; charset=utf-8"; httpWebRequest.Accept = "text/json"; httpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse(); string result = ""; LuisClass.Response answer = new LuisClass.Response(); using (Stream responseStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); result = reader.ReadToEnd(); } LuisClass.RootObject lc = JsonConvert.DeserializeObject <LuisClass.RootObject>(result); answer = GenerateText(lc, SetTopic); return(Json(answer, JsonRequestBehavior.AllowGet)); }
private LuisClass.Response Fyrirsagnir(LuisClass.RootObject lc, string SetTopic) { string responsestring = ""; LuisClass.Response ResponseClass = new LuisClass.Response(); Extract ex = new Extract(); ex = Extractfjoldi(lc); ex.topic = "Fréttir " + ex.midill; ex = ReturnURL(lc, ex); string Url = ex.URL; int fjoldi = ex.fjoldi; string midill = ex.midill; string tegund = ex.tegund; HtmlWeb web = new HtmlWeb(); web.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"; string myString = ""; //HVernig MBL er skrapaður if (midill == null) { responsestring = "Geturðu endurtekið spurninguna?"; } if (midill == "mbl") { System.Xml.XmlDocument rssXmlDoc = new XmlDocument(); // Load the RSS file from the RSS URL rssXmlDoc.Load(Url); responsestring = ""; // Parse the Items in the RSS file9 XmlNodeList rssNodes = rssXmlDoc.SelectNodes("//item//title"); string tala = ""; for (int x = 1; x <= ex.fjoldi; x++) { tala = Tolutexti(x); XmlNode item = rssNodes[x]; responsestring = responsestring + "Frétt númer " + tala + ". " + item.FirstChild.InnerText + ". "; } } if (midill == "dv") { HtmlDocument document = web.Load(Url); HtmlAgilityPack.HtmlNode[] Yfirsagnir = document.DocumentNode.SelectNodes("//div[@class=\"alphadelta\"]//article//h2").ToArray(); //Strengur hnýttur saman7 responsestring = ""; string tala = ""; for (int x = 0; x < fjoldi; x++) { tala = Tolutexti(x + 1); myString = System.Net.WebUtility.HtmlDecode(Yfirsagnir[x].InnerText); responsestring = "D V býður ekki upp á r s s streymi og því er ekki hægt að lesa fréttir."; // responsestring = responsestring + "Frétt númer " + tala + ". " + Regex.Replace(myString, @"\t|\n|\r", "") + ". "; } } if (midill == "vísir") { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; System.Net.ServicePointManager.Expect100Continue = false; HtmlDocument document = web.Load(Url); HtmlAgilityPack.HtmlNode[] Yfirsagnir = document.DocumentNode.SelectNodes("//div[@class= \"row ui-mb-xs-30\"]//div[@class= \"article-item__content\"]").ToArray(); foreach (var item in Yfirsagnir) { // item.InnerText } //Strengur hnýttur saman7 responsestring = ""; string tala = ""; for (int x = 0; x < fjoldi; x++) { tala = Tolutexti(x + 1); myString = System.Net.WebUtility.HtmlDecode(Yfirsagnir[x].InnerText); responsestring = "D V býður ekki upp á r s s streymi og því er ekki hægt að lesa fréttir."; // responsestring = responsestring + "Frétt númer " + tala + ". " + Regex.Replace(myString, @"\t|\n|\r", "") + ". "; } } if (midill == "rúv") { System.Xml.XmlDocument rssXmlDoc = new XmlDocument(); // Load the RSS file from the RSS URL rssXmlDoc.Load(Url); responsestring = ""; // Parse the Items in the RSS file9 XmlNodeList rssNodes = rssXmlDoc.GetElementsByTagName("//item//title"); string tala = ""; for (int x = 1; x <= ex.fjoldi; x++) { tala = Tolutexti(x); XmlNode item = rssNodes[x]; responsestring = responsestring + "Frétt númer " + tala + ". " + item.FirstChild.InnerText + ". "; } } ResponseClass.TextResponse = responsestring; ResponseClass.SetTopic = "Fréttir " + midill + " " + tegund; return(ResponseClass); }
private LuisClass.Response Lesa(LuisClass.RootObject lc, string SetTopic) { Extract ex = new Extract(); ex.topic = SetTopic; if (ex.topic.Contains("mbl") == true) { ex.midill = "mbl"; } if (ex.topic.Contains("dv") == true) { ex.midill = "dv"; } if (ex.topic.Contains("vísir") == true) { ex.midill = "vísir"; } if (ex.topic.Contains("rúv") == true) { ex.midill = "rúv"; } if (ex.topic.Contains("íþróttir") == true) { ex.tegund = "íþróttir"; } if (ex.topic.Contains("viðskipti") == true) { ex.tegund = "viðskipti"; } if (ex.topic.Contains("slúður") == true) { ex.tegund = "slúður"; } ex = ReturnURL(lc, ex); if (ex.URL == null) { ex.URL = ""; } LuisClass.Response r = new LuisClass.Response(); HtmlWeb web = new HtmlWeb(); HtmlDocument document = web.Load(ex.URL); string responsestring = ""; Extract ex2 = new Extract(); ex2 = Extractfjoldi(lc); ex.fjoldi = ex2.fjoldi - 1; if (SetTopic.Contains("vísir") == true) { System.Xml.XmlDocument rssXmlDoc = new XmlDocument(); ex2 = ReturnURL(lc, ex); string Url = ex2.URL; // Load the RSS file from the RSS URL rssXmlDoc.Load(Url); responsestring = ""; // Parse the Items in the RSS file9 XmlNodeList rssNodes = rssXmlDoc.SelectNodes("//item//description"); responsestring = rssNodes[ex2.fjoldi - 1].FirstChild.Value; responsestring = Regex.Replace(responsestring, @"<[^>]*>", String.Empty, RegexOptions.IgnoreCase).Trim(); } if (SetTopic.Contains("rúv") == true) { System.Xml.XmlDocument rssXmlDoc = new XmlDocument(); ex2 = ReturnURL(lc, ex); string Url = ex2.URL; // Load the RSS file from the RSS URL rssXmlDoc.Load(Url); responsestring = ""; // Parse the Items in the RSS file9 XmlNodeList rssNodes = rssXmlDoc.GetElementsByTagName("//item//description"); responsestring = rssNodes[ex2.fjoldi - 1].FirstChild.Value; } if (SetTopic.Contains("dv") == true) { responsestring = "Þú vilt ekkert vera að skoða fréttir á DV!"; } if (SetTopic.Contains("mbl") == true) { System.Xml.XmlDocument rssXmlDoc = new XmlDocument(); ex2 = ReturnURL(lc, ex); string Url = ex2.URL; // Load the RSS file from the RSS URL rssXmlDoc.Load(Url); responsestring = ""; // Parse the Items in the RSS file9 XmlNodeList rssNodes = rssXmlDoc.SelectNodes("//item//description"); responsestring = rssNodes[ex2.fjoldi - 1].FirstChild.Value; responsestring = Regex.Replace(responsestring, @"<[^>]*>", String.Empty, RegexOptions.IgnoreCase).Trim(); } r.SetTopic = SetTopic; r.TextResponse = responsestring; return(r); }