Nlp2cron is a toolkit for converting natural language into cron expressions, which can be used for timed tasks of conversational robots and cron expression recognition in normal development

online experience

Note: The training samples are limited, I made up line by line, and cannot cover them all. Currently, only the control of hours, minutes and seconds is supported.

Grandpa, go try it

Use the tutorial

Note: Please move to v1.1 version v1.1

1. Introduce dependencies

 <dependency>
    <groupId>cn.langpy</groupId>
    <artifactId>nlp2cron</artifactId>
    <version>2.0.BETA</version>
  </dependency>

2. Model configuration

Download the model of the corresponding release version, unzip it to any directory, and then configure the model path in the code, such as:

CrondModel.init("d:/model");

3. Use

Suppose the unzipped directory is

├─D
│  └─model
│         └─variables
│         └─saved_model.pb

Note: Currently only supports hour, minute and second control

 public static void main(String[] args) {
        /*模型初始化,初始化需要时间,可提前进行初始化*/
        CrondModel.init("d:/model");
        String test1 = "明早八点";
        String test2 = "每天晚上7点开始";
        String test3 = "每15分钟一次";
        String test4 = "每2小时一次";
        String test5 = "每天晚上7点开始";
        String test6 = "每天早上7点开始";
        String test7 = "上午一点执行";
        String test8 = "明天早上8点";
        String cron1 = CrondUtil.toCron(test1);
        String cron2 = CrondUtil.toCron(test2);
        String cron3 = CrondUtil.toCron(test3);
        String cron4 = CrondUtil.toCron(test4);
        String cron5 = CrondUtil.toCron(test5);
        String cron6 = CrondUtil.toCron(test6);
        String cron7 = CrondUtil.toCron(test7);
        String cron8 = CrondUtil.toDate(test8);
        String cron9 = CrondUtil.toDateTime(test8);
        String cron10 = CrondUtil.toTime(test8);
        /*使用完关闭 如果在web中需要重复使用则不需要关闭*/
        CrondModel.close();
        //明早八点 转为cron表达式:0 0 8 3 1 ? 2021
        //每天晚上7点开始 转为cron表达式:0 0 19 * * ? *
        //每15分钟一次 转为cron表达式:0 0/15 * * * ? *
        //每2小时一次 转为cron表达式:0 0 0/2 * * ? *
        //每天晚上7点开始 转为cron表达式:0 0 19 * * ? *
        //每天早上7点开始 转为cron表达式:0 0 7 * * ? *
        //上午一点执行 转为cron表达式:0 0 1 * * ? *
        //明天早上八点 转为date表达式:2021-01-03
        //明天早上八点 转为datetime表达式:2021-01-03 08:00:00
        //明天早上八点 转为time表达式:08:00:00
}

principle

The implementation principle is a simplified version of the seq2seq model, and the corresponding model architecture diagram is as follows:

1. Directly use global vector encoding for prediction

2. In the decoding stage, it is assumed that the output information is already contained in the state h, so the output of the previous word is no longer used as the input of the next word prediction number (there is another reason that I am lazy, and then I found that this works well, hia hia hia !)

3. In order to simplify the model and speed up the convergence, GRU is used uniformly for decoding and encoding

Enter image description

Imprint

V1.0: Initial version

V2.0.BETA: Optimize model size and performance based on tf2.0 version

#nlp2cron #nlp2cron #toolkit #converting #natural #language #cron #expressions #timed #tasks #conversational #robots #cron #expression #recognition #normal #development

Leave a Comment

Your email address will not be published. Required fields are marked *