java anchor 发现

package example;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.techwolf.oceanus.text.understand.util.FileUtil;

import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AnchorEscapeTest {

    private static int basePositionCode = 170610;
    private static int targetPositionCode = 170625;
    private static String targetPositionName = "传媒 | 影视媒体 | 带货主播";
    private static final String PARAMS_PATH = "escape/anchor_escape_params.json";

    private static String paramStr;

    static {
        try {
            paramStr = FileUtil.readString(PARAMS_PATH, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static JSONObject ob = JSON.parseObject(paramStr);
    private static Pattern prefixCodePattern = Pattern.compile(ob.getString("prefixCode"));
    private static Pattern titleOrJdOnePattern = Pattern.compile(ob.getString("keywordsOne"));
    private static Pattern titleOrJdTwoPattern = Pattern.compile(ob.getString("keywordsTwo"));
    private static Pattern titleOrJdThreePattern = Pattern.compile(ob.getString("keywordsThree"));
    private static Pattern titleExcludeOnePattern = Pattern.compile(ob.getString("keywordsFour"));
    private static Pattern jdExcludeTwoPattern = Pattern.compile(ob.getString("keywordsFive"));

    public AnchorEscapeTest() throws IOException {
    }

    public static boolean checkAnchor(String positionTitle, String positionDesc) {
        String title = positionTitle.toLowerCase();
        String desc = positionDesc.toLowerCase();
        Matcher leveOneMatcher = prefixCodePattern.matcher(Integer.toString(positionCode).substring(0, 3));
        Matcher titleOneMatcher = titleOrJdOnePattern.matcher(title);
        Matcher jdOneMatcher = titleOrJdOnePattern.matcher(desc);
        Matcher titleTwoMatcher = titleOrJdTwoPattern.matcher(title);
        Matcher jdTwoMatcher = titleOrJdTwoPattern.matcher(desc);
        Matcher titleThreeMatcher = titleOrJdThreePattern.matcher(title);
        Matcher jdThreeMatcher = titleOrJdThreePattern.matcher(desc);
        Matcher titleExcludeMatcher = titleExcludeOnePattern.matcher(title);
        Matcher jdExcludeMatcher = jdExcludeTwoPattern.matcher(desc);

        boolean isAnchor = false;
        if (leveOneMatcher.find() && Objects.equals(positionResults.get(0).positionCode, basePositionCode)) { // 在特定一级类下,并且三级类=170610
            if ((titleOneMatcher.find() || jdOneMatcher.find()) && (titleTwoMatcher.find() || jdTwoMatcher.find()) ||
                    (titleThreeMatcher.find() || jdThreeMatcher.find())) {
                if (!(titleExcludeMatcher.find() || jdExcludeMatcher.find())) {
                    isAnchor = true;
                }
            }
        }
        return isAnchor;
    }

    public static void main(String[] args) throws IOException {
        String title = "招电商主播,这个是";
        String desc = "这是你的机会,快来参与,速";
        // 带货主播识别
        boolean res = checkAnchor(title, desc);
    }
}

 

posted @ 2021-09-23 21:41  今夜无风  阅读(83)  评论(0编辑  收藏  举报