package org.diagbot.nlp.test;

import com.alibaba.fastjson.JSON;
import org.diagbot.nlp.participle.ParticipleToken;
import org.diagbot.nlp.participle.ParticipleUtil;
import org.diagbot.nlp.participle.cfg.Configuration;
import org.diagbot.nlp.participle.cfg.DefaultConfig;
import org.diagbot.nlp.participle.word.Lexeme;
import org.diagbot.nlp.participle.word.LexemePath;
import org.diagbot.nlp.participle.word.Segment;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.List;

/**
 * @Auther: fyeman
 * @Date: 2018/6/11/011 10:45
 * @Description:
 */
public class ParticipleTest {
    public static void main(String[] args) {
        try {
            String content = "剑突下痛胀痛1天,";
//            ParticipleTest test = new ParticipleTest();
//            InputStream is = test.getClass().getClassLoader().getResourceAsStream("present.txt");
//            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
//
//            String line="";
//            StringBuffer  buffer = new StringBuffer();
//            while((line=br.readLine())!=null){
//                buffer.append(line);
//            }
//            content = buffer.toString();

            long start = System.currentTimeMillis();

//            Configuration configuration = new DefaultConfig();
//            Segment segment = configuration.loadMainDict("tc.dict");

            List<Lexeme> lexemes = ParticipleUtil.participle(content, false);
            String result = "";
//            for (Lexeme lexeme : lexemes) {
//                if (lexeme.getOffset() > -1) {
//                    result = result + " | " + lexeme.getText();
//                }
//            }
            long end = System.currentTimeMillis();

            start = System.currentTimeMillis();
            lexemes = ParticipleUtil.participle(content, false);
            end = System.currentTimeMillis();

            System.out.println(end - start);
//            System.out.println(JSON.toJSONString(lexemes));
//            ParticipleToken token = new ParticipleToken();
//            token.start(new StringReader(content), segment);
//            LexemePath<Lexeme> lexemePath = token.getLexemePath();
//            token.end();
//
//            long end = System.currentTimeMillis();
//
//            System.out.println("总耗时..........." + (start - end));
//
//            String result = "";
//            for (Lexeme lexeme : lexemePath) {
//                if (lexeme.getOffset() > -1) {
//                        result = result + " | " + lexeme.getText();
//                }
//            }
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
