All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.special.chars.test.data.NameTest Maven / Gradle / Ivy

There is a newer version: 0.0.2
Show newest version
package com.github.houbb.special.chars.test.data;

import com.github.houbb.heaven.support.filter.IFilter;
import com.github.houbb.heaven.util.guava.Guavas;
import com.github.houbb.heaven.util.io.FileUtil;
import com.github.houbb.heaven.util.lang.CharUtil;
import com.github.houbb.heaven.util.lang.StringUtil;
import com.github.houbb.heaven.util.util.CollectionUtil;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * 去重,备注。
 *
 * key: 中文
 * value: 表情
 * eng: 英语
 * @author binbin.hou
 * @since 0.0.1
 */
@Ignore
public class NameTest {

    @Test
    public void nameRankTest() {
        final String o = "D:\\_github\\special-char\\special-char-test\\src\\main\\resources\\fhdq\\detail\\index_nav_wm\\常用网名符号排行榜.txt";
        final String t = "D:\\_github\\special-char\\special-char-name\\src\\main\\resources\\special-char-name-rank.txt";

        List lines = FileUtil.readAllLines(o);
        List results = Guavas.newArrayList();
        for(int i = 0; i < lines.size(); i++) {
            int num = i+1;

            int length = String.valueOf(num).length();
            String chars = lines.get(i).substring(length);

            String result = chars.substring(0,1)+","+chars.substring(1);
            results.add(result);
        }

        FileUtil.write(t, results);
    }

    /**
     * 遍历文件夹
     * @since 0.0.1
     */
    @Test
    public void allInOneTest() {
        final String sourceDir = "D:\\_github\\special-char\\special-char-test\\src\\main\\resources\\fhdq\\detail\\wm";
        final String targetP = "D:\\_github\\special-char\\special-char-name\\src\\main\\resources\\special-char-name-all-in-one.txt";

        File[] files = new File(sourceDir).listFiles();

        List lines = new ArrayList<>();
        for(File file : files) {
            String name = FileUtil.getFileName(file.getAbsolutePath());

            char lastChar = name.charAt(name.length()-1);
            boolean isNum = Character.isDigit(lastChar);
            if(!isNum) {
                lines.add("###### "+name);
            }

            String original = FileUtil.readAllLines(file).get(0);
            List splits = StringUtil.splitToList(original, " ");
            lines.addAll(splits);
        }

        // 过滤掉页码:【页:】过滤掉单个字符
        lines = CollectionUtil.filterList(lines, new IFilter() {
            @Override
            public boolean filter(String s) {
                if(s.endsWith("页:")) {
                    return true;
                }
                if("上一页".equals(s) || "下一页".equals(s)) {
                    return true;
                }
                if(s.length() <= 1) {
                    return true;
                }
                return false;
            }
        });
        FileUtil.write(targetP, lines);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy