public SentimentAnnotator(string name, Properties props)
 {
     this.modelPath = props.GetProperty(name + ".model", DefaultModel);
     if (modelPath == null)
     {
         throw new ArgumentException("No model specified for Sentiment annotator");
     }
     this.model = SentimentModel.LoadSerialized(modelPath);
 }
Esempio n. 2
0
        public static async Task <SentimentPrediction> PredictSentimentAsync(SentimentModel predictData)
        {
            if (MLTraining.SentimentModel == null)
            {
                MLTraining.SentimentModel = await MLTraining.SentimentTrainAsync();
            }
            var prediction = MLTraining.SentimentModel.Predict(predictData);

            return(prediction);
        }
        public IEnumerator TestCreateSentimentModel()
        {
            Log.Debug("NaturalLanguageUnderstandingServiceV1IntegrationTests", "Attempting to CreateSentimentModel...");
            SentimentModel createSentimentModelResponse = null;
            string         modelId      = "";
            MemoryStream   trainingData = new MemoryStream(ASCIIEncoding.Default.GetBytes("This is a mock file."));

            service.CreateSentimentModel(
                callback: (DetailedResponse <SentimentModel> response, IBMError error) =>
            {
                Log.Debug("NaturalLanguageUnderstandingServiceV1IntegrationTests", "CreateSentimentModel result: {0}", response.Response);
                createSentimentModelResponse = response.Result;
                Assert.IsNotNull(createSentimentModelResponse);
                Assert.AreEqual(createSentimentModelResponse.Name, "testString");
                Assert.AreEqual(createSentimentModelResponse.Language, "en");
                Assert.AreEqual(createSentimentModelResponse.Description, "testString");
                Assert.AreEqual(createSentimentModelResponse.ModelVersion, "testString");
                Assert.AreEqual(createSentimentModelResponse.VersionDescription, "testString");
                Assert.IsNull(error);

                modelId = createSentimentModelResponse.ModelId;
            },
                language: "en",
                trainingData: trainingData,
                name: "testString",
                description: "testString",
                modelVersion: "testString",
                versionDescription: "testString"
                );

            while (createSentimentModelResponse == null)
            {
                yield return(null);
            }

            DeleteModelResults deleteModelResults = null;

            service.DeleteSentimentModel(
                callback: (DetailedResponse <DeleteModelResults> response, IBMError error) =>
            {
                Log.Debug("NaturalLanguageUnderstandingServiceV1IntegrationTests", "DeleteSentimentModel result: {0}", response.Response);
                deleteModelResults = response.Result;
                Assert.IsNull(error);
            },
                modelId: modelId
                );

            while (deleteModelResults == null)
            {
                yield return(null);
            }
        }
Esempio n. 4
0
        private static void SentimentTest()
        {
            var builder = new SentimentModel();

            var dataView = builder.LoadFromText("comment.tsv", allowQuoting: true);

            builder.Train(dataView);

            //var inputs = new List<SentimentData>();

            while (true)
            {
                var word = Console.ReadLine();
                if (string.Equals(word, "exit", StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }

                //inputs.Add(new SentimentData
                //{
                //    SentimentText = word
                //});
                //if (inputs.Count < 3) continue;

                //var results = builder.Predict(inputs);
                //foreach (var result in results)
                //{
                //    Console.WriteLine($"Text\t\t:{result.SentimentText}");

                //    Console.WriteLine($"Prediction\t:{result.Prediction}");
                //    Console.WriteLine($"Probability\t:{result.Probability}");
                //    Console.WriteLine($"Score\t\t:{result.Score}");
                //}
                //inputs.Clear();

                var result = builder.Predict(new SentimentData
                {
                    SentimentText = word
                });

                Console.WriteLine($"Text\t\t:{result.SentimentText}");

                Console.WriteLine($"Prediction\t:{result.Prediction}");
                Console.WriteLine($"Probability\t:{result.Probability}");
                Console.WriteLine($"Score\t\t:{result.Score}");
            }
        }
Esempio n. 5
0
        private static List <SentimentModel> UseModelWithSingleItem(MLContext mlContext, ITransformer model, List <SentimentData> dataModelList)
        {
            var sentimentDataResult = new List <SentimentModel>();
            PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine <SentimentData, SentimentPrediction>(model);

            foreach (var dataModel in dataModelList)
            {
                var resultPrediction   = predictionFunction.Predict(dataModel);
                var tempSentimentModel = new SentimentModel
                {
                    Text           = resultPrediction.SentimentText,
                    Location       = resultPrediction.Location,
                    SentimentValue = resultPrediction.Probability
                };
                sentimentDataResult.Add(tempSentimentModel);
            }
            return(sentimentDataResult);
        }
Esempio n. 6
0
        public IHttpActionResult GetSentimentVanPersoon(string id)
        {
            int intID = -1;

            try
            {
                intID = int.Parse(id);
            }
            catch
            {
                return(NotFound());
            }
            List <Bericht> berichts = berichtMng.GetBerichten(b => b.Personen.FirstOrDefault(p => p.ID == intID) != null).ToList();

            SentimentModel model = new SentimentModel()
            {
                Naam          = berichtMng.GetPersoon(intID).Naam,
                Objectiviteit = berichts.Average(b => b.Objectiviteit),
                Polariteit    = berichts.Average(b => b.Polariteit)
            };

            return(Ok(model));
        }
Esempio n. 7
0
 public IndexModel(ILogger <IndexModel> logger, SentimentModel sentimentModel)
 {
     _logger         = logger;
     _sentimentModel = sentimentModel;
 }