<commit_before>/**
 *
 * APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川,
 * <EMAIL>
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package org.apdplat.jsearch.search;

import org.apdplat.jsearch.score.ProximityScore;
import org.apdplat.jsearch.score.Score;
import org.apdplat.jsearch.score.WordFrequencyScore;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.SegmentationAlgorithm;
import org.apdplat.word.segmentation.Word;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 文本搜索
 * @author 杨尚川
 */
public class TextSearcher implements Searcher {

    private static final Logger LOGGER = LoggerFactory.getLogger(TextSearcher.class);
    private String indexText = "data/index_text.txt";
    private String index = "data/index.txt";
    private Map<String, String> indexMap = new ConcurrentHashMap<>();
    private Score score = new WordFrequencyScore();

    public TextSearcher(){
        init();
    }

    public TextSearcher(String index, String indexText){
        this.index = index;
        this.indexText = indexText;
        init();
    }

    private void init(){
        try{
            LOGGER.error("开始初始化索引");
            long start = System.currentTimeMillis();
            Files.readAllLines(Paths.get(index)).parallelStream().forEach(line -> {
                String[] attrs = line.split("=");
                if (attrs != null && attrs.length == 3) {
                    indexMap.put(attrs[0], attrs[2]);
                }
            });
            LOGGER.error("索引初始化完毕，耗时：" + (System.currentTimeMillis()-start) + "毫秒");
        }catch (Exception e){
            LOGGER.error("索引初始化失败", e);
            throw new RuntimeException(e);
        }
    }

    public String getIndexText() {<commit_msg>日志级别调整<commit_after>/**
 *
 * APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川,
 * <EMAIL>
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package org.apdplat.jsearch.search;

import org.apdplat.jsearch.score.ProximityScore;
import org.apdplat.jsearch.score.Score;
import org.apdplat.jsearch.score.WordFrequencyScore;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.SegmentationAlgorithm;
import org.apdplat.word.segmentation.Word;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 文本搜索
 * @author 杨尚川
 */
public class TextSearcher implements Searcher {

    private static final Logger LOGGER = LoggerFactory.getLogger(TextSearcher.class);
    private String indexText = "data/index_text.txt";
    private String index = "data/index.txt";
    private Map<String, String> indexMap = new ConcurrentHashMap<>();
    private Score score = new WordFrequencyScore();

    public TextSearcher(){
        init();
    }

    public TextSearcher(String index, String indexText){
        this.index = index;
        this.indexText = indexText;
        init();
    }

    private void init(){
        try{
            LOGGER.info("开始初始化索引");
            long start = System.currentTimeMillis();
            Files.readAllLines(Paths.get(index)).parallelStream().forEach(line -> {
                String[] attrs = line.split("=");
                if (attrs != null && attrs.length == 3) {
                    indexMap.put(attrs[0], attrs[2]);
                }
            });
            LOGGER.info("索引初始化完毕，耗时：" + (System.currentTimeMillis()-start) + "毫秒");
        }catch (Exception e){
            LOGGER.error("索引初始化失败", e);
            throw new RuntimeException(e);
        }
    }

    public String getIndexText() {
{'fraction_non_alphanumeric': 0.10747051114023591, 'fraction_numerical': 0.003744617112900206, 'mean_word_length': 3.125096525096525, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5214881', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1610, 'n_words': 446}