Exemple #1
0
        public string AnalyzeScores(string localizationCode, string messages)
        {
            JsonSerializer serializer = new JsonSerializer();
            TextReader reader = new StringReader(messages);
            JArray jArray = (JArray)serializer.Deserialize(reader, typeof(JArray));

            JArray scoreResults = new JArray();

            for (int index = 0; index < jArray.Count; index++ )
            {
                JToken entry = jArray[index];
                IMessage message = new Message
                {
                     Content = new StringBuilder( entry["text"].ToString()),
                     Metadata = new StringBuilder(entry.ToString())
                };

                double score =  this.AnalyzeScore(localizationCode, message);

                entry["Score"] = score;

                scoreResults.Add(entry);
            }

            TextWriter writer = new StringWriter();

            serializer.Serialize(writer, scoreResults);

            string mergedJsonResult = writer.ToString();

            return mergedJsonResult;
        }
        public double GetMessageScore(string localizationCode, string message)
        {
            IMessage messageEntity = new Message
            {
                Content = new StringBuilder(message)
            };

            double score = ExecutionEngine.GetInstance().AnalyzeScore(localizationCode, messageEntity);

            return score;
        }
        public void TestAnalyzeScore()
        {
            IMessageVerifierAlgorithm algorithm = new SentimentVerifierAlgorithm();
            ILocalization localization = new  En_Us_Localization();

            ExecutionEngine.GetInstance().RegisterAnalyzer(localization, algorithm);

            string localizationCode = localization.LocalizationCode;
            IMessage message = new Message
            {
                 Content = new StringBuilder("I am sad")
            };

            double score = ExecutionEngine.GetInstance().AnalyzeScore(localizationCode, message);

            Assert.AreEqual(-0.857924, score);
        }