weka.core.Instances.stringFreeStructure()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中weka.core.Instances.stringFreeStructure()方法的一些代码示例,展示了Instances.stringFreeStructure()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.stringFreeStructure()方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:stringFreeStructure

Instances.stringFreeStructure介绍

[英]Create a copy of the structure. If the data has string or relational attributes, theses are replaced by empty copies. Other attributes are left unmodified, but the underlying list structure holding references to the attributes is shallow-copied, so that other Instances objects with a reference to this list are not affected.
[中]创建结构的副本。如果数据具有字符串或关系属性,则这些属性将替换为空副本。其他属性保持不变,但保留对属性引用的基础列表结构会被浅层复制,因此引用此列表的其他实例对象不会受到影响。

代码示例

代码示例来源:origin: com.googlecode.obvious/obviousx-weka

@Override
public Instances stringFreeStructure() {
 return super.stringFreeStructure();
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Sets the format of output instances. The derived class should use this
 * method once it has determined the outputformat. The output queue is
 * cleared.
 *
 * @param outputFormat the new output format
 */
protected void setOutputFormat(Instances outputFormat) {
 if (outputFormat != null) {
  m_OutputFormat = outputFormat.stringFreeStructure();
  initOutputLocators(m_OutputFormat, null);
  // Rename the relation
  String relationName =
   outputFormat.relationName() + "-" + this.getClass().getName();
  if (this instanceof OptionHandler) {
   String[] options = ((OptionHandler) this).getOptions();
   for (String option : options) {
    relationName += option.trim();
   }
  }
  m_OutputFormat.setRelationName(relationName);
 } else {
  m_OutputFormat = null;
 }
 m_OutputQueue = new Queue();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Sets the format of output instances. The derived class should use this
 * method once it has determined the outputformat. The output queue is
 * cleared.
 *
 * @param outputFormat the new output format
 */
protected void setOutputFormat(Instances outputFormat) {
 if (outputFormat != null) {
  m_OutputFormat = outputFormat.stringFreeStructure();
  initOutputLocators(m_OutputFormat, null);
  // Rename the relation
  String relationName =
   outputFormat.relationName() + "-" + this.getClass().getName();
  if (this instanceof OptionHandler) {
   String[] options = ((OptionHandler) this).getOptions();
   for (String option : options) {
    relationName += option.trim();
   }
  }
  m_OutputFormat.setRelationName(relationName);
 } else {
  m_OutputFormat = null;
 }
 m_OutputQueue = new Queue();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Constructor
 * 
 * @param matchDetails the internally encoded match details string
 * @param inputStructure the incoming instances structure
 * @param statusMessagePrefix an optional status message prefix string for
 *          logging
 * @param log the log to use (may be null)
 * @param env environment variables
 */
public SubstringReplacerRules(String matchDetails, Instances inputStructure,
 String statusMessagePrefix, Logger log, Environment env) {
 m_matchRules =
  matchRulesFromInternal(matchDetails, inputStructure, statusMessagePrefix,
   log, env);
 m_inputStructure = new Instances(inputStructure);
 m_outputStructure = new Instances(inputStructure).stringFreeStructure();
 m_env = env;
 m_statusMessagePrefix = statusMessagePrefix;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Constructor
 * 
 * @param matchDetails the internally encoded match details string
 * @param inputStructure the incoming instances structure
 * @param statusMessagePrefix an optional status message prefix string for
 *          logging
 * @param log the log to use (may be null)
 * @param env environment variables
 */
public SubstringReplacerRules(String matchDetails, Instances inputStructure,
 String statusMessagePrefix, Logger log, Environment env) {
 m_matchRules =
  matchRulesFromInternal(matchDetails, inputStructure, statusMessagePrefix,
   log, env);
 m_inputStructure = new Instances(inputStructure);
 m_outputStructure = new Instances(inputStructure).stringFreeStructure();
 m_env = env;
 m_statusMessagePrefix = statusMessagePrefix;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Sets the format of the input instances. If the filter is able to determine
 * the output format before seeing any input instances, it does so here. This
 * default implementation clears the output format and output queue, and the
 * new batch flag is set. Overriders should call
 * <code>super.setInputFormat(Instances)</code>
 *
 * @param instanceInfo an Instances object containing the input instance
 *          structure (any instances contained in the object are ignored -
 *          only the structure is required).
 * @return true if the outputFormat may be collected immediately
 * @throws Exception if the inputFormat can't be set successfully
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {
 testInputFormat(instanceInfo);
 m_InputFormat = instanceInfo.stringFreeStructure();
 m_OutputFormat = null;
 m_OutputQueue = new Queue();
 m_NewBatch = true;
 m_FirstBatchDone = false;
 initInputLocators(m_InputFormat, null);
 return false;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Sets the format of the input instances. If the filter is able to determine
 * the output format before seeing any input instances, it does so here. This
 * default implementation clears the output format and output queue, and the
 * new batch flag is set. Overriders should call
 * <code>super.setInputFormat(Instances)</code>
 *
 * @param instanceInfo an Instances object containing the input instance
 *          structure (any instances contained in the object are ignored -
 *          only the structure is required).
 * @return true if the outputFormat may be collected immediately
 * @throws Exception if the inputFormat can't be set successfully
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {
 testInputFormat(instanceInfo);
 m_InputFormat = instanceInfo.stringFreeStructure();
 m_OutputFormat = null;
 m_OutputQueue = new Queue();
 m_NewBatch = true;
 m_FirstBatchDone = false;
 initInputLocators(m_InputFormat, null);
 return false;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public void buildClassifier(Instances data) throws Exception {
 if (getPathToPreConstructedFilter() != null
  && getPathToPreConstructedFilter().length() > 0) {
  loadFilter();
 }
 if (getClassifier() == null) {
  throw new Exception("No base classifier set!");
 }
 if (getPreConstructedFilter() == null) {
  throw new Exception("No filter set!");
 }
 Instances filtered = Filter.useFilter(data, getPreConstructedFilter());
 m_filteredInstances = filtered.stringFreeStructure();
 getClassifier().buildClassifier(filtered);
}

代码示例来源:origin: Waikato/weka-trunk

@SuppressWarnings("unchecked")
public void setup(Instances inputFormat) throws Exception {
 m_inputContainsStringAttributes = inputFormat.checkForStringAttributes();
 m_inputFormat = inputFormat.stringFreeStructure();
 if (!m_inputContainsStringAttributes) {
  return;
 }
 m_numClasses =
  !m_doNotOperateOnPerClassBasis && m_inputFormat.classIndex() >= 0 && m_inputFormat.classAttribute().isNominal() ?
      m_inputFormat.numClasses() : 1;
 m_dictsPerClass =
  m_sortDictionary ? new TreeMap[m_numClasses]
   : new LinkedHashMap[m_numClasses];
 m_classIndex = m_inputFormat.classIndex();
 for (int i = 0; i < m_numClasses; i++) {
  m_dictsPerClass[i] =
   m_sortDictionary ? new TreeMap<String, int[]>()
    : new LinkedHashMap<String, int[]>();
 }
 determineSelectedRange(inputFormat);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@SuppressWarnings("unchecked")
public void setup(Instances inputFormat) throws Exception {
 m_inputContainsStringAttributes = inputFormat.checkForStringAttributes();
 m_inputFormat = inputFormat.stringFreeStructure();
 if (!m_inputContainsStringAttributes) {
  return;
 }
 m_numClasses =
  !m_doNotOperateOnPerClassBasis && m_inputFormat.classIndex() >= 0 && m_inputFormat.classAttribute().isNominal() ?
      m_inputFormat.numClasses() : 1;
 m_dictsPerClass =
  m_sortDictionary ? new TreeMap[m_numClasses]
   : new LinkedHashMap[m_numClasses];
 m_classIndex = m_inputFormat.classIndex();
 for (int i = 0; i < m_numClasses; i++) {
  m_dictsPerClass[i] =
   m_sortDictionary ? new TreeMap<String, int[]>()
    : new LinkedHashMap<String, int[]>();
 }
 determineSelectedRange(inputFormat);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * If possible, get the output structure for the named connection type as a
 * header-only set of instances. Can return null if the specified connection
 * type is not representable as Instances or cannot be determined at present.
 *
 * @param connectionName the name of the connection type to get the output
 *          structure for
 * @return the output structure as a header-only Instances object
 * @throws WekaException if a problem occurs
 */
@Override
public Instances outputStructureForConnectionType(String connectionName)
 throws WekaException {
 if (getStepManager().isStepBusy()) {
  return null;
 }
 if (getStepManager().numOutgoingConnectionsOfType(StepManager.CON_DATASET) == 0
  && getStepManager()
   .numOutgoingConnectionsOfType(StepManager.CON_INSTANCE) == 0) {
  return null;
 }
 try {
  return new Instances(new StringReader(m_data)).stringFreeStructure();
 } catch (IOException e) {
  throw new WekaException(e);
 }
}

代码示例来源:origin: Waikato/weka-trunk

m_OutputFormat = m_OutputFormat.stringFreeStructure();
m_OutputStringAtts = new StringLocator(m_OutputFormat,
 m_OutputStringAtts.getAllowedIndices());

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

m_OutputFormat = m_OutputFormat.stringFreeStructure();
m_OutputStringAtts = new StringLocator(m_OutputFormat,
 m_OutputStringAtts.getAllowedIndices());

代码示例来源:origin: Waikato/weka-trunk

/**
 * This will remove all buffered instances from the inputformat dataset. Use
 * this method rather than getInputFormat().delete();
 */
protected void flushInput() {
 if ((m_InputStringAtts.getAttributeIndices().length > 0)
  || (m_InputRelAtts.getAttributeIndices().length > 0)) {
  m_InputFormat = m_InputFormat.stringFreeStructure();
  m_InputStringAtts =
   new StringLocator(m_InputFormat, m_InputStringAtts.getAllowedIndices());
  m_InputRelAtts = new RelationalLocator(m_InputFormat,
   m_InputRelAtts.getAllowedIndices());
 } else {
  // This more efficient than new Instances(m_InputFormat, 0);
  m_InputFormat.delete();
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Build the clusterer on the filtered data.
 * 
 * @param data the training data
 * @throws Exception if the clusterer could not be built successfully
 */
@Override
public void buildClusterer(Instances data) throws Exception {
 if (m_Clusterer == null) {
  throw new Exception("No base clusterer has been set!");
 }
 // remove instances with missing class
 if (data.classIndex() > -1) {
  data = new Instances(data);
  data.deleteWithMissingClass();
 }
 m_Filter.setInputFormat(data); // filter capabilities are checked here
 data = Filter.useFilter(data, m_Filter);
 // can clusterer handle the data?
 getClusterer().getCapabilities().testWithFail(data);
 m_FilteredInstances = data.stringFreeStructure();
 m_Clusterer.buildClusterer(data);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * This will remove all buffered instances from the inputformat dataset. Use
 * this method rather than getInputFormat().delete();
 */
protected void flushInput() {
 if ((m_InputStringAtts.getAttributeIndices().length > 0)
  || (m_InputRelAtts.getAttributeIndices().length > 0)) {
  m_InputFormat = m_InputFormat.stringFreeStructure();
  m_InputStringAtts =
   new StringLocator(m_InputFormat, m_InputStringAtts.getAllowedIndices());
  m_InputRelAtts = new RelationalLocator(m_InputFormat,
   m_InputRelAtts.getAllowedIndices());
 } else {
  // This more efficient than new Instances(m_InputFormat, 0);
  m_InputFormat.delete();
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Build the clusterer on the filtered data.
 * 
 * @param data the training data
 * @throws Exception if the clusterer could not be built successfully
 */
@Override
public void buildClusterer(Instances data) throws Exception {
 if (m_Clusterer == null) {
  throw new Exception("No base clusterer has been set!");
 }
 // remove instances with missing class
 if (data.classIndex() > -1) {
  data = new Instances(data);
  data.deleteWithMissingClass();
 }
 m_Filter.setInputFormat(data); // filter capabilities are checked here
 data = Filter.useFilter(data, m_Filter);
 // can clusterer handle the data?
 getClusterer().getCapabilities().testWithFail(data);
 m_FilteredInstances = data.stringFreeStructure();
 m_Clusterer.buildClusterer(data);
}

代码示例来源:origin: Waikato/meka

/**
 * Sets up the filter and runs checks.
 *
 * @return filtered data
 */
protected Instances setUp(Instances data) throws Exception {
  String      relName;
  String      classAtt;
  relName  = data.relationName();
  classAtt = data.classAttribute().name();
  if (m_Classifier == null)
    throw new Exception("No base classifiers have been set!");
  getCapabilities().testWithFail(data);
  // get fresh instances object
  data = new Instances(data);
  Attribute classAttribute = (Attribute)data.classAttribute().copy();
  m_Filter.setInputFormat(data); // filter capabilities are checked here
  data = Filter.useFilter(data, m_Filter);
  if ((!classAttribute.equals(data.classAttribute())) && (!m_DoNotCheckForModifiedClassAttribute))
    throw new IllegalArgumentException("Cannot proceed: " + getFilterSpec() + " has modified the class attribute!");
  data.setRelationName(relName);
  data.setClassIndex(data.attribute(classAtt).index());
  // can classifier handle the data?
  testCapabilities(data);
  m_FilteredInstances = data.stringFreeStructure();
  return data;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Build the associator on the filtered data.
 * 
 * @param data the training data
 * @throws Exception if the Associator could not be built successfully
 */
@Override
public void buildAssociations(Instances data) throws Exception {
 if (m_Associator == null) {
  throw new Exception("No base associator has been set!");
 }
 // create copy and set class-index
 data = new Instances(data);
 if (getClassIndex() == 0) {
  data.setClassIndex(data.numAttributes() - 1);
 } else {
  data.setClassIndex(getClassIndex() - 1);
 }
 if (getClassIndex() != -1) {
  // remove instances with missing class
  data.deleteWithMissingClass();
 }
 m_Filter.setInputFormat(data); // filter capabilities are checked here
 data = Filter.useFilter(data, m_Filter);
 // can associator handle the data?
 getAssociator().getCapabilities().testWithFail(data);
 m_FilteredInstances = data.stringFreeStructure();
 m_Associator.buildAssociations(data);
}

代码示例来源:origin: Waikato/weka-trunk

m_streamingFilter.batchFinished();
Instances structureCopy =
 m_streamingFilter.getOutputFormat().stringFreeStructure();
while (m_streamingFilter.numPendingOutput() > 0) {
 getStepManager().throughputUpdateStart();

相关文章

Instances类方法