<commit_before>package com.githang.java;

import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author Geek_Soledad (<EMAIL>)
 */
public class MergeHtml {
    private static Set<String> MERGE_NODE_NAME = new HashSet<String>();
    static {
        MERGE_NODE_NAME.add("html");
        MERGE_NODE_NAME.add("div");
        MERGE_NODE_NAME.add("head");
        MERGE_NODE_NAME.add("body");
        MERGE_NODE_NAME.add("table");
        MERGE_NODE_NAME.add("thead");
        MERGE_NODE_NAME.add("tbody");
        MERGE_NODE_NAME.add("tr");
        MERGE_NODE_NAME.add("td");
        MERGE_NODE_NAME.add("title");
        MERGE_NODE_NAME.add("a");
        MERGE_NODE_NAME.add("dl");
        MERGE_NODE_NAME.add("dt");
        MERGE_NODE_NAME.add("dd");
        MERGE_NODE_NAME.add("ul");
    }

    public static void main(String[] args) throws IOException {
        File workDir;
        if(args.length < 1) {
//            workDir = new File("./resources/");
            System.out.println("java -jar merge-translated-html.jar [path]");
            return;
        } else {
            workDir = new File(args[0]);
        }
        File sourcesFolder = new File(workDir, "source");
        File targetFolder = new File(workDir, "target");

        if(!sourcesFolder.exists() || targetFolder.exists()) {
            System.out.println(sourcesFolder.getPath() + " or " + targetFolder.getPath() + " is not exist.");
            return;
        }

        File outputFolder = new File(workDir, "output");
        if(!outputFolder.exists()) {
            outputFolder.mkdirs();
        }
        File[] targets = targetFolder.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".html");
            }
        });
        for(File target : targets) {
            File source = new File(sourcesFolder, target.getName());

            Document result = mergeFileContent(source, target);
            System.out.println(result.html());
            File output = new File(outputFolder, target.getName());
            FileUtils.writeStringToFile(output, result.html(), "UTF-8");
        }
    }

    private static Document mergeFileContent(File source, File target) throws IOException {
        Document sourceRoot = Jsoup.parse(source, "UTF-8");
//        System.out.println(sourceRoot.toString());

        Document targetRoot = Jsoup.parse(target, "UTF-8");
//        System.out.println(targetRoot.toString());
<commit_msg>修复判断文件夹是否存在的逻辑错误<commit_after>package com.githang.java;

import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author Geek_Soledad (<EMAIL>)
 */
public class MergeHtml {
    private static Set<String> MERGE_NODE_NAME = new HashSet<String>();
    static {
        MERGE_NODE_NAME.add("html");
        MERGE_NODE_NAME.add("div");
        MERGE_NODE_NAME.add("head");
        MERGE_NODE_NAME.add("body");
        MERGE_NODE_NAME.add("table");
        MERGE_NODE_NAME.add("thead");
        MERGE_NODE_NAME.add("tbody");
        MERGE_NODE_NAME.add("tr");
        MERGE_NODE_NAME.add("td");
        MERGE_NODE_NAME.add("title");
        MERGE_NODE_NAME.add("a");
        MERGE_NODE_NAME.add("dl");
        MERGE_NODE_NAME.add("dt");
        MERGE_NODE_NAME.add("dd");
        MERGE_NODE_NAME.add("ul");
    }

    public static void main(String[] args) throws IOException {
        File workDir;
        if(args.length < 1) {
//            workDir = new File("./resources/");
            System.out.println("java -jar merge-translated-html.jar [path]");
            return;
        } else {
            workDir = new File(args[0]);
        }
        File sourcesFolder = new File(workDir, "source");
        File targetFolder = new File(workDir, "target");

        if(!sourcesFolder.exists() || !targetFolder.exists()) {
            System.out.println(sourcesFolder.getPath() + " or " + targetFolder.getPath() + " is not exist.");
            return;
        }

        File outputFolder = new File(workDir, "output");
        if(!outputFolder.exists()) {
            outputFolder.mkdirs();
        }
        File[] targets = targetFolder.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".html");
            }
        });
        for(File target : targets) {
            File source = new File(sourcesFolder, target.getName());

            Document result = mergeFileContent(source, target);
            System.out.println(result.html());
            File output = new File(outputFolder, target.getName());
            FileUtils.writeStringToFile(output, result.html(), "UTF-8");
        }
    }

    private static Document mergeFileContent(File source, File target) throws IOException {
        Document sourceRoot = Jsoup.parse(source, "UTF-8");
//        System.out.println(sourceRoot.toString());

        Document targetRoot = Jsoup.parse(target, "UTF-8");
//        System.out.println(targetRoot.toString());

{'fraction_non_alphanumeric': 0.13620262132483174, 'fraction_numerical': 0.001771165426850868, 'mean_word_length': 2.536005009392611, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1348207', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1671, 'n_words': 312}