public GlobalDocumentDataBuilderUserControl()
        {
            InitializeComponent();

            var serviceProvider = DependencyResolver.GetServices().BuildServiceProvider();

            documentDataBusinessLogic = serviceProvider.GetService <IDocumentDataBusinessLogic>();
            featureSelector           = serviceProvider.GetService <IFeatureSelector>();
            topicPredictor            = serviceProvider.GetService <ITopicPredictor>();

            documentDataDisplayUserControl = new DocumentDataDisplayUserControl();
            panelDocumentDataDisplayUserControl.Controls.Add(documentDataDisplayUserControl);

            UpdateRunButtonEnabledProperty();
            SetStatusLabel("Waiting for input", Color.DodgerBlue);

            filepathsToUseForDocumentData = new List <string>();
        }
Beispiel #2
0
        public List <ClassEvaluationResult> EvaluateTopicPredictor(ITopicPredictor topicPredictor, List <DocumentData> documentDataList)
        {
            ArgumentValidator.ValidateObject(topicPredictor);
            ArgumentValidator.ValidateNotEmptyList(documentDataList);

            var    evaluationResults     = new Dictionary <string, ClassEvaluationResult>();
            double total                 = documentDataList.Count;
            var    successfullyPredicted = 0;

            var distinctTopics = documentDataList.ToDatasetRepresentation().GetAllDistinctTopics();

            foreach (var topic in distinctTopics)
            {
                evaluationResults.Add(topic, new ClassEvaluationResult());
            }

            var predicted = new int[documentDataList.Count(x => x.Topics.Count > 0)];
            var expected  = new int[documentDataList.Count(x => x.Topics.Count > 0)];

            foreach (var documentData in documentDataList.Where(x => x.Topics.Count > 0))
            {
                var predictedTopic = topicPredictor.PredictTopic(documentData);
                var expectedTopic  = documentData.Topics[0];

                evaluationResults.TryGetValue(predictedTopic, out var resultForPredictedTopic);
                evaluationResults.TryGetValue(expectedTopic, out var resultForExpectedTopic);

                if (resultForPredictedTopic == null && resultForExpectedTopic == null)
                {
                    continue;
                }

                if (predictedTopic != expectedTopic)
                {
                    if (resultForPredictedTopic != null)
                    {
                        resultForPredictedTopic.FalsePositives++;
                    }

                    if (resultForExpectedTopic != null)
                    {
                        resultForExpectedTopic.FalseNegatives++;
                    }
                }
                else
                {
                    if (resultForPredictedTopic != null)
                    {
                        resultForPredictedTopic.TruePositives++;
                    }
                }

                var remainingTopics = distinctTopics
                                      .Where(x => x != predictedTopic && x != expectedTopic)
                                      .ToList();

                foreach (var remainingTopic in remainingTopics)
                {
                    if (evaluationResults.TryGetValue(remainingTopic, out var resultForRemainingTopic))
                    {
                        resultForRemainingTopic.TrueNegatives++;
                    }
                }
            }

            return(evaluationResults.Values.ToList());
        }