예제 #1
0
        private static bool ClearFolder(BackgroundWorker backgroundWorker)
        {
            try
            {
                FileMg.DirectoryDelete(FileMg.AutoTmtOutputFileDir, true);
                FileMg.DeleteTmtCacheFile(FileMg.AutoTmtDataFileDir);
            }
            catch
            { }

            if (Configures.GetAutoIsDeleteExistingFile())
            {
                OutputMg.OutputHeader1(backgroundWorker, "Step 0", "Clear output folder");
                OutputMg.OutputContent(backgroundWorker, "Start to clear");
                try
                {
                    FileMg.ClearAutoFolder();
                    FileMg.InitDataFolder();
                }
                catch
                {
                    OutputMg.OutputHeader1(backgroundWorker, "Failed", "Clear folder failed. Please try to run this tool as Administrator.");
                    return(false);
                }

                OutputMg.OutputContent(backgroundWorker, "Finished clearing");
            }

            return(true);
        }
예제 #2
0
 private void AddUserSearchTerms(List<string> topicTerms)
 {
     string extraSearchTermPath = Configures.GetManualSearchTermPath();
     if (!File.Exists(extraSearchTermPath))
     {
         return;
     }
     else
     {
         string[] lines = FileOperators.ReadFileLines(extraSearchTermPath);
         foreach (string line in lines)
         {
             if (line.Contains(":"))
             {
                 int commaIndex = line.IndexOf(":");
                 string compName = line.Substring(0, commaIndex);
                 if (compName.Equals(targetTopicName))
                 {
                     string extraTermStr = line.Substring(commaIndex + 1);
                     string[] extraTerms = extraTermStr.Split(',');
                     foreach (string extraTerm in extraTerms)
                     {
                         string trimmedTerm = extraTerm.Trim();
                         if (!topicTerms.Contains(trimmedTerm))
                         {
                             topicTerms.Add(trimmedTerm);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #3
0
파일: MainWindow.cs 프로젝트: lawenliu/MaRK
        private void createFromManualDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImportManualDataWindow dlg = new ImportManualDataWindow();
            DialogResult           dr  = dlg.ShowDialog();

            if (dr == DialogResult.OK)
            {
                scMainPanel.Panel2Collapsed    = false;
                scOutputResult.Panel1Collapsed = true;
                scOutputResult.Panel2Collapsed = false;

                string[] paths = { dlg.RawFileDir, dlg.ModelFilePath };
                backgroundWorker = new BackgroundWorker();
                backgroundWorker.WorkerReportsProgress = true;
                backgroundWorker.DoWork             += new DoWorkEventHandler(GenerateManualData_DoWork);
                backgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(GenerateManualData_ProgressChanged);
                backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(GenerateManualData_Completed);
                backgroundWorker.RunWorkerAsync(paths);
            }
            else if (dr == DialogResult.Retry)
            {
                RenderManualData(Configures.GetManualModelFilePath(), Configures.GetManualSearchTermPath());
            }


            //step by step
            //GenerateManualDataWizard dlg = new GenerateManualDataWizard();
            //DialogResult dr = dlg.ShowDialog();
            //if (dr == DialogResult.OK)
            //{
            //    RenderManualData(Configures.GetManualWizardModelFilePath());
            //}
        }
예제 #4
0
        private void InitializeTab1()
        {
            tbRawFileFolder.Text = Configures.GetAutoWizardRawFilePath();

            if (string.IsNullOrWhiteSpace(tbRawFileFolder.Text))
            {
                btnCopy.Enabled = false;
            }
        }
예제 #5
0
        private void RunTmt_DoWork(object sender, DoWorkEventArgs e)
        {
            TmtToolMg.RunTmtTool(tbTopicNumberArray.Text.Trim(), tbMaxIteration.Text.Trim());
            int    maxIteration        = Int32.Parse(Configures.GetAutoWizardMaxIteration());
            string termDistZipFilePath = FileMg.AutoTmtOutputFileDir + string.Format(Constants.TmtOutputTopicTermDistZipFilePathTemp, maxIteration.ToString("D5"));

            UnzipToolMg.RunUnzipTool(termDistZipFilePath, FileMg.AutoRDataFileDir);
            e.Result = true;
        }
예제 #6
0
파일: MainWindow.cs 프로젝트: lawenliu/MaRK
        private void GenerateManualData_Completed(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!(bool)(e.Result))
            {
                MessageBox.Show("Generating manual model failed! Please check the ouput window to fix the problem and run again.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            RenderManualData(Configures.GetManualModelFilePath(), FileMg.ManualTopicLabelFileDir + Constants.TopicManualTermFileName);
        }
예제 #7
0
        private void tbSourceFileFolder_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbRawFileFolder.Text.Trim()))
            {
                Configures.SaveAutoWizardRawFilePath(tbRawFileFolder.Text);

                btnCopy.Enabled = true;
                CountFileNumber(tbRawFileFolder.Text);
            }
        }
예제 #8
0
        private void btnSelectFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            folderBrowserDialog.Description         = "Select the raw files directory";
            folderBrowserDialog.ShowNewFolderButton = false;
            folderBrowserDialog.RootFolder          = Environment.SpecialFolder.MyComputer;
            folderBrowserDialog.SelectedPath        = Configures.GetAutoWizardRawFilePath();

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                tbRawFileFolder.Text = folderBrowserDialog.SelectedPath;
            }
        }
예제 #9
0
        private void btnSelectModelFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
            openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                tbModelFilePath.Text = openFileDialog.FileName;
                Configures.SaveManualWizardModelFilePath(tbModelFilePath.Text);
            }
        }
예제 #10
0
        private void searchTermPath_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
            openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            tbSearchTermPath.Text           = Configures.GetManualSearchTermPath();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.tbSearchTermPath.Text = openFileDialog.FileName;
            }
        }
예제 #11
0
        private static bool GenerateTopicWithTmt(BackgroundWorker backgroundWorker)
        {
            OutputMg.OutputHeader1(backgroundWorker, "Step 3", "Generate Topic with TMT");
            /* 1. Run Tmt Tool */
            OutputMg.OutputContent(backgroundWorker, "Start to run TMT");
            if (!TmtToolMg.RunTmtTool(Configures.GetAutoWizardTopicNumberArray(), Configures.GetAutoWizardMaxIteration()))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to startup TMT. Make sure you have authority to run command.");
                return(false);
            }

            /* 2. Check Tmt output */
            int    maxIter             = Int32.Parse(Configures.GetAutoWizardMaxIteration());
            string termDistZipFilePath = FileMg.AutoTmtOutputFileDir + string.Format(Constants.TmtOutputTopicTermDistZipFilePathTemp, maxIter.ToString("D5"));

            if (!File.Exists(termDistZipFilePath))
            {
                OutputMg.OutputContent(backgroundWorker, "Cannot find the result file of topic modeling.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished generating topic and term distribution.");

            /* 3. Unzip Term distribution */
            OutputMg.OutputContent(backgroundWorker, "Start to unzip term distribution file");
            if (!UnzipToolMg.RunUnzipTool(termDistZipFilePath, FileMg.AutoRDataFileDir) ||
                !File.Exists(FileMg.AutoRDataFileDir + Constants.RInputFileName))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to unzip term distribution file. Make sure you have setup 7-zip.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished unzipping term distribution file.");

            return(true);
        }
예제 #12
0
        private void LabelTopic_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!Directory.Exists(FileMg.AutoTopicLabelFileDir))
            {
                Directory.CreateDirectory(FileMg.AutoTopicLabelFileDir);
            }

            int minmumTopicNumber = PrepareTopicFile.GetMinimumTopicNumber();
            int maxIteration      = Int32.Parse(Configures.GetAutoWizardMaxIteration());

            if (minmumTopicNumber != -1)
            {
                string summaryFilePath   = FileMg.AutoTmtOutputFileDir + string.Format(Constants.TmtOutputSummaryFilePathTemp, maxIteration.ToString("D5"));
                string topicTermFilePath = FileMg.AutoTopicLabelFileDir + Constants.TopicTermFileName;
                PrepareTopicFile.Execute(summaryFilePath, topicTermFilePath);
                JNSPToolMg.RunJNSPTool();
                string   jnspOutputFileName = FileMg.AutoJNSPDataFileDir + Constants.JnspOptionCNTFileName + Constants.JnspOptionWindowNumber + ".cnt";
                KDDLabel kddLabel           = new KDDLabel(jnspOutputFileName, topicTermFilePath, summaryFilePath, FileMg.AutoTopicLabelFileDir + Constants.TopicLabelFileName);
                kddLabel.GenerateTopicLabel();
                TopicSim.CalTopicSimilarity(topicTermFilePath, FileMg.AutoTopicLabelFileDir + Constants.TopicSimilarityFileName);

                RToolMg.RunRTool();
            }
        }
예제 #13
0
 public void InitializeTab3()
 {
     tbModelFilePath.Text = Configures.GetManualWizardModelFilePath();
 }
예제 #14
0
 private void tbMaxIteration_Leave(object sender, EventArgs e)
 {
     Configures.SaveAutoWizardMaxIteration(tbMaxIteration.Text);
 }
예제 #15
0
        private static bool LabelTopic(BackgroundWorker backgroundWorker)
        {
            OutputMg.OutputHeader1(backgroundWorker, "Step 4", "Label Topic");
            /* 0. Create file directory */
            if (!Directory.Exists(FileMg.AutoTopicLabelFileDir))
            {
                Directory.CreateDirectory(FileMg.AutoTopicLabelFileDir);
            }

            /* 1. Get minimum topic number */
            OutputMg.OutputContent(backgroundWorker, "Getting minimum topic number.");
            int minmumTopicNumber = PrepareTopicFile.GetMinimumTopicNumber();
            int maxIteration      = Int32.Parse(Configures.GetAutoWizardMaxIteration());

            if (minmumTopicNumber == -1)
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to get minimum topic number. Please check whether you run TMT successfully.");
                return(false);
            }

            /* 2. Run TMT */
            OutputMg.OutputContent(backgroundWorker, "Minimum topic number is " + minmumTopicNumber);
            string summaryFilePath   = FileMg.AutoTmtOutputFileDir + string.Format(Constants.TmtOutputSummaryFilePathTemp, maxIteration.ToString("D5"));
            string topicTermFilePath = FileMg.AutoTopicLabelFileDir + Constants.TopicTermFileName;

            OutputMg.OutputContent(backgroundWorker, "Start to generate topic terms file.");
            PrepareTopicFile.Execute(summaryFilePath, topicTermFilePath);
            //LabelDomainTopic.Execute(Constants.DefaultSourceFileDir, Constants.TopicLabelFileDir + Constants.TopicTermFileName, summaryFilePath, Constants.TopicLabelFileDir + Constants.TopicLabelFileName);
            if (!File.Exists(topicTermFilePath))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to generate topic terms file.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished generating topic terms file.");

            /* 3. Run JNSP */
            OutputMg.OutputContent(backgroundWorker, "Start to run JNSP tool.");
            if (!Directory.Exists(FileMg.AutoJNSPDataFileDir))
            {
                Directory.CreateDirectory(FileMg.AutoJNSPDataFileDir);
            }

            JNSPToolMg.RunJNSPTool();
            string jnspOutputFileName = FileMg.AutoJNSPDataFileDir + Constants.JnspOptionCNTFileName + Constants.JnspOptionWindowNumber + ".cnt";

            if (!File.Exists(jnspOutputFileName))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to run JNSP tool.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished running JNSP tool.");

            /* 4. Label topic */
            OutputMg.OutputContent(backgroundWorker, "Start to label topic.");
            KDDLabel kddLabel = new KDDLabel(jnspOutputFileName, topicTermFilePath, summaryFilePath, FileMg.AutoTopicLabelFileDir + Constants.TopicLabelFileName);

            kddLabel.GenerateTopicLabel();
            if (!File.Exists(FileMg.AutoTopicLabelFileDir + Constants.TopicLabelFileName))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to label topic.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished labeling topic");

            /* 5. Generate Similarity */
            OutputMg.OutputContent(backgroundWorker, "Start to generate topic similarity.");
            TopicSim.CalTopicSimilarity(topicTermFilePath, FileMg.AutoTopicLabelFileDir + Constants.TopicSimilarityFileName);
            if (!File.Exists(FileMg.AutoTopicLabelFileDir + Constants.TopicLabelFileName))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to generate topic similarity.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished generating topic similarity");
            /* 6. Running R Tool */
            OutputMg.OutputContent(backgroundWorker, "Start to generate BiTree with R tool.");
            RToolMg.RunRTool();
            if (!File.Exists(FileMg.AutoRDataFileDir + Constants.ROutputFileName))
            {
                OutputMg.OutputContent(backgroundWorker, "Failed to generate BiTree with R tool. Please make sure you have setup R tool.");
                return(false);
            }

            OutputMg.OutputContent(backgroundWorker, "Finished generating BiTree with R tool");

            return(true);
        }
예제 #16
0
 private void InitializeTab3()
 {
     tbTopicNumberArray.Text = Configures.GetAutoWizardTopicNumberArray();
     tbMaxIteration.Text     = Configures.GetAutoWizardMaxIteration();
 }
예제 #17
0
 private void tbTopicNumberArray_Leave(object sender, EventArgs e)
 {
     Configures.SaveAutoWizardTopicNumberArray(tbTopicNumberArray.Text);
 }
예제 #18
0
 private void ImportManualDataWindow_Load(object sender, EventArgs e)
 {
     tbRawFileFolder.Text  = Configures.GetManualRawMaterialFileDir();
     tbModelFilePath.Text  = Configures.GetManualModelFilePath();
     tbSearchTermPath.Text = Configures.GetManualSearchTermPath();
 }
예제 #19
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     Configures.SaveManualRawMaterialFileDir(tbRawFileFolder.Text);
     Configures.SaveManualModelFilePath(tbModelFilePath.Text);
     Configures.SaveManualSearchTermPath(tbSearchTermPath.Text);
 }
예제 #20
0
        public void InitializeTwiceThrowsSystemAlreadyConfiguredException()
        {
            Configures[new Random().Next(0, 4)]();

            Check.ThatCode(Configures[new Random().Next(0, 4)]).Throws <AlreadyConfiguredException>();
        }
예제 #21
0
 private void cbIsDelDestFile_CheckedChanged(object sender, EventArgs e)
 {
     Configures.SaveAutoWizardIsDeleteExistingFile(cbIsDelDestFile.Checked);
 }
예제 #22
0
 private void InitializeTab0()
 {
     cbIsDelDestFile.Checked = Configures.GetAutoWizardIsDeleteExistingFile();
 }
예제 #23
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     Configures.SaveAutoRawMaterialFileDir(tbRawFileFolder.Text);
 }
예제 #24
0
 private void ImportAutoDataWindow_Load(object sender, EventArgs e)
 {
     tbRawFileFolder.Text = Configures.GetAutoRawMaterialFileDir();
 }