1 Star 0 Fork 0

点点杠 / ZHSpokenDateFormat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ZHSpokenDateFormat

介绍

一个Java工具类,实现中文语句提取口语化的中文日期并转换为YYYY-MM-DD格式

描述

基于正则表达式关键字提取,自年、季度、月、周、日向下提取拼接成日期字符串,同时支持“从……到……”形式的范围日期查找。

日期 口语格式 同义词
去、前、今、本、明、后、前、近、最近 YYYY、YY
季度 这、本、上、下、前、近、最近、第 -
这、本、上、下、上、前、近、最近、半年 MM、M
这、本、上、下、前、近、最近 周、礼拜、星期
现在、昨、今、前、明、后、前、近、最近、半个月、月上旬、月中旬、月下旬 DD、D、天、日、号、星期X、周X、礼拜X

使用

代码

ZHSpokenDateFormat.AnalyzeResult analyzeResult = ZHSpokenDateFormat.analyzeStr("今年上半年有什么电影");

AnalyzeResult 类属性

// 是否有日期格式匹配
private boolean matchDate;
// 开始时间
private String beginDate;
// 结束时间
private String endDate;
// 去除日期字符串后剩余的字符串部分
private String remainingPart;

示例

代码


 public static void main(String[] args) {

        String[] questions = {
                "今年上半年有什么电影",
                "从2010年3月份到二零一九年十二月份有哪些动漫",
                "最近两个礼拜有什么电视剧",
                "七月上旬开了几场演唱会",
        };

        for (String question : questions) {

            ZHSpokenDateFormat.AnalyzeResult analyzeResult = ZHSpokenDateFormat.analyzeStr(question);

            System.out.println("原句:" + question);
            System.out.println("是否有日期格式匹配:" + analyzeResult.isMatchDate());
            System.out.println("开始时间:" + analyzeResult.getBeginDate());
            System.out.println("结束时间:" + analyzeResult.getEndDate());
            System.out.println("去除日期字符串后剩余的字符串部分:" + analyzeResult.getRemainingPart());

            // 当然你也可以通过以下方式获取匹配文字
            String matchStr = question.replaceAll(analyzeResult.getRemainingPart(), "");
            System.out.println("匹配文字:" + matchStr);

            System.out.println("\n");
        }

    }

结果

原句:今年上半年有什么电影
是否有日期格式匹配:true
开始时间:2020-01-01
结束时间:2020-06-30
去除日期字符串后剩余的字符串部分:有什么电影
匹配文字:今年上半年


原句:从2010年3月份到二零一九年十二月份有哪些动漫
是否有日期格式匹配:true
开始时间:2010-03-01
结束时间:2019-12-31
去除日期字符串后剩余的字符串部分:有哪些动漫
匹配文字:从2010年3月份到二零一九年十二月份


原句:最近两个礼拜有什么电视剧
是否有日期格式匹配:true
开始时间:2020-10-5
结束时间:2020-10-11
去除日期字符串后剩余的字符串部分:有什么电视剧
匹配文字:最近两个礼拜


原句:七月上旬开了几场演唱会
是否有日期格式匹配:true
开始时间:2020-07-01
结束时间:2020-07-10
去除日期字符串后剩余的字符串部分:开了几场演唱会
匹配文字:七月上旬

License

ZHSpokenDateFormat is a MIT licensed

MIT License Copyright (c) 2020 wangnamu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/diandiangang/ZHSpokenDateFormat.git
git@gitee.com:diandiangang/ZHSpokenDateFormat.git
diandiangang
ZHSpokenDateFormat
ZHSpokenDateFormat
main

搜索帮助