private void PredictParagraphs()
        {
            Receive <PredictParagraphsMsg>((x) =>
            {
                using (Py.GIL())
                {
                    var path = System.IO.Path.GetFullPath("...\\...\\...\\Nlp\\");
                    dynamic pythonDataLoader         = Py.Import("data_loader");
                    var paragraphs                   = pythonDataLoader.split_into_paragraphs(pythonDataLoader.read_pdf_to_text(path + x.FileName));
                    dynamic pythonDataClassification = Py.Import("data_classifiers");

                    var converter = new PyConverter();
                    converter.AddListType();
                    converter.Add(new Int32Type());
                    converter.Add(new Int64Type());
                    converter.Add(new DoubleType());
                    converter.Add(new FloatType());
                    converter.Add(new StringType());
                    var predicted_paragraphs = pythonDataClassification.predict_arguments(trainedModel, paragraphs);
                    var testLabels           = pythonDataLoader.read_labels_of_paragraphs(path + x.TrainingDataName);
                    var predictedLabels      = pythonDataLoader.get_labels(predicted_paragraphs);
                    pythonDataClassification.display_metrics(testLabels, predictedLabels);
                    List <object> positive_paragraphs = converter.ToClr(pythonDataClassification.get_positive_paragraphs(predicted_paragraphs));
                    List <object> negative_paragraphs = converter.ToClr(pythonDataClassification.get_negative_paragraphs(predicted_paragraphs));

                    judge.Tell(new ReturnParagraphsMsg(positive_paragraphs, negative_paragraphs));
                }
            });
        }
 public PyConverter NewMyListConverter()
 {
     using (Py.GIL())
     {
         var converter = new PyConverter();  //create a instance of PyConverter
         converter.AddListType();
         converter.Add(new StringType());
         converter.Add(new Int64Type());
         converter.Add(new Int32Type());
         converter.Add(new FloatType());
         converter.Add(new DoubleType());
         return(converter);
     }
 }
        private void TellRelatedParagraphs()
        {
            Receive <RelatedArgumentsQueryMsg>((x) =>
            {
                using (Py.GIL())
                {
                    threshold = 0.05;
                    dynamic pythonDataProcessing = Py.Import("data_processing");
                    var converter = new PyConverter();
                    converter.AddListType();
                    converter.Add(new DoubleType());
                    var argument = x.BlacklistedArguments.First();
                    List <String> paragraphsLeft = positiveParagraphs.Except(x.BlacklistedArguments).ToList();
                    var valueMap   = new Dictionary <int, Double>();
                    var resultList = new List <string>();
                    foreach (var paragraph in paragraphsLeft)
                    {
                        var ngramEvaluation       = pythonDataProcessing.evaluate_sentence(argument, paragraph, 2);
                        List <object> ngramScores = converter.ToClr(ngramEvaluation);
                        var value = 0.0;
                        foreach (var score in ngramScores)
                        {
                            value += (double)score;
                        }
                        valueMap.Add(valueMap.Count, value);
                    }
                    Dictionary <int, Double> sortedValueMap = (valueMap.OrderByDescending(y => y.Value)).ToDictionary(y => y.Key, y => y.Value);

                    foreach (var val in sortedValueMap)
                    {
                        if (val.Value > threshold)
                        {
                            resultList.Add(paragraphsLeft.ElementAt(val.Key));
                        }
                        else
                        {
                            break;
                        }
                        if (resultList.Count > 1)
                        {
                            break;
                        }
                    }

                    x.QuerySender.Tell(new RelatedArgumentsDefenderResponseMsg(resultList));
                }
            });
        }
示例#4
0
        public PyConverter GetConverter()
        {
            //using (Py.GIL())
            //{
            var converter = new PyConverter();

            converter.AddListType();
            converter.Add(new StringType());
            converter.Add(new Int64Type());
            converter.Add(new Int32Type());
            converter.Add(new FloatType());
            converter.Add(new DoubleType());
            converter.AddDictType <object, object>();
            return(converter);

            //}
        }