public static void SalvarArff(Instances Data, string Diretorio, string NomeArquivo) { ArffSaver saver = new ArffSaver(); saver.setInstances(Data); saver.setFile(new java.io.File(string.Format("{0}" + NomeArquivo, Diretorio))); saver.writeBatch(); }
private void button4_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "arff файлы (*.arff)|*.arff|Все файлы (*.*)|*.*"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { ArffSaver arffSaver = new ArffSaver(); arffSaver.setInstances(dataSet); arffSaver.setFile(new java.io.File(saveFileDialog1.FileName)); arffSaver.writeBatch(); } }
//saves instances to arff format public static void SaveArff(Instances insts, string filename) { if (insts == null) { Console.WriteLine("instances empty null"); return; } var saver = new ArffSaver(); saver.setInstances(insts); saver.setFile(new java.io.File(filename + ".arff")); saver.writeBatch(); }
public Runtime SaveToArffFile(string file) { if (File.Exists(file)) { File.Delete(file); } var saver = new ArffSaver(); saver.setInstances(Impl); saver.setFile(new java.io.File(file)); saver.writeBatch(); return(this); }
/// <summary> /// Adds teta results of gini results to the list /// Change the attributes of the arff file /// Adds the attributes to arff file /// </summary> /// <param name="insts"></param> /// <param name="result"></param> /// <param name="path"></param> private void CreateNewDataset(weka.core.Instances insts, List <double[]> result, string path) { //Tetaları Listeye Ekle List <List <string> > lst = new List <List <string> >(); for (int i = 0; i < insts.numInstances(); i++) { lst.Add(new List <string>()); for (int j = 0; j < insts.instance(i).numValues() - 1; j++) { string value = insts.instance(i).toString(j); for (int k = 0; k < categories[j].Length; k++) { if (insts.instance(i).toString(j) == categories[j][k]) { lst[lst.Count - 1].Add(String.Format("{0:0.00}", result[j][k])); break; } } } } //Attiribute Değiştir for (int i = 0; i < insts.numAttributes() - 1; i++) { string name = insts.attribute(i).name().ToString(); insts.deleteAttributeAt(i); weka.core.Attribute att = new weka.core.Attribute(name); insts.insertAttributeAt(att, i); } //Attiributeları yaz for (int i = 0; i < insts.numInstances(); i++) { for (int j = 0; j < insts.instance(i).numValues() - 1; j++) { insts.instance(i).setValue(j, Convert.ToDouble(lst[i][j])); } } if (File.Exists(path)) { File.Delete(path); } var saver = new ArffSaver(); saver.setInstances(insts); saver.setFile(new java.io.File(path)); saver.writeBatch(); }
/// <summary> /// Guardamos los datos como ARFF /// </summary> /// <returns></returns> public static bool GuardarComoARFF(Instances datos, string directorio) { // TODO: Cambiar esto de workspace??? Probar si funciona // objeto para guardar ArffSaver guardar = new ArffSaver(); // guardamos las instancias en el objeto para guardar guardar.setInstances(datos); // Creamos el directorio donde se quiere escribir guardar.setFile(new File(directorio)); // escribir guardar.writeBatch(); throw new Exception(); }
public cFeedBackMessage Run() { if (this.Input == null) { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "No input data defined."; return FeedBackMessage; } string PathForImages; if (IsDisplayUIForFilePath) { SaveFileDialog CurrSaveFileDialog = new SaveFileDialog(); CurrSaveFileDialog.Filter = "CSV file (*.csv)|*.csv| XLS file (*.xls)|*.xls| ARFF file (*.arff)|*.arff"; System.Windows.Forms.DialogResult Res = CurrSaveFileDialog.ShowDialog(); if (Res != System.Windows.Forms.DialogResult.OK) { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "Incorrect File Name."; return FeedBackMessage; } FilePath = CurrSaveFileDialog.FileName; if (CurrSaveFileDialog.FilterIndex == 1) this.FileType = eFileType.CSV; else if (CurrSaveFileDialog.FilterIndex == 2) this.FileType = eFileType.XLS; else this.FileType = eFileType.ARFF; } else if (IsIncludeImageAsComment) { this.FileType = eFileType.XLS; var dlg1 = new Ionic.Utils.FolderBrowserDialogEx(); dlg1.Description = "Create a folder that will contain your file and the images."; dlg1.ShowNewFolderButton = true; dlg1.ShowEditBox = true; //dlg1.NewStyle = false; // dlg1.SelectedPath = txtExtractDirectory.Text; dlg1.ShowFullPathInEditBox = true; dlg1.RootFolder = System.Environment.SpecialFolder.Desktop; // Show the FolderBrowserDialog. DialogResult result = dlg1.ShowDialog(); if (result != DialogResult.OK) { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "Incorrect File Name."; return FeedBackMessage; } PathForImages = dlg1.SelectedPath; if (Directory.Exists(PathForImages) == false) { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "Incorrect File Name."; return FeedBackMessage; } } else { if (this.FilePath == "") { FeedBackMessage.IsSucceed = false; FeedBackMessage.Message = "Incorrect File Name."; return FeedBackMessage; } } if (this.FileType == eFileType.CSV) { if (IsTagToBeSaved == false) { using (StreamWriter myFile = new StreamWriter(FilePath, this.IsAppend, Encoding.Default)) { // Export titles: string sHeaders = ""; if (this.Input.ListRowNames != null) sHeaders += this.Separator; for (int j = 0; j < this.Input.Count; j++) { sHeaders = sHeaders.ToString() + this.Input[j].Name + Separator; } sHeaders = sHeaders.Remove(sHeaders.Length - 1); myFile.WriteLine(sHeaders); // Export data. for (int i = 0; i < this.Input[0].Count; i++) { string stLine = ""; if ((this.Input.ListRowNames != null) && (this.Input.ListRowNames.Count > i)) stLine += this.Input.ListRowNames[i] + this.Separator; for (int j = 0; j < this.Input.Count; j++) { stLine = stLine.ToString() + this.Input[j][i] + Separator; } stLine = stLine.Remove(stLine.Length - 1); myFile.WriteLine(stLine); } myFile.Close(); } } } else if (this.FileType == eFileType.XLS) { // ExportToExcel(this.Input, FilePath, PathForImages); //Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); //Microsoft.Office.Interop.Excel.Workbook xlWorkBook; //Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; //object misValue = System.Reflection.Missing.Value; //// xlApp = new Excel.ApplicationClass(); //xlWorkBook = xlApp.Workbooks.Add(misValue); //xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //// Microsoft.Office.Interop.Excel.Range cell = GetMyPictureCELL(taperSheet); ////xlWorkSheet.Cells[j + 2, 1].AddComment(" "); ////xlWorkSheet.Cells[j + 2, 1].Comment.Shape.Fill.UserPicture(imagenames[j]); //xlWorkBook.SaveAs(FilePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, // Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); //xlWorkBook.Close(true, misValue, misValue); //xlApp.Quit(); //releaseObject(xlWorkSheet); //releaseObject(xlWorkBook); //releaseObject(xlApp); } else if (this.FileType == eFileType.ARFF) { Instances insts = this.Input.CreateWekaInstances(); ArffSaver saver = new ArffSaver(); CSVSaver savercsv = new CSVSaver(); saver.setInstances(insts); saver.setFile(new java.io.File(FilePath)); saver.writeBatch(); // System.Diagnostics.Process proc1 = new System.Diagnostics.Process(); // proc1.StartInfo.FileName = "C:\\Program Files\\Weka-3-6\\RunWeka.bat explorer"; // proc1.StartInfo.Arguments = FilePath; // proc1.Start(); } if (this.IsRunEXCEL) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "excel"; proc.StartInfo.Arguments = FilePath; proc.Start(); } return FeedBackMessage; }