コード例 #1
0
 public void OnExecutionProgress(string service, AnalysisExecutionProgressEventArgs ea)
 {
     if (ExecutionProgress != null)
     {
         ExecutionProgress(service, ea);
     }
 }
コード例 #2
0
ファイル: Form.cs プロジェクト: RavenB/SemantAPI
        private void ExecutionProgress(string service, AnalysisExecutionProgressEventArgs ea)
        {
            if (_cancelFlag)
            {
                ea.Cancel = true;
                return;
            }

            if (ea.Status == AnalysisExecutionStatus.Canceled)
            {
                MessageBox.Show(ea.Reason, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _cancelFlag = true;
                return;
            }

            if (ea.Status == AnalysisExecutionStatus.Processed || ea.Status == AnalysisExecutionStatus.Failed)
            {
                WriteDebugInfo("Got the {0} progress event from {1}. Total documents: {2}\tProcessed: {3}\tFailed:{4}", ea.Progress, service, ea.TotalDocuments, ea.ProcessedDocuments, ea.FailedDocuments);
                SetControlPropertyThreadSafe(pbMechanicalTurk, "Value", ea.Progress);
            }

            if (ea.Status == AnalysisExecutionStatus.Success)
            {
                WriteDebugInfo("All documents have been sent for processing. Sent documents: {0} Failed documents: {1}", ea.ProcessedDocuments, ea.FailedDocuments);

                bool hasComplianceScore = _documents.Any(item => item.Value.HasReferencePolarity());
                if (hasComplianceScore)
                    NormalizeResultSet(_documents);

                string outputFile = GetControlPropertyThreadSafe(tbSource, "Text") as string;
                try
                {
                    using (CsvFileWriter writter = new CsvFileWriter(outputFile))
                    {
                        List<string> columns = new List<string>();
                        columns.Add("Document ID");

                        IList<string> services = _documents.First().Value.GetServices();
                        foreach (string item in services)
                        {
                            if (item == "MechanicalTurk")
                                columns.AddRange(new List<string>()
                                {
                                    string.Format("{0} Polarity", item),
                                    string.Format("{0} Confidence Score", item)
                                });
                            else if (item == "Bitext")
                                columns.AddRange(new List<string>()
                                {
                                    string.Format("{0} Polarity", item),
                                    string.Format("{0} Average Sentiment Score", item)
                                });
                            else if (item == "Viralheat")
                                columns.AddRange(new List<string>()
                                {
                                    string.Format("{0} Polarity", item),
                                    string.Format("{0} Probability Score", item)
                                });
                            else
                                columns.AddRange(new List<string>()
                                {
                                    string.Format("{0} Polarity", item),
                                    string.Format("{0} Sentiment Score", item)
                                });
                        }

                        columns.Add("Source text");
                        writter.WriteRow(columns);

                        foreach (KeyValuePair<string, ResultSet> data in _documents)
                        {
                            columns = new List<string>();
                            columns.Add(data.Key);

                            foreach (string srvc in services)
                            {
                                ResultSet results = data.Value;
                                columns.Add(results.GetPolarity(srvc));
                                columns.Add(results.GetScore(srvc).ToString("F"));
                            }

                            columns.Add(data.Value.Source);
                            writter.WriteRow(columns);
                        }
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show("Looks like the file is in use. Close another program that locks the file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    WriteDebugInfo("IO Exception: {0}", ex.Message);
                }
                WriteDebugInfo("The output file is written!");

                SetControlPropertyThreadSafe(btClose, "Enabled", true);
                SetControlPropertyThreadSafe(btProcess, "Text", "Process");
                SetControlPropertyThreadSafe(pbMechanicalTurk, "Value", 0);
                MessageBox.Show("Analysis is done! Check the output file for results.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #3
0
ファイル: ExecutionContext.cs プロジェクト: RavenB/SemantAPI
 public void OnExecutionProgress(string service, AnalysisExecutionProgressEventArgs ea)
 {
     if (ExecutionProgress != null)
         ExecutionProgress(service, ea);
 }
コード例 #4
0
ファイル: Form.cs プロジェクト: RavenB/SemantAPI
        private void ExecutionProgress(string service, AnalysisExecutionProgressEventArgs ea)
        {
            if (_cancelFlag)
            {
                ea.Cancel = true;
                return;
            }

            if (ea.Status == AnalysisExecutionStatus.Canceled)
            {
                MessageBox.Show(ea.Reason, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                UpdateMarker(service, true);
                ea.Cancel = true;

                if (IsAnalysysDone())
                {
                    SetControlPropertyThreadSafe(btClose, "Enabled", true);
                    SetControlPropertyThreadSafe(btProcess, "Text", "Process");
                    SetControlPropertyThreadSafe(pbAlchemy, "Value", 0);
                    SetControlPropertyThreadSafe(pbRepustate, "Value", 0);
                    SetControlPropertyThreadSafe(pbChatterbox, "Value", 0);
                    SetControlPropertyThreadSafe(pbSemantria, "Value", 0);
                    SetControlPropertyThreadSafe(pbViralheat, "Value", 0);
                    SetControlPropertyThreadSafe(pbBitext, "Value", 0);
                    SetControlPropertyThreadSafe(pbSkyttle, "Value", 0);
                }

                return;
            }

            if (ea.Status == AnalysisExecutionStatus.Processed || ea.Status == AnalysisExecutionStatus.Failed)
            {
                WriteDebugInfo("Got the {0} progress event from {1}. Total documents: {2}\tProcessed: {3}\tFailed:{4}", ea.Progress, service, ea.TotalDocuments, ea.ProcessedDocuments, ea.FailedDocuments);
                switch (service)
                {
                    case "Semantria":
                        SetControlPropertyThreadSafe(pbSemantria, "Value", ea.Progress);
                        break;

                    case "Alchemy":
                        SetControlPropertyThreadSafe(pbAlchemy, "Value", ea.Progress);
                        break;

                    case "Repustate":
                        SetControlPropertyThreadSafe(pbRepustate, "Value", ea.Progress);
                        break;

                    case "Chatterbox":
                        SetControlPropertyThreadSafe(pbChatterbox, "Value", ea.Progress);
                        break;

                    case "Viralheat":
                        SetControlPropertyThreadSafe(pbViralheat, "Value", ea.Progress);
                        break;

                    case "Bitext":
                        SetControlPropertyThreadSafe(pbBitext, "Value", ea.Progress);
                        break;

                    case "Skyttle":
                        SetControlPropertyThreadSafe(pbSkyttle, "Value", ea.Progress);
                        break;
                }
            }

            if (ea.Status == AnalysisExecutionStatus.Success)
            {
                WriteDebugInfo("Analysis on {0} service has been finished. Total documents: {1}\tProcessed: {2}\tFailed:{3}", service, ea.TotalDocuments, ea.ProcessedDocuments, ea.FailedDocuments);
                UpdateMarker(service, (ea.Status == AnalysisExecutionStatus.Success) ? true : false);

                if (IsAnalysysDone())
                {
                    WriteDebugInfo("All services have finished analysis! Writing the output...");
                    string outputFile = GetControlPropertyThreadSafe(tbOutput, "Text") as string;

                    try
                    {
                        using (CsvFileWriter writter = new CsvFileWriter(outputFile))
                        {
                            List<string> columns = new List<string>();
                            columns.Add("Document ID");

                            IList<string> services = _documents.First().Value.GetServices();
                            foreach (string item in services)
                            {
                                if (item == "Bitext")
                                    columns.AddRange(new List<string>()
                                    {
                                        string.Format("{0} Polarity", item),
                                        string.Format("{0} Average Sentiment Score", item)
                                    });
                                else if (item == "Viralheat")
                                    columns.AddRange(new List<string>()
                                    {
                                        string.Format("{0} Polarity", item),
                                        string.Format("{0} Probability Score", item)
                                    });
                                else
                                    columns.AddRange(new List<string>()
                                    {
                                        string.Format("{0} Polarity", item),
                                        string.Format("{0} Sentiment Score", item)
                                    });
                            }
                            columns.Add("Source text");
                            writter.WriteRow(columns);

                            foreach (KeyValuePair<string, ResultSet> data in _documents)
                            {
                                columns = new List<string>();
                                columns.Add(data.Key);

                                foreach (string srvc in services)
                                {
                                    ResultSet results = data.Value;
                                    columns.Add(results.GetPolarity(srvc));
                                    columns.Add(results.GetScore(srvc).ToString("F"));
                                }

                                columns.Add(data.Value.Source);
                                writter.WriteRow(columns);
                            }
                        }
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("Looks like the file is in use. Close another program that locks the file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        WriteDebugInfo("IO Exception: {0}", ex.Message);
                    }
                    WriteDebugInfo("The output file is written!");

                    SetControlPropertyThreadSafe(btClose, "Enabled", true);
                    SetControlPropertyThreadSafe(btProcess, "Text", "Process");
                    SetControlPropertyThreadSafe(pbAlchemy, "Value", 0);
                    SetControlPropertyThreadSafe(pbRepustate, "Value", 0);
                    SetControlPropertyThreadSafe(pbChatterbox, "Value", 0);
                    SetControlPropertyThreadSafe(pbSemantria, "Value", 0);
                    SetControlPropertyThreadSafe(pbViralheat, "Value", 0);
                    SetControlPropertyThreadSafe(pbBitext, "Value", 0);
                    SetControlPropertyThreadSafe(pbSkyttle, "Value", 0);

                    MessageBox.Show("Analysis is done! Check the output file for results.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }