Java Code Examples for weka.core.converters.AbstractFileSaver

The following are top voted examples for showing how to use weka.core.converters.AbstractFileSaver. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: meka   File: Explorer.java   Source Code and License 6 votes vote down vote up
/**
 * Saves the data to the specified file.
 * 
 * @param file the file to save the data to
 * @param saver the saver to use, determines it automatically if null
 */
public void save(File file, AbstractFileSaver saver) {
	if (saver == null)
		saver = ConverterUtils.getSaverForFile(file);
	try {
		saver.setInstances(m_Data);
		if ((saver.retrieveFile() == null) || !saver.retrieveFile().equals(file))
			saver.setFile(file);
		saver.writeBatch();
		m_CurrentFile = file;
	}
	catch (Exception e) {
		System.err.println("Failed to save data to '" + file + "':");
		e.printStackTrace();
		JOptionPane.showMessageDialog(
				this, 
				"Failed to save dataset to '" + file + "':\n" + e, 
				"Error saving",
				JOptionPane.ERROR_MESSAGE);
	}

	updateMenu();
}
 
Example 2
Project: repo.kmeanspp.silhouette_score   File: HDFSSaverCustomizer.java   Source Code and License 5 votes vote down vote up
@Override
public void closingOK() {
  m_saver.getConfig().setHDFSHost(m_hdfsHostText.getText());
  m_saver.getConfig().setHDFSPort(m_hdfsPortText.getText());
  m_saver.setHDFSPath(m_hdfsPathText.getText());
  m_saver.setDFSReplicationFactor(m_dfsReplicationText.getText());
  m_saver.setSaver((AbstractFileSaver) m_baseSaverEditor.getValue());

  m_saver.setFilePrefix(m_filePrefixText.getText());
}
 
Example 3
Project: repo.kmeanspp.silhouette_score   File: PreprocessPanel.java   Source Code and License 5 votes vote down vote up
/**
  * saves the data with the specified saver
  * 
  * @param saver	the saver to use for storing the data
  * @param inst	the data to save
  */
 public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) {
   if (m_IOThread == null) {
     m_IOThread = new Thread() {
  @Override
  public void run() {
    try {
      m_Log.statusMessage("Saving to file...");

      saver.setInstances(inst);
      saver.writeBatch();
      
      m_Log.statusMessage("OK");
    }
    catch (Exception ex) {
      ex.printStackTrace();
      m_Log.logMessage(ex.getMessage());
    }
    m_IOThread = null;
  }
};
     m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
     m_IOThread.start();
   }
   else {
     JOptionPane.showMessageDialog(this,
			    "Can't save at this time,\n"
			    + "currently busy with other IO",
			    "Saving instances",
			    JOptionPane.WARNING_MESSAGE);
   } 
 }
 
Example 4
Project: repo.kmeanspp.silhouette_score   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the loader that was chosen by the user, can be null in case the
 * user aborted the dialog or the save dialog was shown.
 * 
 * @return the chosen loader, if any
 */
public AbstractFileLoader getLoader() {
  configureCurrentConverter(LOADER_DIALOG);

  if (m_CurrentConverter instanceof AbstractFileSaver) {
    return null;
  } else {
    return (AbstractFileLoader) m_CurrentConverter;
  }
}
 
Example 5
Project: repo.kmeanspp.silhouette_score   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the saver that was chosen by the user, can be null in case the user
 * aborted the dialog or the open dialog was shown.
 * 
 * @return the chosen saver, if any
 */
public AbstractFileSaver getSaver() {
  configureCurrentConverter(SAVER_DIALOG);

  if (m_CurrentConverter instanceof AbstractFileLoader) {
    return null;
  } else {
    return (AbstractFileSaver) m_CurrentConverter;
  }
}
 
Example 6
Project: repo.kmeanspp.silhouette_score   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * For testing the file chooser.
 * 
 * @param args the commandline options - ignored
 * @throws Exception if something goes wrong with loading/saving
 */
public static void main(String[] args) throws Exception {
  ConverterFileChooser fc;
  int retVal;
  AbstractFileLoader loader;
  AbstractFileSaver saver;
  Instances data;

  fc = new ConverterFileChooser();
  retVal = fc.showOpenDialog(null);

  // load file
  if (retVal == ConverterFileChooser.APPROVE_OPTION) {
    loader = fc.getLoader();
    data = loader.getDataSet();
    retVal = fc.showSaveDialog(null);

    // save file
    if (retVal == ConverterFileChooser.APPROVE_OPTION) {
      saver = fc.getSaver();
      saver.setInstances(data);
      saver.writeBatch();
    } else {
      System.out.println("Saving aborted!");
    }
  } else {
    System.out.println("Loading aborted!");
  }
}
 
Example 7
Project: autoweka   File: PreprocessPanel.java   Source Code and License 5 votes vote down vote up
/**
  * saves the data with the specified saver
  * 
  * @param saver	the saver to use for storing the data
  * @param inst	the data to save
  */
 public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) {
   if (m_IOThread == null) {
     m_IOThread = new Thread() {
  public void run() {
    try {
      m_Log.statusMessage("Saving to file...");

      saver.setInstances(inst);
      saver.writeBatch();
      
      m_Log.statusMessage("OK");
    }
    catch (Exception ex) {
      ex.printStackTrace();
      m_Log.logMessage(ex.getMessage());
    }
    m_IOThread = null;
  }
};
     m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
     m_IOThread.start();
   }
   else {
     JOptionPane.showMessageDialog(this,
			    "Can't save at this time,\n"
			    + "currently busy with other IO",
			    "Saving instances",
			    JOptionPane.WARNING_MESSAGE);
   } 
 }
 
Example 8
Project: autoweka   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the loader that was chosen by the user, can be null in case the
 * user aborted the dialog or the save dialog was shown.
 * 
 * @return		the chosen loader, if any
 */
public AbstractFileLoader getLoader() {
  configureCurrentConverter(LOADER_DIALOG);
  
  if (m_CurrentConverter instanceof AbstractFileSaver)
    return null;
  else
    return (AbstractFileLoader) m_CurrentConverter;
}
 
Example 9
Project: autoweka   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the saver that was chosen by the user, can be null in case the
 * user aborted the dialog or the open dialog was shown.
 * 
 * @return		the chosen saver, if any
 */
public AbstractFileSaver getSaver() {
  configureCurrentConverter(SAVER_DIALOG);
  
  if (m_CurrentConverter instanceof AbstractFileLoader)
    return null;
  else
    return (AbstractFileSaver) m_CurrentConverter;
}
 
Example 10
Project: autoweka   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
  * For testing the file chooser.
  * 
  * @param args	the commandline options - ignored
  * @throws Exception	if something goes wrong with loading/saving
  */
 public static void main(String[] args) throws Exception {
   ConverterFileChooser	fc;
   int				retVal;
   AbstractFileLoader		loader;
   AbstractFileSaver		saver;
   Instances			data;
   
   fc     = new ConverterFileChooser();
   retVal = fc.showOpenDialog(null);
   
   // load file
   if (retVal == ConverterFileChooser.APPROVE_OPTION) {
     loader = fc.getLoader();
     data   = loader.getDataSet();
     retVal = fc.showSaveDialog(null);

     // save file
     if (retVal == ConverterFileChooser.APPROVE_OPTION) {
saver = fc.getSaver();
saver.setInstances(data);
saver.writeBatch();
     }
     else {
System.out.println("Saving aborted!");
     }
   }
   else {
     System.out.println("Loading aborted!");
   }
 }
 
Example 11
Project: umple   File: PreprocessPanel.java   Source Code and License 5 votes vote down vote up
/**
  * saves the data with the specified saver
  * 
  * @param saver	the saver to use for storing the data
  * @param inst	the data to save
  */
 public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) {
   if (m_IOThread == null) {
     m_IOThread = new Thread() {
  @Override
  public void run() {
    try {
      m_Log.statusMessage("Saving to file...");

      saver.setInstances(inst);
      saver.writeBatch();
      
      m_Log.statusMessage("OK");
    }
    catch (Exception ex) {
      ex.printStackTrace();
      m_Log.logMessage(ex.getMessage());
    }
    m_IOThread = null;
  }
};
     m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
     m_IOThread.start();
   }
   else {
     JOptionPane.showMessageDialog(this,
			    "Can't save at this time,\n"
			    + "currently busy with other IO",
			    "Saving instances",
			    JOptionPane.WARNING_MESSAGE);
   } 
 }
 
Example 12
Project: umple   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the loader that was chosen by the user, can be null in case the
 * user aborted the dialog or the save dialog was shown.
 * 
 * @return the chosen loader, if any
 */
public AbstractFileLoader getLoader() {
  configureCurrentConverter(LOADER_DIALOG);

  if (m_CurrentConverter instanceof AbstractFileSaver) {
    return null;
  } else {
    return (AbstractFileLoader) m_CurrentConverter;
  }
}
 
Example 13
Project: umple   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the saver that was chosen by the user, can be null in case the user
 * aborted the dialog or the open dialog was shown.
 * 
 * @return the chosen saver, if any
 */
public AbstractFileSaver getSaver() {
  configureCurrentConverter(SAVER_DIALOG);

  if (m_CurrentConverter instanceof AbstractFileLoader) {
    return null;
  } else {
    return (AbstractFileSaver) m_CurrentConverter;
  }
}
 
Example 14
Project: umple   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * For testing the file chooser.
 * 
 * @param args the commandline options - ignored
 * @throws Exception if something goes wrong with loading/saving
 */
public static void main(String[] args) throws Exception {
  ConverterFileChooser fc;
  int retVal;
  AbstractFileLoader loader;
  AbstractFileSaver saver;
  Instances data;

  fc = new ConverterFileChooser();
  retVal = fc.showOpenDialog(null);

  // load file
  if (retVal == ConverterFileChooser.APPROVE_OPTION) {
    loader = fc.getLoader();
    data = loader.getDataSet();
    retVal = fc.showSaveDialog(null);

    // save file
    if (retVal == ConverterFileChooser.APPROVE_OPTION) {
      saver = fc.getSaver();
      saver.setInstances(data);
      saver.writeBatch();
    } else {
      System.out.println("Saving aborted!");
    }
  } else {
    System.out.println("Loading aborted!");
  }
}
 
Example 15
Project: jbossBA   File: PreprocessPanel.java   Source Code and License 5 votes vote down vote up
/**
  * saves the data with the specified saver
  * 
  * @param saver	the saver to use for storing the data
  * @param inst	the data to save
  */
 public void saveInstancesToFile(final AbstractFileSaver saver, final Instances inst) {
   if (m_IOThread == null) {
     m_IOThread = new Thread() {
  public void run() {
    try {
      m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_Log_StatusMessage_Text_First"));

      saver.setInstances(inst);
      saver.writeBatch();
      
      m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_Log_StatusMessage_Text_Second"));
    }
    catch (Exception ex) {
      ex.printStackTrace();
      m_Log.logMessage(ex.getMessage());
    }
    m_IOThread = null;
  }
};
     m_IOThread.setPriority(Thread.MIN_PRIORITY); // UI has most priority
     m_IOThread.start();
   }
   else {
     JOptionPane.showMessageDialog(this,
   		  Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_JOptionPaneShowMessageDialog_Text_First"),
			    Messages.getInstance().getString("PreprocessPanel_SaveInstancesToFile_Run_JOptionPaneShowMessageDialog_Text_Second"),
			    JOptionPane.WARNING_MESSAGE);
   } 
 }
 
Example 16
Project: jbossBA   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the loader that was chosen by the user, can be null in case the
 * user aborted the dialog or the save dialog was shown
 * 
 * @return		the chosen loader, if any
 */
public AbstractFileLoader getLoader() {
  configureCurrentConverter(LOADER_DIALOG);
  
  if (m_CurrentConverter instanceof AbstractFileSaver)
    return null;
  else
    return (AbstractFileLoader) m_CurrentConverter;
}
 
Example 17
Project: jbossBA   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
 * returns the saver that was chosen by the user, can be null in case the
 * user aborted the dialog or the open dialog was shown
 * 
 * @return		the chosen saver, if any
 */
public AbstractFileSaver getSaver() {
  configureCurrentConverter(SAVER_DIALOG);
  
  if (m_CurrentConverter instanceof AbstractFileLoader)
    return null;
  else
    return (AbstractFileSaver) m_CurrentConverter;
}
 
Example 18
Project: jbossBA   File: ConverterFileChooser.java   Source Code and License 5 votes vote down vote up
/**
  * For testing the file chooser
  * 
  * @param args	the commandline options - ignored
  * @throws Exception	if something goes wrong with loading/saving
  */
 public static void main(String[] args) throws Exception {
   ConverterFileChooser	fc;
   int				retVal;
   AbstractFileLoader		loader;
   AbstractFileSaver		saver;
   Instances			data;
   
   fc     = new ConverterFileChooser();
   retVal = fc.showOpenDialog(null);
   
   // load file
   if (retVal == ConverterFileChooser.APPROVE_OPTION) {
     loader = fc.getLoader();
     data   = loader.getDataSet();
     retVal = fc.showSaveDialog(null);

     // save file
     if (retVal == ConverterFileChooser.APPROVE_OPTION) {
saver = fc.getSaver();
saver.setInstances(data);
saver.writeBatch();
     }
     else {
System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +Messages.getInstance().getString("ConverterFileChooser_Main_Text_First"));
     }
   }
   else {
     System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +Messages.getInstance().getString("ConverterFileChooser_Main_Text_Second"));
   }
 }
 
Example 19
Project: repo.kmeanspp.silhouette_score   File: ConverterFileChooser.java   Source Code and License 4 votes vote down vote up
/**
 * initializes the GUI.
 * 
 * @param dialogType the type of dialog to setup the GUI for
 */
protected void initGUI(int dialogType) {
  Vector<ExtensionFileFilter> list;
  int i;
  boolean acceptAll;

  // backup current state
  acceptAll = isAcceptAllFileFilterUsed();

  // setup filters
  resetChoosableFileFilters();
  setAcceptAllFileFilterUsed(acceptAll);
  if (dialogType == LOADER_DIALOG) {
    list = filterNonCoreLoaderFileFilters(m_LoaderFileFilters);
  } else {
    list = filterSaverFileFilters(filterNonCoreSaverFileFilters(m_SaverFileFilters));
  }
  for (i = 0; i < list.size(); i++) {
    addChoosableFileFilter(list.get(i));
  }
  if (list.size() > 0) {
    if ((m_LastFilter == null) || (!list.contains(m_LastFilter))) {
      setFileFilter(list.get(0));
    } else {
      setFileFilter(m_LastFilter);
    }
  }

  // listener
  if (m_Listener != null) {
    removePropertyChangeListener(m_Listener);
  }
  m_Listener = new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      // filter changed
      if (evt.getPropertyName().equals(FILE_FILTER_CHANGED_PROPERTY)) {
        updateCurrentConverter();
      }
    }
  };
  addPropertyChangeListener(m_Listener);

  // initial setup
  if (dialogType == LOADER_DIALOG) {
    m_Editor.setClassType(AbstractFileLoader.class);
    m_Editor.setValue(new weka.core.converters.ArffLoader());
  } else {
    m_Editor.setClassType(AbstractFileSaver.class);
    m_Editor.setValue(new weka.core.converters.ArffSaver());
  }

  updateCurrentConverter();
}
 
Example 20
Project: autoweka   File: ConverterFileChooser.java   Source Code and License 4 votes vote down vote up
/**
  * initializes the GUI.
  * 
  * @param dialogType		the type of dialog to setup the GUI for
  */
 protected void initGUI(int dialogType) {
   Vector<ExtensionFileFilter>	list;
   int				i;
   boolean 			acceptAll;

   // backup current state
   acceptAll = isAcceptAllFileFilterUsed();

   // setup filters
   resetChoosableFileFilters();
   setAcceptAllFileFilterUsed(acceptAll);
   if (dialogType == LOADER_DIALOG)
     list = filterNonCoreLoaderFileFilters(m_LoaderFileFilters);
   else
     list = filterSaverFileFilters(filterNonCoreSaverFileFilters(m_SaverFileFilters));
   for (i = 0; i < list.size(); i++) {
     addChoosableFileFilter(list.get(i));
   }
   if (list.size() > 0) {
     if ( (m_LastFilter == null) || (!list.contains(m_LastFilter)) )
setFileFilter(list.get(0));
     else
setFileFilter(m_LastFilter);
   }

   // listener
   if (m_Listener != null)
     removePropertyChangeListener(m_Listener);
   m_Listener = new PropertyChangeListener() {
     public void propertyChange(PropertyChangeEvent evt) {
// filter changed
if (evt.getPropertyName().equals(FILE_FILTER_CHANGED_PROPERTY)) {
  updateCurrentConverter();
}
     }
   };
   addPropertyChangeListener(m_Listener);
   
   // initial setup
   if (dialogType == LOADER_DIALOG) {
     m_Editor.setClassType(AbstractFileLoader.class);
     m_Editor.setValue(new weka.core.converters.ArffLoader());
   }
   else {
     m_Editor.setClassType(AbstractFileSaver.class);
     m_Editor.setValue(new weka.core.converters.ArffSaver());
   }
   
   updateCurrentConverter();
 }
 
Example 21
Project: umple   File: ConverterFileChooser.java   Source Code and License 4 votes vote down vote up
/**
 * initializes the GUI.
 * 
 * @param dialogType the type of dialog to setup the GUI for
 */
protected void initGUI(int dialogType) {
  Vector<ExtensionFileFilter> list;
  int i;
  boolean acceptAll;

  // backup current state
  acceptAll = isAcceptAllFileFilterUsed();

  // setup filters
  resetChoosableFileFilters();
  setAcceptAllFileFilterUsed(acceptAll);
  if (dialogType == LOADER_DIALOG) {
    list = filterNonCoreLoaderFileFilters(m_LoaderFileFilters);
  } else {
    list = filterSaverFileFilters(filterNonCoreSaverFileFilters(m_SaverFileFilters));
  }
  for (i = 0; i < list.size(); i++) {
    addChoosableFileFilter(list.get(i));
  }
  if (list.size() > 0) {
    if ((m_LastFilter == null) || (!list.contains(m_LastFilter))) {
      setFileFilter(list.get(0));
    } else {
      setFileFilter(m_LastFilter);
    }
  }

  // listener
  if (m_Listener != null) {
    removePropertyChangeListener(m_Listener);
  }
  m_Listener = new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      // filter changed
      if (evt.getPropertyName().equals(FILE_FILTER_CHANGED_PROPERTY)) {
        updateCurrentConverter();
      }
    }
  };
  addPropertyChangeListener(m_Listener);

  // initial setup
  if (dialogType == LOADER_DIALOG) {
    m_Editor.setClassType(AbstractFileLoader.class);
    m_Editor.setValue(new weka.core.converters.ArffLoader());
  } else {
    m_Editor.setClassType(AbstractFileSaver.class);
    m_Editor.setValue(new weka.core.converters.ArffSaver());
  }

  updateCurrentConverter();
}