/******************************************************** * CLASS METHODS *********************************************************/ /// <summary> /// If we don't have this sentiment data, add it to our list t /// </summary> /// <param name="type">Type of Sentiment Data required</param> /// <param name="symbol">Symbol of the requested sentiment data.</param> public void Add(SentimentDataType type, string symbol) { //Convert it all to uper case symbol = symbol.ToUpper(); if (SentimentData.ContainsKey(type)) { if (SentimentData[type].Contains(symbol)) { return; } else { SentimentData[type].Add(symbol); _totalCount++; _sentimentCount++; } } else { //Add a new type of sentiment: SentimentData.Add(type, new List <string>()); SentimentData[type].Add(symbol); _totalCount++; _sentimentCount++; } }
/// <summary> /// Add this sentiment-data to list of requested data streams for events: /// </summary> /// <param name="type">Enum SentimentDataType: Estimize, Stockpulse</param> /// <param name="symbol">String symbol of asset we'd like sentiment data</param> public void AddSentimentData(SentimentDataType type, string symbol) { try { if (!_locked) { symbol = symbol.ToUpper(); DataManager.Add(type, symbol); } else { throw new Exception("Algorithm.AddMetaData(): Modify meta-data requested while algorithm running."); } } catch (Exception err) { Error("Algorithm.AddMetaData(): " + err.Message); } }
/******************************************************** * CLASS METHODS *********************************************************/ /// <summary> /// If we don't have this sentiment data, add it to our list t /// </summary> /// <param name="type">Type of Sentiment Data required</param> /// <param name="symbol">Symbol of the requested sentiment data.</param> public void Add(SentimentDataType type, string symbol) { //Convert it all to uper case symbol = symbol.ToUpper(); if (SentimentData.ContainsKey(type)) { if (SentimentData[type].Contains(symbol)) { return; } else { SentimentData[type].Add(symbol); _totalCount++; _sentimentCount++; } } else { //Add a new type of sentiment: SentimentData.Add(type, new List<string>()); SentimentData[type].Add(symbol); _totalCount++; _sentimentCount++; } }
public static List <SentimentDataType> readFile(string filePath) { try { List <SentimentDataType> dataList = new List <SentimentDataType>(); // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(filePath)) { string lineRead = sr.ReadLine(); float resualt; while (lineRead != null) { if (lineRead.Contains("product/productId")) { SentimentDataType temp = new SentimentDataType(); temp.productID = lineRead.Split(':')[1]; dataList.Add(temp); } else if (lineRead.Contains("review/userId")) { dataList.LastOrDefault().userID = lineRead.Split(':')[1]; } else if (lineRead.Contains("review/profileName")) { dataList.LastOrDefault().profileName = lineRead.Split(':')[1]; } else if (lineRead.Contains("review/helpfulness")) { string temp = lineRead.Split(':')[1]; dataList.LastOrDefault().helpfullness = float.Parse(temp.Split('/')[0]); dataList.LastOrDefault().helpfullness /= float.Parse(temp.Split('/')[1]); } else if (lineRead.Contains("review/score") && float.TryParse(lineRead.Split(':')[1], out resualt)) { dataList.LastOrDefault().score = resualt; } else if (lineRead.Contains("review/time")) { dataList.LastOrDefault().time = Int32.Parse(lineRead.Split(':')[1]); } else if (lineRead.Contains("review/summary")) { dataList.LastOrDefault().summary = lineRead.Split(':')[1]; } else if (lineRead.Contains("review/text")) { dataList.LastOrDefault().text = lineRead.Split(':')[1]; } lineRead = sr.ReadLine(); } } return(dataList); } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); return(null); } }