<commit_before><commit_msg>add IndexBuilder for review_polarity<commit_after>package edu.neu.ccs.pyramid.data_formatter.review_polarity;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

import java.io.File;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by chengli on 10/24/14.
 */
public class IndexBuilder {

    static String getBody(File file) throws Exception{
        String entireFileText = new Scanner(file)
                .useDelimiter("\\A").next();
        return entireFileText;
    }

    static String getFileName(File file) throws Exception{
        String fullPath = file.getAbsolutePath();
        return fullPath;
    }

    public static XContentBuilder getBuilder(File file) throws Exception{
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject();
        builder.field("body",getBody(file));
        builder.field("file_name",getFileName(file));
        builder.array("real_label", getRealLabel(file));
        builder.array("label",getLabel(file));
        builder.field("split",getTrainOrTest());
        builder.endObject();
        return builder;
    }

    static String getLabel(File file){
        String parent = file.getParentFile().getName();
        if (parent.equals("pos")){
            return "1";
        } else {
            return "0";
        }
    }

    static String getRealLabel(File file){
        String parent = file.getParentFile().getName();
        return parent;
    }

    static String getTrainOrTest() {
        String res = null;
        double ran = Math.random();

        if ( ran< 0.6){
            res = "train";
        } else {
            res = "test";
        }
        return res;
    }
}
{'fraction_non_alphanumeric': 0.11480865224625623, 'fraction_numerical': 0.005546311702717693, 'mean_word_length': 2.5442043222003927, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '6651232', 'n_tokens_mistral': 513, 'n_tokens_neox': 499, 'n_words': 111}