/** Sorts the index in the order of the date of publication of the posts. */ protected void sortIndexes() { for (SingleIndex s : indexList) { for (int i = 0; i < postsPerIndex && !queue.isEmpty(); i++) { s.getPosts().add(queue.remove()); } } }
/** * Sets the format of the input instances. * * @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 format couldn't be set successfully */ public boolean setInputFormat(Instances instanceInfo) throws Exception { super.setInputFormat(instanceInfo); m_Insert.setUpper(instanceInfo.numAttributes()); Instances outputFormat = new Instances(instanceInfo, 0); Attribute newAttribute = null; switch (m_AttributeType) { case Attribute.NUMERIC: newAttribute = new Attribute(m_Name); break; case Attribute.NOMINAL: newAttribute = new Attribute(m_Name, m_Labels); break; case Attribute.STRING: newAttribute = new Attribute(m_Name, (FastVector) null); break; case Attribute.DATE: newAttribute = new Attribute(m_Name, m_DateFormat); break; default: throw new IllegalArgumentException("Unknown attribute type in Add"); } if ((m_Insert.getIndex() < 0) || (m_Insert.getIndex() > getInputFormat().numAttributes())) { throw new IllegalArgumentException("Index out of range"); } outputFormat.insertAttributeAt(newAttribute, m_Insert.getIndex()); setOutputFormat(outputFormat); // all attributes, except index of added attribute // (otherwise the length of the input/output indices differ) Range atts = new Range(m_Insert.getSingleIndex()); atts.setInvert(true); atts.setUpper(outputFormat.numAttributes() - 1); initOutputLocators(outputFormat, atts.getSelection()); return true; }
/** * Input an instance for filtering. Ordinarily the instance is processed and made available for * output immediately. Some filters require all instances be read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input format has been defined. */ public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } Instance inst = (Instance) instance.copy(); // First copy string values from input to output copyValues(inst, true, inst.dataset(), getOutputFormat()); // Insert the new attribute and reassign to output inst.setDataset(null); inst.insertAttributeAt(m_Insert.getIndex()); inst.setDataset(getOutputFormat()); push(inst); return true; }
/** * Sets index of the attribute used. * * @param attIndex the index of the attribute */ public void setAttributeIndex(String attIndex) { m_Insert.setSingleIndex(attIndex); }
/** * Get the index of the attribute used. * * @return the index of the attribute */ public String getAttributeIndex() { return m_Insert.getSingleIndex(); }