ThisApplication.java 2.9 KB
Newer Older
R
roo00 已提交
1 2 3 4 5 6 7 8 9 10 11
package com.x.query.service.processing;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.BooleanUtils;

import com.x.base.core.project.Context;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.LoggerFactory;
R
roo00 已提交
12 13
import com.x.query.service.processing.jaxrs.neural.GenerateQueue;
import com.x.query.service.processing.jaxrs.neural.LearnQueue;
R
roo00 已提交
14 15 16 17 18 19 20 21
import com.x.query.service.processing.schedule.CrawlCms;
import com.x.query.service.processing.schedule.CrawlWork;
import com.x.query.service.processing.schedule.CrawlWorkCompleted;

public class ThisApplication {

	protected static Context context;

R
roo00 已提交
22
//	public static CRFLexicalAnalyzer analyzer;
R
roo00 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

	public static GenerateQueue generateQueue = new GenerateQueue();

	public static LearnQueue learnQueue = new LearnQueue();

	public static final Set<String> learning_stop_tag = Collections.synchronizedSet(new HashSet<String>());

	public static final Set<String> generating_stop_tag = Collections.synchronizedSet(new HashSet<String>());

	public static Context context() {
		return context;
	}

	public static void init() {
		try {
			LoggerFactory.setLevel(Config.logLevel().x_query_service_processing());
R
roo00 已提交
39 40 41 42 43 44 45 46
			// setupHanLP(context);
//			analyzer = new CRFLexicalAnalyzer();
//			analyzer.enableOffset(false);
//			analyzer.enableAllNamedEntityRecognize(true);
//			analyzer.enableNumberQuantifierRecognize(true);
//			analyzer.enableNameRecognize(true);
//			analyzer.enableOrganizationRecognize(true);
//			analyzer.enablePlaceRecognize(true);
R
roo00 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
			generateQueue.start();
			learnQueue.start();
			if (BooleanUtils.isTrue(Config.query().getCrawlWork().getEnable())) {
				context.scheduleLocal(CrawlWork.class, Config.query().getCrawlWork().getCron());
			}
			if (BooleanUtils.isTrue(Config.query().getCrawlWork().getEnable())) {
				context.scheduleLocal(CrawlWorkCompleted.class, Config.query().getCrawlWorkCompleted().getCron());
			}
			if (BooleanUtils.isTrue(Config.query().getCrawlCms().getEnable())) {
				context.scheduleLocal(CrawlCms.class, Config.query().getCrawlCms().getCron());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void destroy() {
		try {
			learnQueue.stop();
			generateQueue.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

R
roo00 已提交
72 73 74 75 76 77 78 79 80 81
//	public static void setupHanLP(Context context) throws Exception {
//		File hamLPProperties = new File(context.path(), "/WEB-INF/classes/hanlp.properties");
//		/*
//		 * 本配置文件中的路径的根目录,根目录+其他路径=完整路径(支持相对路径,请参考:https://github.com/hankcs/HanLP/pull/
//		 * 254) #Windows用户请注意,路径分隔符统一使用
//		 */
//		String data = "root=" + StringUtils.replace(Config.base(), "\\", "/")
//				+ "/commons/hanlp/\nHanLP.Config.ShowTermNature = true\nHanLP.Config.Normalization = true";
//		FileUtils.writeStringToFile(hamLPProperties, data, "utf-8", false);
//	}
R
roo00 已提交
82 83

}