本文整理汇总了Java中weka.core.xml.XStream类的典型用法代码示例。如果您正苦于以下问题:Java XStream类的具体用法?Java XStream怎么用?Java XStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XStream类属于weka.core.xml包,在下文中一共展示了XStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateFileFormat
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Validate the file format. After this bean is deserialized, classes for XML
* serialization may not be in the classpath any more.
*
* @param ff the current file format to validate
*/
public Tag validateFileFormat(Tag ff) {
Tag r = ff;
if (ff.getID() == BINARY) {
return ff;
}
if (ff.getID() == KOMLV && !KOML.isPresent()) {
r = null;
}
if (ff.getID() == XSTREAM && !XStream.isPresent()) {
r = null;
}
return r;
}
示例2: validateFileFormat
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Validate the file format. After this bean is deserialized, classes for
* XML serialization may not be in the classpath any more.
*
* @param ff the current file format to validate
*/
public Tag validateFileFormat(Tag ff) {
Tag r = ff;
if (ff.getID() == BINARY) {
return ff;
}
if (ff.getID() == KOMLV && !KOML.isPresent()) {
r = null;
}
if (ff.getID() == XSTREAM && !XStream.isPresent()) {
r = null;
}
return r;
}
示例3: serializeClassifierAsJson
import weka.core.xml.XStream; //导入依赖的package包/类
public String serializeClassifierAsJson() throws IOException
{
try {
return XStream.serialize(trainedClassifier);
} catch (Exception e) {
if(e instanceof IOException)
throw (IOException)e;
else
throw new OperationFailedUnexpectedly(e);
}
}
示例4: deserializeClassifierFromJson
import weka.core.xml.XStream; //导入依赖的package包/类
public Classifier deserializeClassifierFromJson(String xmlString) throws IOException
{
try
{
if (!StringUtils.isEmpty(classifierImpl)) {
Class.forName(classifierImpl);
trainedClassifier = (Classifier) XStream.deSerialize(xmlString);
}
} catch (Exception e) {
throw new IOException(e);
}
return trainedClassifier;
}
示例5: setupFileChooser
import weka.core.xml.XStream; //导入依赖的package包/类
protected void setupFileChooser() {
if (m_fileChooser == null) {
m_fileChooser =
new JFileChooser(new File(System.getProperty("user.dir")));
}
m_fileChooser.addChoosableFileFilter(m_binaryFilter);
if (KOML.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_KOMLFilter);
}
if (XStream.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_XStreamFilter);
}
m_fileChooser.setFileFilter(m_binaryFilter);
}
示例6: saveXStream
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Save a model in XStream deep object serialized XML form.
*
* @param saveTo the file name to save to
* @param model the model to save
* @param header the header of the data that was used to train the model
* (optional)
*/
public static void saveXStream(File saveTo, Object model, Instances header)
throws Exception {
Vector<Object> v = new Vector<Object>();
v.add(model);
if (header != null) {
v.add(header);
}
v.trimToSize();
XStream.write(saveTo.getAbsolutePath(), v);
}
示例7: setupFileChooser
import weka.core.xml.XStream; //导入依赖的package包/类
protected void setupFileChooser() {
if (m_fileChooser == null) {
m_fileChooser =
new JFileChooser(new File(System.getProperty("user.dir")));
}
m_fileChooser.addChoosableFileFilter(m_binaryFilter);
if (KOML.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_KOMLFilter);
}
if (XStream.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_XStreamFilter);
}
m_fileChooser.setFileFilter(m_binaryFilter);
}
示例8: saveModel
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Helper routine to actually save the models.
*/
private void saveModel(String fileName, Instances trainHeader, Object model) {
m_fileFormat = validateFileFormat(m_fileFormat);
if (m_fileFormat == null) {
// default to binary if validation fails
m_fileFormat = s_fileFormatsAvailable.get(0);
}
try {
switch (m_fileFormat.getID()) {
case KOMLV:
fileName = fileName + KOML.FILE_EXTENSION + FILE_EXTENSION;
saveKOML(new File(fileName), model, trainHeader);
break;
case XSTREAM:
fileName = fileName + XStream.FILE_EXTENSION + FILE_EXTENSION;
saveXStream(new File(fileName), model, trainHeader);
break;
default:
fileName = fileName + "." + FILE_EXTENSION;
saveBinary(new File(fileName), model, trainHeader);
break;
}
} catch (Exception ex) {
stop(); // stop all processing
System.err.println("[SerializedModelSaver] Problem saving model");
if (m_logger != null) {
m_logger.logMessage("[SerializedModelSaver] "
+ statusMessagePrefix() + " Problem saving model");
m_logger.statusMessage(statusMessagePrefix()
+ "ERROR (See log for details)");
}
}
}
示例9: saveXStream
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Save a model in XStream deep object serialized XML form.
*
* @param saveTo the file name to save to
* @param model the model to save
* @param header the header of the data that was used to train the model (optional)
*/
public static void saveXStream(File saveTo, Object model, Instances header) throws Exception {
Vector v = new Vector();
v.add(model);
if (header != null) {
v.add(header);
}
v.trimToSize();
XStream.write(saveTo.getAbsolutePath(), v);
}
示例10: setupFileChooser
import weka.core.xml.XStream; //导入依赖的package包/类
protected void setupFileChooser() {
if (m_fileChooser == null) {
m_fileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
}
m_fileChooser.addChoosableFileFilter(m_binaryFilter);
if (KOML.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_KOMLFilter);
}
if (XStream.isPresent()) {
m_fileChooser.addChoosableFileFilter(m_XStreamFilter);
}
m_fileChooser.setFileFilter(m_binaryFilter);
}
示例11: saveModel
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Helper routine to actually save the models.
*/
private void saveModel(String fileName, Instances trainHeader, Object model) {
m_fileFormat = validateFileFormat(m_fileFormat);
if (m_fileFormat == null) {
// default to binary if validation fails
m_fileFormat = s_fileFormatsAvailable.get(0);
}
try {
switch (m_fileFormat.getID()) {
case KOMLV:
fileName = fileName + KOML.FILE_EXTENSION + FILE_EXTENSION;
saveKOML(new File(fileName), model, trainHeader);
break;
case XSTREAM:
fileName = fileName + XStream.FILE_EXTENSION + FILE_EXTENSION;
saveXStream(new File(fileName), model, trainHeader);
break;
default:
fileName = fileName + "." + FILE_EXTENSION;
saveBinary(new File(fileName), model, trainHeader);
break;
}
} catch (Exception ex) {
System.err.println(Messages.getInstance().getString(
"SerializedModelSaver_SaveModel_Error_Text"));
if (m_logger != null) {
m_logger.logMessage(Messages.getInstance().getString(
"SerializedModelSaver_SaveModel_LogMessage_Text_First")
+ statusMessagePrefix()
+ Messages.getInstance().getString(
"SerializedModelSaver_SaveModel_LogMessage_Text_Second")
+ " : "
+ ex.getMessage());
m_logger.statusMessage(statusMessagePrefix()
+ Messages.getInstance().getString(
"SerializedModelSaver_SaveModel_StatusMessage_Text"));
}
}
}
示例12: saveXStream
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Save a model in XStream deep object serialized XML form.
*
* @param saveTo the file name to save to
* @param model the model to save
* @param header the header of the data that was used to train the model
* (optional)
*/
public static void saveXStream(File saveTo, Object model, Instances header)
throws Exception {
Vector v = new Vector();
v.add(model);
if (header != null) {
v.add(header);
}
v.trimToSize();
XStream.write(saveTo.getAbsolutePath(), v);
}
示例13: loadModel
import weka.core.xml.XStream; //导入依赖的package包/类
public void loadModel() {
try {
if (m_fileChooser == null) {
// i.e. after de-serialization
setupFileChooser();
}
int returnVal = m_fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File loadFrom = m_fileChooser.getSelectedFile();
// add extension if necessary
if (m_fileChooser.getFileFilter() == m_binaryFilter) {
if (!loadFrom.getName().toLowerCase().endsWith("." + FILE_EXTENSION)) {
loadFrom =
new File(loadFrom.getParent(), loadFrom.getName() + "."
+ FILE_EXTENSION);
}
} else if (m_fileChooser.getFileFilter() == m_KOMLFilter) {
if (!loadFrom.getName().toLowerCase()
.endsWith(KOML.FILE_EXTENSION + FILE_EXTENSION)) {
loadFrom =
new File(loadFrom.getParent(), loadFrom.getName()
+ KOML.FILE_EXTENSION + FILE_EXTENSION);
}
} else if (m_fileChooser.getFileFilter() == m_XStreamFilter) {
if (!loadFrom.getName().toLowerCase()
.endsWith(XStream.FILE_EXTENSION + FILE_EXTENSION)) {
loadFrom =
new File(loadFrom.getParent(), loadFrom.getName()
+ XStream.FILE_EXTENSION + FILE_EXTENSION);
}
}
loadFromFile(loadFrom);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(Classifier.this,
"Problem loading classifier.\n" + ex.getMessage(), "Load Model",
JOptionPane.ERROR_MESSAGE);
if (m_log != null) {
m_log.statusMessage(statusMessagePrefix() + "ERROR: unable to load "
+ "model (see log).");
m_log.logMessage("[Classifier] " + statusMessagePrefix()
+ "Problem loading classifier. " + ex.getMessage());
}
}
}
示例14: saveModel
import weka.core.xml.XStream; //导入依赖的package包/类
public void saveModel() {
try {
if (m_fileChooser == null) {
// i.e. after de-serialization
setupFileChooser();
}
int returnVal = m_fileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File saveTo = m_fileChooser.getSelectedFile();
String fn = saveTo.getAbsolutePath();
if (m_fileChooser.getFileFilter() == m_binaryFilter) {
if (!fn.toLowerCase().endsWith("." + FILE_EXTENSION)) {
fn += "." + FILE_EXTENSION;
}
} else if (m_fileChooser.getFileFilter() == m_KOMLFilter) {
if (!fn.toLowerCase().endsWith(KOML.FILE_EXTENSION + FILE_EXTENSION)) {
fn += KOML.FILE_EXTENSION + FILE_EXTENSION;
}
} else if (m_fileChooser.getFileFilter() == m_XStreamFilter) {
if (!fn.toLowerCase().endsWith(
XStream.FILE_EXTENSION + FILE_EXTENSION)) {
fn += XStream.FILE_EXTENSION + FILE_EXTENSION;
}
}
saveTo = new File(fn);
// now serialize model
// KOML?
if ((KOML.isPresent())
&& saveTo.getAbsolutePath().toLowerCase()
.endsWith(KOML.FILE_EXTENSION + FILE_EXTENSION)) {
SerializedModelSaver.saveKOML(saveTo, m_Classifier,
(m_trainingSet != null) ? new Instances(m_trainingSet, 0) : null);
/*
* Vector v = new Vector(); v.add(m_Classifier); if (m_trainingSet !=
* null) { v.add(new Instances(m_trainingSet, 0)); } v.trimToSize();
* KOML.write(saveTo.getAbsolutePath(), v);
*/
} /* XStream */else if ((XStream.isPresent())
&& saveTo.getAbsolutePath().toLowerCase()
.endsWith(XStream.FILE_EXTENSION + FILE_EXTENSION)) {
SerializedModelSaver.saveXStream(saveTo, m_Classifier,
(m_trainingSet != null) ? new Instances(m_trainingSet, 0) : null);
/*
* Vector v = new Vector(); v.add(m_Classifier); if (m_trainingSet !=
* null) { v.add(new Instances(m_trainingSet, 0)); } v.trimToSize();
* XStream.write(saveTo.getAbsolutePath(), v);
*/
} else /* binary */{
ObjectOutputStream os =
new ObjectOutputStream(new BufferedOutputStream(
new FileOutputStream(saveTo)));
os.writeObject(m_Classifier);
if (m_trainingSet != null) {
Instances header = new Instances(m_trainingSet, 0);
os.writeObject(header);
}
os.close();
}
if (m_log != null) {
m_log.statusMessage(statusMessagePrefix() + "Model saved.");
m_log.logMessage("[Classifier] " + statusMessagePrefix()
+ " Saved classifier " + getCustomName());
}
}
} catch (Exception ex) {
JOptionPane
.showMessageDialog(Classifier.this, "Problem saving classifier.\n",
"Save Model", JOptionPane.ERROR_MESSAGE);
if (m_log != null) {
m_log.statusMessage(statusMessagePrefix() + "ERROR: unable to"
+ " save model (see log).");
m_log.logMessage("[Classifier] " + statusMessagePrefix()
+ " Problem saving classifier " + getCustomName() + ex.getMessage());
}
}
}
示例15: loadLayout
import weka.core.xml.XStream; //导入依赖的package包/类
/**
* Load a pre-saved layout
*/
private void loadLayout() {
m_loadB.setEnabled(false);
m_saveB.setEnabled(false);
m_playB.setEnabled(false);
m_playBB.setEnabled(false);
int returnVal = m_FileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
// stopFlow();
// determine filename
File oFile = m_FileChooser.getSelectedFile();
// set internal flow directory environment variable
// add extension if necessary
if (m_FileChooser.getFileFilter() == m_KfFilter) {
if (!oFile.getName().toLowerCase().endsWith(FILE_EXTENSION)) {
oFile = new File(oFile.getParent(), oFile.getName() + FILE_EXTENSION);
}
} else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {
if (!oFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION + "kf")) {
oFile = new File(oFile.getParent(), oFile.getName()
+ KOML.FILE_EXTENSION + "kf");
}
} else if (m_FileChooser.getFileFilter() == m_XMLFilter) {
if (!oFile.getName().toLowerCase().endsWith(FILE_EXTENSION_XML)) {
oFile = new File(oFile.getParent(), oFile.getName()
+ FILE_EXTENSION_XML);
}
} else if (m_FileChooser.getFileFilter() == m_XStreamFilter) {
if (!oFile.getName().toLowerCase()
.endsWith(XStream.FILE_EXTENSION + "kf")) {
oFile = new File(oFile.getParent(), oFile.getName()
+ XStream.FILE_EXTENSION + "kf");
}
}
String flowName = oFile.getName();
if (flowName.lastIndexOf('.') > 0) {
flowName = flowName.substring(0, flowName.lastIndexOf('.'));
}
loadLayout(oFile, getAllowMultipleTabs());
}
m_loadB.setEnabled(true);
m_playB.setEnabled(true);
m_playBB.setEnabled(true);
m_saveB.setEnabled(true);
}