/** * Provides a much faster way of serialization. * * @return a byte array that can be read with the corresponding method. * @see CEDD#setByteArrayRepresentation(byte[]) */ @Override public byte[] getByteArrayRepresentation() { return SerializationUtils.toByteArray(feature); }
/** * by patch contributed by Franz Graf, franz.graf@gmail.com * @return the feature vector as double[] */ @Override public double[] getFeatureVector() { return SerializationUtils.toDoubleArray(descriptorValues); }
@Override public double[] getFeatureVector() { return SerializationUtils.castToDoubleArray(histogram); }
document.add(new TextField(featureFieldName + "_hash", SerializationUtils.arrayToString(hashes), Field.Store.YES));
@Override public void setByteArrayRepresentation(byte[] in) { int[] result = SerializationUtils.toIntArray(in); NumberOfBitplanesDiscarded = result[0]; NumberOfCoefficients = result[1]; haarTransformedHistogram = new int[result.length - 2]; for (int i = 2; i < result.length; i++) { haarTransformedHistogram[i - 2] = result[i]; } }
/** * Converts a byte array with 4 elements to a float. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float)} to encode. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float) */ public static float toFloat(byte[] data) { return Float.intBitsToFloat(toInt(data)); }
/** * Converts a float to a byte array with 4 elements. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toFloat(byte[])} to decode. * * @param data the float to convert * @return the resulting byte array * @see net.semanticmetadata.lire.utils.SerializationUtils#toFloat(byte[]) */ public static byte[] toBytes(float data) { return toBytes(Float.floatToRawIntBits(data)); }
/** * Convenience method for creating a float array from a byte array. * * @param data * @return */ public static float[] toFloatArray(byte[] data) { float[] result = new float[data.length / 4]; byte[] tmp = new byte[4]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 4, tmp, 0, 4); result[i] = toFloat(tmp); } return result; }
/** * Convenience method for creating a double array from a byte array. * * @param data * @return */ public static double[] toDoubleArray(byte[] data) { double[] result = new double[data.length / 8]; byte[] tmp = new byte[8]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 8, tmp, 0, 8); result[i] = toDouble(tmp); } return result; }
/** * Converts a byte array with 4 elements to a double. Used to put doubles into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(double)} to encode. Note that there is a loss * in precision as the double is converted to a float in the course of conversion. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(double) */ public static double toDouble(byte[] data) { return Double.longBitsToDouble(toLong(data)); }
document.add(new TextField(featureFieldName + "_hash", SerializationUtils.arrayToString(hashes), Field.Store.YES));
@Override public void setByteArrayRepresentation(byte[] in) { int[] result = SerializationUtils.toIntArray(in); NumberOfBitplanesDiscarded = result[0]; NumberOfCoefficients = result[1]; haarTransformedHistogram = new int[result.length - 2]; for (int i = 2; i < result.length; i++) { haarTransformedHistogram[i - 2] = result[i]; } }
public static int[] toIntArray(byte[] in, int offset, int length) { int[] result = new int[(length >> 2)]; byte[] tmp = new byte[4]; for (int i = 0; i < length >> 2; i++) { System.arraycopy(in, offset + (i * 4), tmp, 0, 4); result[i] = toInt(tmp); } return result; }
/** * Converts a float to a byte array with 4 elements. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toFloat(byte[])} to decode. * * @param data the float to convert * @return the resulting byte array * @see net.semanticmetadata.lire.utils.SerializationUtils#toFloat(byte[]) */ public static byte[] toBytes(float data) { return toBytes(Float.floatToRawIntBits(data)); }
/** * Convenience method for creating a float array from a byte array. * * @param data * @return */ public static float[] toFloatArray(byte[] data) { float[] result = new float[data.length / 4]; byte[] tmp = new byte[4]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 4, tmp, 0, 4); result[i] = toFloat(tmp); } return result; }
/** * Convenience method for creating a double array from a byte array. * * @param data * @return */ public static double[] toDoubleArray(byte[] data) { double[] result = new double[data.length / 8]; byte[] tmp = new byte[8]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 8, tmp, 0, 8); result[i] = toDouble(tmp); } return result; }
/** * Converts a byte array with 4 elements to a double. Used to put doubles into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(double)} to encode. Note that there is a loss * in precision as the double is converted to a float in the course of conversion. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(double) */ public static double toDouble(byte[] data) { return Double.longBitsToDouble(toLong(data)); }
/** * Returns the vector representation in byte[] format. * @return the vector representation as a byte array. */ @Override public byte[] getByteVectorRepresentation() { return SerializationUtils.toByteArray(vector); }
/** * by patch contributed by Franz Graf, franz.graf@gmail.com * @return the feature vector as double[] */ @Override public double[] getFeatureVector() { return SerializationUtils.toDoubleArray(descriptorValues); }
@Override public void run() { try { QueueItem data = queue.take(); while (data.id != null) { document.clear(); document.put(DocumentBuilder.FIELD_NAME_IDENTIFIER, data.id); document.put("title", data.id); for (Iterator<GlobalFeature> iterator = data.features.iterator(); iterator.hasNext(); ) { GlobalFeature f = iterator.next(); document.put(f.getFieldName(), f.getByteArrayRepresentation()); if (doHashingBitSampling) { document.put(f.getFieldName() + DocumentBuilder.HASH_FIELD_SUFFIX, SerializationUtils.arrayToString((BitSampling.generateHashes(f.getFeatureVector())))); } else if (doMetricSpaceIndexing) { if (MetricSpaces.supportsFeature(f)) { document.put(f.getFieldName() + DocumentBuilder.HASH_FIELD_SUFFIX, MetricSpaces.generateHashString(f)); } } } output(document); data = queue.take(); } } catch (InterruptedException e) { e.printStackTrace(); } }