private static void ProcessPost(Post post) { var json = new AlchemyAPI.AlchemyAPI().TextGetTextSentiment(post.Text); var res = json.FromJson<RequestRes>(); if (res.docSentiment != null) { post.Sentiment = res.docSentiment.score; if (post.Sentiment < 0) { post.SapID = SapConnection.Con.CreateLead(string.Format("{0} wrote on {1}: {2}", post.FromUserName, (AccountType)post.Type, post.Text)); //if (!string.IsNullOrEmpty(post.SapID)) // SapConnection.Con.CreateSubscription(post.SapID); } } }
public List <string> GenerateTags(string content) { // Create an AlchemyAPI object. var alchemyObj = new AlchemyAPI.AlchemyAPI(); // Load an API key from disk. alchemyObj.SetAPIKey("2d5cf3e2b75b88de5e96c37d87915f3ec0edb483"); string textGetRankedTaxonomy = alchemyObj.TextGetRankedKeywords(content); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(textGetRankedTaxonomy); XmlNodeList keyWordNodes = xmlDocument.GetElementsByTagName("text"); return((from XmlNode keyWordNode in keyWordNodes select keyWordNode.InnerText).ToList()); }
public static void ExtractEntities(int tweetId, string text, Repository tycheRepo) { AlchemyAPI.AlchemyAPI alchemyObj = new AlchemyAPI.AlchemyAPI(); alchemyObj.SetAPIKey(ConfigurationManager.AppSettings["AlchemyAPIKey"]); string xml; XDocument xdoc; try { xml = alchemyObj.TextGetRankedNamedEntities(text); } catch { xml = ""; } if (xml != "") { xdoc = XDocument.Load(new StringReader(xml)); foreach (XElement e in xdoc.Descendants("entity")) { interaction_entity entity = new interaction_entity(); entity.interaction_id = tweetId; entity.entity = e.Element("text").Value; entity.entity_count = int.Parse(e.Element("count").Value); entity.entity_relevance = decimal.Parse(e.Element("relevance").Value); entity.entity_sentiment = e.Element("sentiment").Element("type").Value; if (e.Element("sentiment").Element("score") != null) entity.entity_sentiment_score = decimal.Parse(e.Element("sentiment").Element("score").Value); else entity.entity_sentiment_score = 0; tycheRepo.Add(entity); } tycheRepo.UpdateLastInteractionProcessed(tweetId, InteractionProcessedAction.Entity); tycheRepo.Save(); Thread.Sleep(12); } }
public static void ExtractKeywordsFromUrl(interaction_url interaction_url, string url, Repository tycheRepo) { AlchemyAPI.AlchemyAPI alchemyObj = new AlchemyAPI.AlchemyAPI(); alchemyObj.SetAPIKey(ConfigurationManager.AppSettings["AlchemyAPIKey"]); string xml; XDocument xdoc; try { xml = alchemyObj.URLGetRankedKeywords(url); } catch { xml = ""; } if (xml != "") { xdoc = XDocument.Load(new StringReader(xml)); foreach (XElement e in xdoc.Descendants("keyword")) { interaction_url_keyword keyword = new interaction_url_keyword(); keyword.interaction_url_id = interaction_url.id; keyword.keyword = e.Element("text").Value; keyword.keyword_count = 1; keyword.keyword_relevance = decimal.Parse(e.Element("relevance").Value); keyword.keyword_sentiment = e.Element("sentiment").Element("type").Value; if (e.Element("sentiment").Element("score") != null) keyword.keyword_sentiment_score = decimal.Parse(e.Element("sentiment").Element("score").Value); else keyword.keyword_sentiment_score = 0; tycheRepo.Add(keyword); } tycheRepo.Save(); Thread.Sleep(12); } }