<commit_before>package edu.cmu.cs.diamond.opendiamond;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // get scopes
        List<Scope> scopes = ScopeSource.getPredefinedScopeList();
        for (Scope scope : scopes) {
            System.out.println(scope);
        }

        // use first scope
        Scope scope = scopes.get(0);

        // set up the rgb filter
        Filter rgb = null;
        try {
            FilterCode c = new FilterCode(new FileInputStream(
                    "/opt/diamond/lib/fil_rgb.a"));
            rgb = new Filter("RGB", c, "f_eval_img2rgb", "f_init_img2rgb",
                    "f_fini_img2rgb", 1, new String[0], new String[0], 400);
            System.out.println(rgb);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // make a new search
        Search search = new Search();
        search.setScope(scope);

        // make a new searchlet
        Searchlet searchlet = new Searchlet();
        searchlet.addFilter(rgb);
        searchlet.setApplicationDependencies(new String[] { "RGB" });
        try {
            search.setSearchlet(searchlet);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // begin search
        search.startSearch();

        // read 10 results
        Result r;
        int count = 0;
        while ((r = search.getNextResult()) != null && count < 10) {
            System.out.println(r);

            byte data[] = r.getData();
            // try {
            // DataOutputStream fout = new DataOutputStream(new
            // FileOutputStream("/tmp/zz.jpg"));
            // fout.write(data);
            // fout.close();
            // } catch (FileNotFoundException e1) {
            // e1.printStackTrace();
            // } catch (IOException e) {
            // // TODO Auto-generated catch block
            // e.printStackTrace();
            // }

            try {
                // try reading the data
                ByteArrayInputStream in = new ByteArrayInputStream(data);
                BufferedImage img = ImageIO.read(in);

                // else, try the other one
                data = r.getValue("_rgb_image.rgbimage".getBytes());
                byte tmp[] = r.getValue("_cols.int".getBytes());
                int w = (tmp[3] & 0xFF) << 24 | (tmp[2] & 0xFF) << 16
                        | (tmp[1] & 0xFF) << 8 | (tmp[0] & 0xFF);
                tmp = r.getValue("_rows.int".getBytes());
                int h = (tmp[3] & 0xFF) << 24 | (tmp[2] & 0xFF) << 16<commit_msg>cleanup<commit_after>package edu.cmu.cs.diamond.opendiamond;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // get scopes
        List<Scope> scopes = ScopeSource.getPredefinedScopeList();
        for (Scope scope : scopes) {
            System.out.println(scope);
        }

        // use first scope
        Scope scope = scopes.get(0);

        // set up the rgb filter
        Filter rgb = null;
        try {
            FilterCode c = new FilterCode(new FileInputStream(
                    "/opt/diamond/lib/fil_rgb.a"));
            rgb = new Filter("RGB", c, "f_eval_img2rgb", "f_init_img2rgb",
                    "f_fini_img2rgb", 1, new String[0], new String[0], 400);
            System.out.println(rgb);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // make a new search
        Search search = new Search();
        search.setScope(scope);

        // make a new searchlet
        Searchlet searchlet = new Searchlet();
        searchlet.addFilter(rgb);
        searchlet.setApplicationDependencies(new String[] { "RGB" });
        try {
            search.setSearchlet(searchlet);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // begin search
        search.startSearch();

        // read 10 results
        Result r;
        int count = 0;
        while ((r = search.getNextResult()) != null && count < 10) {
            System.out.println(r);

            byte data[] = r.getData();

            try {
                // try reading the data
                ByteArrayInputStream in = new ByteArrayInputStream(data);
                BufferedImage img = ImageIO.read(in);

                // else, try the other one
                data = r.getValue("_rgb_image.rgbimage".getBytes());
                byte tmp[] = r.getValue("_cols.int".getBytes());
                int w = (tmp[3] & 0xFF) << 24 | (tmp[2] & 0xFF) << 16
                        | (tmp[1] & 0xFF) << 8 | (tmp[0] & 0xFF);
                tmp = r.getValue("_rows.int".getBytes());
                int h = (tmp[3] & 0xFF) << 24 | (tmp[2] & 0xFF) << 16
{'fraction_non_alphanumeric': 0.12623628843733142, 'fraction_numerical': 0.013306959180003597, 'mean_word_length': 1.731827111984283, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6125107', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1538, 'n_words': 375}