// Path: src/main/java/net/semanticmetadata/lire/solr/HashingMetricSpacesManager.java
// public class HashingMetricSpacesManager {
//     /**
//      * Pre-load the static members of MetricSpaces to make sure hash generation is on time.
//      */
//     public static void init() {
//         ClassLoader classloader = Thread.currentThread().getContextClassLoader();
//         try {
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_CEDD.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_ColorLayout.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_EdgeHistogram.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_FCTH.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_OpponentHistogram.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_PHOG.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/jpg_us_filter_JCD.msd.gz")));
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         try {
//             BitSampling.readHashFunctions(classloader.getResourceAsStream("lsh/LshBitSampling_2048.obj")); // load BitSampling data from disk.
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//     }
// }


import net.semanticmetadata.lire.imageanalysis.features.global.GenericGlobalShortFeature;
import net.semanticmetadata.lire.indexers.hashing.BitSampling;
import net.semanticmetadata.lire.solr.HashingMetricSpacesManager;
import org.apache.solr.common.util.XML;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import java.io.*;
import java.util.Base64;
package net.semanticmetadata.lire.solr.tools;



public class EncodeAndHashStax {
    static BufferedWriter bw;
    public static void main(String[] args) throws XMLStreamException, IOException {
        HashingMetricSpacesManager.init();

        bw = new BufferedWriter(new FileWriter("150k_out.xml"));

        StringBuilder sb = new StringBuilder();
        String hashes = null;

        XMLInputFactory f = XMLInputFactory.newInstance();
        XMLStreamReader r = f.createXMLStreamReader(new FileInputStream("images_150k_cat.xml"));
        boolean isInRelevantTag = false;
        boolean skipTag = false;
        while(r.hasNext()) {
            int state = r.next();
            if (state == XMLEvent.START_ELEMENT) {
                if (r.getLocalName().equals("field")) {
                    String ft = r.getAttributeValue(0);
                    if (ft.equals("sf_hi")) isInRelevantTag = true;
                    if (!ft.equals("sf_ha")) {
                        write("<" + r.getLocalName() + " name=\""+ft+"\">");
                    } else skipTag = true;
                } else {
                    write("<" + r.getLocalName() + ">");
                }
            } else if (state == XMLEvent.CHARACTERS) {
// Path: src/main/java/net/semanticmetadata/lire/solr/HashingMetricSpacesManager.java
// public class HashingMetricSpacesManager {
//     /**
//      * Pre-load the static members of MetricSpaces to make sure hash generation is on time.
//      */
//     public static void init() {
//         ClassLoader classloader = Thread.currentThread().getContextClassLoader();
//         try {
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_CEDD.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_ColorLayout.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_EdgeHistogram.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_FCTH.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_OpponentHistogram.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/logos-ca-ee_PHOG.msd.gz")));
//             MetricSpaces.loadReferencePoints(new GZIPInputStream(classloader.getResourceAsStream("metricspaces/jpg_us_filter_JCD.msd.gz")));
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         try {
//             BitSampling.readHashFunctions(classloader.getResourceAsStream("lsh/LshBitSampling_2048.obj")); // load BitSampling data from disk.
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//     }
// }


// Path: src/main/java/net/semanticmetadata/lire/solr/tools/EncodeAndHashStax.java
import net.semanticmetadata.lire.imageanalysis.features.global.GenericGlobalShortFeature;
import net.semanticmetadata.lire.indexers.hashing.BitSampling;
import net.semanticmetadata.lire.solr.HashingMetricSpacesManager;
import org.apache.solr.common.util.XML;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import java.io.*;
import java.util.Base64;

package net.semanticmetadata.lire.solr.tools;



public class EncodeAndHashStax {
    static BufferedWriter bw;
    public static void main(String[] args) throws XMLStreamException, IOException {
        HashingMetricSpacesManager.init();

        bw = new BufferedWriter(new FileWriter("150k_out.xml"));

        StringBuilder sb = new StringBuilder();
        String hashes = null;

        XMLInputFactory f = XMLInputFactory.newInstance();
        XMLStreamReader r = f.createXMLStreamReader(new FileInputStream("images_150k_cat.xml"));
        boolean isInRelevantTag = false;
        boolean skipTag = false;
        while(r.hasNext()) {
            int state = r.next();
            if (state == XMLEvent.START_ELEMENT) {
                if (r.getLocalName().equals("field")) {
                    String ft = r.getAttributeValue(0);
                    if (ft.equals("sf_hi")) isInRelevantTag = true;
                    if (!ft.equals("sf_ha")) {
                        write("<" + r.getLocalName() + " name=\""+ft+"\">");
                    } else skipTag = true;
                } else {
                    write("<" + r.getLocalName() + ">");
                }
            } else if (state == XMLEvent.CHARACTERS) {
                if (!isInRelevantTag)