protected void displayNewTxf(String strLabel, String strValue) { strLabel = (strLabel == null) ? "" : strLabel.trim(); strValue = (strValue == null) ? "" : strValue.trim(); JCheckBox chkBox1 = new JCheckBox(Util.getImageIcon("boxGray.gif")); DataField txf1 = new DataField(strLabel); DataField txf2 = new DataField(strValue); JPanel pnlTxf = new JPanel(m_gbl); m_nRow = m_nRow + 1; txf1.setName("label"); txf2.setName("value"); /* 1st line of text field*/ m_gbc.weightx = 0; showComp(m_gbl, m_gbc, 0, m_nRow, 1, chkBox1); m_gbc.weightx = 1; showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf1); // showSpaces( gbl, gbc, 2, 6 ); showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf2); m_gbc.weightx = 0; txf1.addFocusListener(this); txf2.addFocusListener(this); m_objTxfValue.addToLabel(txf1); m_objTxfValue.addToValue(txf2); }
protected void toXml(Record record) throws SAXException { if (!MarcFactory.newInstance().validateRecord(record)) { throw new MarcException("Marc record didn't validate"); } char temp[]; AttributesImpl atts = new AttributesImpl(); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); handler.startElement(Constants.MARCXML_NS_URI, RECORD, RECORD, atts); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, LEADER, LEADER, atts); Leader leader = record.getLeader(); temp = leader.toString().toCharArray(); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, LEADER, LEADER); for (ControlField field : record.getControlFields()) { atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD, atts); temp = getDataElement(field.getData()); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD); } for (DataField field : record.getDataFields()) { atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); atts.addAttribute("", "ind1", "ind1", "CDATA", String.valueOf(field.getIndicator1())); atts.addAttribute("", "ind2", "ind2", "CDATA", String.valueOf(field.getIndicator2())); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD, atts); for (Subfield subfield : field.getSubfields()) { atts = new AttributesImpl(); atts.addAttribute("", "code", "code", "CDATA", String.valueOf(subfield.getCode())); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 7); handler.startElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD, atts); temp = getDataElement(subfield.getData()); handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD); } if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler.endElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD); } if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); handler.endElement(Constants.MARCXML_NS_URI, RECORD, RECORD); }
/* * Decode a tar file header. The stream is assumed to be at the beginning of the header. */ private TarFile decodeNextFile() throws IOException { byte[] buffer = new byte[TAR_FILE_GRANULARITY]; // A header must be present for an OVA component file to be available.. this.inputStream.readFully(buffer); // If last two empty sections of the TAR file were reached, exit. String signature = SIGNATURE_FIELD.getFirstFieldValue(buffer); if (!TAR_SIGNATURE.equals(signature)) { logger.error("Invalid file signature: '{}'", signature); logger.error("Input stream buffer content: [{}]", buffer); return null; } // Get embedded file name. TarFile fileInfo = new TarFile(); fileInfo.name = NAME_FIELD.getFirstFieldValue(buffer); // Get embedded file length. String octalByteLength = OCTAL_BYTE_LENGTH_FIELD.getFirstFieldValue(buffer); long fileByteLength = Long.parseLong(octalByteLength.trim(), 8 /* octal base */); // Get embedded file content. fileInfo.content = getFileContentStream(fileByteLength); return fileInfo; }
public static StreamElement createElementFromREST( DataField[] outputFormat, String[] fieldNames, Object[] fieldValues) { ArrayList<Serializable> values = new ArrayList<Serializable>(); // ArrayList<String> fields = new ArrayList<String>(); long timestamp = -1; for (int i = 0; i < fieldNames.length; i++) { if (fieldNames[i].equalsIgnoreCase("TIMED")) { timestamp = Long.parseLong((String) fieldValues[i]); continue; } boolean found = false; for (DataField f : outputFormat) { if (f.getName().equalsIgnoreCase(fieldNames[i])) { // fields.add(fieldNames[i]); found = true; break; } } if (found == false) continue; switch (findIndexInDataField(outputFormat, fieldNames[i])) { case DataTypes.DOUBLE: values.add(Double.parseDouble((String) fieldValues[i])); break; case DataTypes.BIGINT: values.add(Long.parseLong((String) fieldValues[i])); break; case DataTypes.TINYINT: values.add(Byte.parseByte((String) fieldValues[i])); break; case DataTypes.SMALLINT: values.add(Short.parseShort((String) fieldValues[i])); break; case DataTypes.INTEGER: values.add(Integer.parseInt((String) fieldValues[i])); break; case DataTypes.CHAR: case DataTypes.VARCHAR: values.add(new String((byte[]) fieldValues[i])); break; case DataTypes.BINARY: try { // StreamElementTest.md5Digest(fieldValues[ i ]); } catch (Exception e) { e.printStackTrace(); } values.add((byte[]) fieldValues[i]); break; case -1: default: logger.error( "The field name doesn't exit in the output structure : FieldName : " + (String) fieldNames[i]); } } if (timestamp == -1) timestamp = System.currentTimeMillis(); return new StreamElement(outputFormat, values.toArray(new Serializable[] {}), timestamp); }
public Object clone() { DataField field = new DataField(); field.setName(getName()); field.setValue(value); field.setDataType(dataType); field.setAppend(this.getAppend()); return field; }
@Override protected void set(int index, int value) { if (index == 0) { return; } super.set(index, value); }
protected void displayNewTxf(String strLabel, String strValue) { strLabel = (strLabel != null) ? strLabel.trim() : ""; strValue = (strValue != null) ? strValue.trim() : ""; JCheckBox chk1 = new JCheckBox(Util.getImageIcon("boxGray.gif")); final DataField txf1 = new DataField(strLabel); final DataField txf2 = new DataField(strValue); m_nRow = m_nRow + 1; txf1.setName("label"); txf2.setName("value"); // new field if (strLabel.equals("") && strValue.equals("")) { txf2.setText(INFOSTR); txf2.addMouseListener(m_mlTxf); if (timer != null) timer.cancel(); timer = new java.util.Timer(); timer.schedule( new TimerTask() { public void run() { WUtil.blink(txf2, WUtil.FOREGROUND); } }, delay, delay); } /* 1st line of text field*/ m_gbc.weightx = 0; showComp(m_gbl, m_gbc, 0, m_nRow, 1, chk1); m_gbc.weightx = 1; showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf1); // showSpaces( gbl, gbc, 2, 6 ); showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf2); m_gbc.weightx = 0; txf1.addFocusListener(this); txf2.addFocusListener(this); // Add the textfields to the respective arrays, so that they // can be retreived later for writing to the file. m_objTxfValue.addToLabel(txf1); m_objTxfValue.addToValue(txf2); }
public void print() { System.out.println( "PK " + getUri() + " " + fieldStr.getName() + " " + getStringField(fieldStr) + " " + getLongField(fieldInt) + " " + getNumericField(fieldDbl) + " " + getDateField(fieldDate) + " " + getBooleanField(fieldBool)); }
public static PMML generateSimpleNeuralNetwork( String modelName, String[] inputfieldNames, String[] outputfieldNames, double[] inputMeans, double[] inputStds, double[] outputMeans, double[] outputStds, int hiddenSize, double[] weights) { int counter = 0; int wtsIndex = 0; PMML pmml = new PMML(); pmml.setVersion("4.0"); Header header = new Header(); Application app = new Application(); app.setName("Drools PMML Generator"); app.setVersion("0.01 Alpha"); header.setApplication(app); header.setCopyright("BSD"); header.setDescription(" Smart Vent Model "); Timestamp ts = new Timestamp(); ts.getContent().add(new java.util.Date().toString()); header.setTimestamp(ts); pmml.setHeader(header); DataDictionary dic = new DataDictionary(); dic.setNumberOfFields(BigInteger.valueOf(inputfieldNames.length + outputfieldNames.length)); for (String ifld : inputfieldNames) { DataField dataField = new DataField(); dataField.setName(ifld); dataField.setDataType(DATATYPE.DOUBLE); dataField.setDisplayName(ifld); dataField.setOptype(OPTYPE.CONTINUOUS); dic.getDataFields().add(dataField); } for (String ofld : outputfieldNames) { DataField dataField = new DataField(); dataField.setName(ofld); dataField.setDataType(DATATYPE.DOUBLE); dataField.setDisplayName(ofld); dataField.setOptype(OPTYPE.CONTINUOUS); dic.getDataFields().add(dataField); } pmml.setDataDictionary(dic); NeuralNetwork nnet = new NeuralNetwork(); nnet.setActivationFunction(ACTIVATIONFUNCTION.LOGISTIC); nnet.setFunctionName(MININGFUNCTION.REGRESSION); nnet.setNormalizationMethod(NNNORMALIZATIONMETHOD.NONE); nnet.setModelName(modelName); MiningSchema miningSchema = new MiningSchema(); for (String ifld : inputfieldNames) { MiningField mfld = new MiningField(); mfld.setName(ifld); mfld.setOptype(OPTYPE.CONTINUOUS); mfld.setUsageType(FIELDUSAGETYPE.ACTIVE); miningSchema.getMiningFields().add(mfld); } for (String ofld : outputfieldNames) { MiningField mfld = new MiningField(); mfld.setName(ofld); mfld.setOptype(OPTYPE.CONTINUOUS); mfld.setUsageType(FIELDUSAGETYPE.PREDICTED); miningSchema.getMiningFields().add(mfld); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(miningSchema); Output outputs = new Output(); for (String ofld : outputfieldNames) { OutputField outFld = new OutputField(); outFld.setName("Out_" + ofld); outFld.setTargetField(ofld); outputs.getOutputFields().add(outFld); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(outputs); NeuralInputs nins = new NeuralInputs(); nins.setNumberOfInputs(BigInteger.valueOf(inputfieldNames.length)); for (int j = 0; j < inputfieldNames.length; j++) { String ifld = inputfieldNames[j]; NeuralInput nin = new NeuralInput(); nin.setId("" + counter++); DerivedField der = new DerivedField(); der.setDataType(DATATYPE.DOUBLE); der.setOptype(OPTYPE.CONTINUOUS); NormContinuous nc = new NormContinuous(); nc.setField(ifld); nc.setOutliers(OUTLIERTREATMENTMETHOD.AS_IS); LinearNorm lin1 = new LinearNorm(); lin1.setOrig(0); lin1.setNorm(-inputMeans[j] / inputStds[j]); nc.getLinearNorms().add(lin1); LinearNorm lin2 = new LinearNorm(); lin2.setOrig(inputMeans[j]); lin2.setNorm(0); nc.getLinearNorms().add(lin2); der.setNormContinuous(nc); nin.setDerivedField(der); nins.getNeuralInputs().add(nin); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(nins); NeuralLayer hidden = new NeuralLayer(); hidden.setNumberOfNeurons(BigInteger.valueOf(hiddenSize)); for (int j = 0; j < hiddenSize; j++) { Neuron n = new Neuron(); n.setId("" + counter++); n.setBias(weights[wtsIndex++]); for (int k = 0; k < inputfieldNames.length; k++) { Synapse con = new Synapse(); con.setFrom("" + k); con.setWeight(weights[wtsIndex++]); n.getCons().add(con); } hidden.getNeurons().add(n); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(hidden); NeuralLayer outer = new NeuralLayer(); outer.setActivationFunction(ACTIVATIONFUNCTION.IDENTITY); outer.setNumberOfNeurons(BigInteger.valueOf(outputfieldNames.length)); for (int j = 0; j < outputfieldNames.length; j++) { Neuron n = new Neuron(); n.setId("" + counter++); n.setBias(weights[wtsIndex++]); for (int k = 0; k < hiddenSize; k++) { Synapse con = new Synapse(); con.setFrom("" + (k + inputfieldNames.length)); con.setWeight(weights[wtsIndex++]); n.getCons().add(con); } outer.getNeurons().add(n); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(outer); NeuralOutputs finalOuts = new NeuralOutputs(); finalOuts.setNumberOfOutputs(BigInteger.valueOf(outputfieldNames.length)); for (int j = 0; j < outputfieldNames.length; j++) { NeuralOutput output = new NeuralOutput(); output.setOutputNeuron("" + (j + inputfieldNames.length + hiddenSize)); DerivedField der = new DerivedField(); der.setDataType(DATATYPE.DOUBLE); der.setOptype(OPTYPE.CONTINUOUS); NormContinuous nc = new NormContinuous(); nc.setField(outputfieldNames[j]); nc.setOutliers(OUTLIERTREATMENTMETHOD.AS_IS); LinearNorm lin1 = new LinearNorm(); lin1.setOrig(0); lin1.setNorm(-outputMeans[j] / outputStds[j]); nc.getLinearNorms().add(lin1); LinearNorm lin2 = new LinearNorm(); lin2.setOrig(outputMeans[j]); lin2.setNorm(0); nc.getLinearNorms().add(lin2); der.setNormContinuous(nc); output.setDerivedField(der); finalOuts.getNeuralOutputs().add(output); } nnet.getExtensionsAndNeuralLayersAndNeuralInputs().add(finalOuts); pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(nnet); return pmml; }
/** * Save the data fields. * * @param out The output file. */ private void saveData(final EncogWriteHelper out) { saveSubSection(out, "DATA", "CONFIG"); out.addSubSection("STATS"); out.addColumn("name"); out.addColumn("isclass"); out.addColumn("iscomplete"); out.addColumn("isint"); out.addColumn("isreal"); out.addColumn("amax"); out.addColumn("amin"); out.addColumn("mean"); out.addColumn("sdev"); out.writeLine(); for (final DataField field : this.script.getFields()) { out.addColumn(field.getName()); out.addColumn(field.isClass()); out.addColumn(field.isComplete()); out.addColumn(field.isInteger()); out.addColumn(field.isReal()); out.addColumn(field.getMax()); out.addColumn(field.getMin()); out.addColumn(field.getMean()); out.addColumn(field.getStandardDeviation()); out.writeLine(); } out.flush(); out.addSubSection("CLASSES"); out.addColumn("field"); out.addColumn("code"); out.addColumn("name"); out.writeLine(); for (final DataField field : this.script.getFields()) { if (field.isClass()) { for (final AnalystClassItem col : field.getClassMembers()) { out.addColumn(field.getName()); out.addColumn(col.getCode()); out.addColumn(col.getName()); out.addColumn(col.getCount()); out.writeLine(); } } } }