{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-28T06:58:52.051378Z",
     "start_time": "2019-08-28T06:58:51.256824Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Sep 02 15:00:00 CST 2019\n",
      "周五下午7点到8点\n",
      "时间文本:周5下午7点,对应时间:2017-07-21 19:00:00\n",
      "时间文本:8点,对应时间:2017-07-21 20:00:00\n"
     ]
    }
   ],
   "source": [
    "from py4j.java_gateway import JavaGateway, GatewayParameters\n",
    "import py4j\n",
    "\n",
    "def f(object, fld):\n",
    "    return py4j.java_gateway.get_field(object, fld)\n",
    "\n",
    "def analyse():\n",
    "    # gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_field=True))    \n",
    "    gateway = JavaGateway(gateway_parameters=GatewayParameters(address='localhost', port=25333))\n",
    "    analyst=gateway.entry_point.getTimeAnalyst()\n",
    "    normalizer=analyst.getNormalizer()\n",
    "    normalizer.parse(\"Hi，all.下周一下午三点开会\")\n",
    "    units = normalizer.getTimeUnit()\n",
    "    for unit in units:\n",
    "        print(unit.getTime())\n",
    "\n",
    "    DateUtil=gateway.jvm.com.time.util.DateUtil()\n",
    "    normalizer.parse(\"周五下午7点到8点\", \"2017-07-19-00-00-00\")\n",
    "    units = normalizer.getTimeUnit()\n",
    "    print(\"周五下午7点到8点\")\n",
    "    for unit in units:\n",
    "        expr=f(unit, \"Time_Expression\")\n",
    "        print(\"时间文本:\"+ expr +\",对应时间:\"+ DateUtil.formatDateDefault(unit.getTime()))\n",
    "        \n",
    "analyse()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
