<commit_before>package org.popkit.leap.elpa.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.popkit.leap.elpa.entity.RecipeDo;

import java.io.File;

/**
 * Created by <NAME>
 * Mail <EMAIL>
 * 2016-05-16:12:02
 */
public class RecipeParser {

    public static RecipeDo parsePkgRecipe(String pkgName) {
        String recipe = PelpaUtils.getRecipeFilePath() + pkgName;
        File recipeFile = new File(recipe);
        if (recipeFile.exists() && recipeFile.isFile()) {
            try {
                String content = FileUtils.readFileToString(recipeFile, "UTF-8");
                return parse(content);
            } catch (Exception e) {

            }
        }
        return null;
    }

    public static RecipeDo parse(String origin) {
        String sub = null;
        try {
            sub = origin.substring(origin.indexOf('(') + 1, origin.lastIndexOf(')'));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (sub == null) {
            return null;
        }

        String[] suArr = sub.split(" ");
        RecipeDo recipeDo = new RecipeDo();
        recipeDo.setPkgName(suArr[0].trim());
        String[] keyValuePair = sub.substring(sub.indexOf(suArr[0]) + suArr[0].length()).split(":");

        for (String keyValue : keyValuePair) {
            try {
                if (StringUtils.isNotBlank(keyValue) && keyValue.split("").length > 1) {
                    String key = keyValue.split(" ")[0].trim();
                    String value = keyValue.split(" ")[1].trim();
                    if ("files".equalsIgnoreCase(key)) {
                        recipeDo.update(key, fileValue(value));
                    } else if ("repo".endsWith(key)) {
                        recipeDo.update(key, trimIt(value));
                    } else {
                        recipeDo.update(key, value);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
        }
        return recipeDo;
    }

    private static String trimIt(String orgin) {
        return orgin.replaceAll("\"", "").trim();
    }

    private static String fileValue(String origin) {
        if (StringUtils.isBlank(origin)) {
            return origin;
        }
        return origin.replaceAll("\"","").replaceAll("\\(", "").replaceAll("\\)", "").trim();
    }
}<commit_msg>fix recipe files<commit_after>package org.popkit.leap.elpa.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.popkit.leap.elpa.entity.RecipeDo;

import java.io.File;

/**
 * Created by <NAME>
 * Mail <EMAIL>
 * 2016-05-16:12:02
 */
public class RecipeParser {

    public static RecipeDo parsePkgRecipe(String pkgName) {
        String recipe = PelpaUtils.getRecipeFilePath() + pkgName;
        File recipeFile = new File(recipe);
        if (recipeFile.exists() && recipeFile.isFile()) {
            try {
                String content = FileUtils.readFileToString(recipeFile, "UTF-8");
                return parse(content);
            } catch (Exception e) {

            }
        }
        return null;
    }

    public static RecipeDo parse(String origin) {
        String sub = null;
        try {
            sub = origin.substring(origin.indexOf('(') + 1, origin.lastIndexOf(')'));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (sub == null) {
            return null;
        }

        String[] suArr = sub.split("\\s+");
        RecipeDo recipeDo = new RecipeDo();
        recipeDo.setPkgName(suArr[0].trim());
        String[] keyValuePair = sub.substring(sub.indexOf(suArr[0]) + suArr[0].length()).split(":");

        for (String keyValue : keyValuePair) {
            try {
                if (StringUtils.isNotBlank(keyValue) && keyValue.split("\\s+").length > 1) {
                    String key = keyValue.split("\\s+")[0].trim();
                    String value = keyValue.split("\\s+")[1].trim();
                    if ("files".equalsIgnoreCase(key)) {
                        recipeDo.update(key, fileValue(keyValue));
                    } else if ("repo".endsWith(key)) {
                        recipeDo.update(key, trimIt(value));
                    } else {
                        recipeDo.update(key, value);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
        }
        return recipeDo;
    }

    private static String trimIt(String orgin) {
        return orgin.replaceAll("\"", "").trim();
    }

    private static String fileValue(String origin) {
        if (StringUtils.isBlank(origin)) {
            return origin;
        }
        String fileContent = origin.substring(origin.indexOf("files") + "files".length());
        return fileContent.replaceAll("\"","").replaceAll("\\(", "").replaceAll("\\)", "").trim();
    }
}
{'fraction_non_alphanumeric': 0.14100776737701654, 'fraction_numerical': 0.008364867556263693, 'mean_word_length': 1.7699944842801987, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, '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': '2370779', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1405, 'n_words': 280}