Python常见实体提取库Duckling,多语言,实体如日期、金额、距离
简介
duckling是wit.ai的Duckling Clojure库的Python包装
用于以多种语言提取日期、金额、距离等常见实体
安装
pip install duckling
python-duckling需要安装JVM才能运行
中文
from duckling import *d = DucklingWrapper(language=Language.CHINESE)
print(d.parse_duration("我今天跑了两个小时")) # 解析时长
print(d.parse_number("我25岁了")) # 解析数值
print(d.parse_ordinal("我是第一,你是第二")) # 解析序数
print(d.parse_temperature("人体最适宜的温度是25摄氏度")) # 解析温度
print(d.parse_time("我们十一点半见")) # 解析时间
print(d.parse_timezone("中国统一用一个时区UTC")) # 解析时区
# [{'dim': 'duration', 'text': '两个小时', 'start': 5, 'end': 9, 'value': {'value': 2.0, 'unit': 'hour', 'year': None, 'month': None, 'day': None, 'hour': 2, 'minute': None, 'second': None}}, {'dim': 'duration', 'text': '两个小时', 'start': 5, 'end': 9, 'value': {'value': 2.0, 'unit': 'hour', 'year': None, 'month': None, 'day': None, 'hour': 2, 'minute': None, 'second': None}}]
# [{'dim': 'number', 'text': '25', 'start': 1, 'end': 3, 'value': {'value': 25.0}}]
# [{'dim': 'ordinal', 'text': '第一', 'start': 2, 'end': 4, 'value': {'value': 1}}, {'dim': 'ordinal', 'text': '第二', 'start': 7, 'end': 9, 'value': {'value': 2}}]
# [{'dim': 'temperature', 'text': '25摄氏度', 'start': 9, 'end': 14, 'value': {'value': 25.0, 'unit': 'celsius'}}]
# [{'dim': 'time', 'text': '十一点半', 'start': 2, 'end': 6, 'value': {'value': '2020-05-14T11:30:00.000+08:00', 'grain': 'minute', 'others': [{'grain': 'minute', 'value': '2020-05-14T11:30:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-14T23:30:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-15T11:30:00.000+08:00'}]}}]
# [{'dim': 'timezone', 'text': 'UTC', 'start': 9, 'end': 12, 'value': {'value': 'UTC'}}]
英文
from duckling import *d = DucklingWrapper()
print(d.parse_time("Let's meet at 11:45am")) # 解析时间
print(d.parse_cycle("coming week")) # 解析周期,失效
print(d.parse_distance("A circle around the equator is 40075.02 kilometers")) # 解析距离
print(d.parse_duration("I ran for 2 hours today")) # 解析时长
print(d.parse_email("Shoot me an email at contact@frank-blechschmidt.com")) # 解析邮箱
print(d.parse_leven_product("5 cups of sugar")) # 解析产品
print(d.parse_leven_unit("two pounds of meat")) # 解析单位
print(d.parse_money("You owe me 10 dollars")) # 解析金钱
print(d.parse_number("I'm 25 years old")) # 解析数值
print(d.parse_ordinal("I'm first, you're 2nd")) # 解析序数
print(d.parse_phone_number("424-242-4242 is obviously a fake number")) # 解析电话号码
print(d.parse_quantity("5 cups of sugar")) # 解析总量
print(d.parse_temperature("Let's change the temperature from thirty two celsius to 65 degrees")) # 解析温度
print(d.parse_time("Let's meet at 11:45am")) # 解析时间
print(d.parse_timezone("My timezone is pdt")) # 解析时区
print(d.parse_unit("6 degrees outside")) # 解析单位(失效)
print(d.parse_unit_of_duration("1 second")) # 解析时长的单位(失效)
print(d.parse_url("http://frank-blechschmidt.com is under construction, but you can check my github github.com/FraBle")) # 解析URL
print(d.parse_volume("1 gallon is 3785ml")) # 解析体积
# [{'dim': 'time', 'text': 'at 11:45am', 'start': 11, 'end': 21, 'value': {'value': '2020-05-14T11:45:00.000+08:00', 'grain': 'minute', 'others': [{'grain': 'minute', 'value': '2020-05-14T11:45:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-15T11:45:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-16T11:45:00.000+08:00'}]}}]
# []
# [{'dim': 'distance', 'text': '40075.02 kilometers', 'start': 31, 'end': 50, 'value': {'value': 40075.02, 'unit': 'kilometre'}}]
# [{'dim': 'duration', 'text': '2 hours', 'start': 10, 'end': 17, 'value': {'value': 2.0, 'unit': 'hour', 'year': None, 'month': None, 'day': None, 'hour': 2, 'minute': None, 'second': None}}]
# [{'dim': 'email', 'text': 'contact@frank-blechschmidt.com', 'start': 21, 'end': 51, 'value': {'value': 'contact@frank-blechschmidt.com'}}]
# [{'dim': 'leven-product', 'text': 'sugar', 'start': 10, 'end': 15, 'value': {'value': 'sugar'}}]
# [{'dim': 'leven-unit', 'text': 'pounds', 'start': 4, 'end': 10, 'value': {'value': 'pound'}}]
# [{'dim': 'amount-of-money', 'text': '10 dollars', 'start': 11, 'end': 21, 'value': {'value': 10.0, 'unit': '$'}}]
# [{'dim': 'number', 'text': '25', 'start': 4, 'end': 6, 'value': {'value': 25.0}}]
# [{'dim': 'ordinal', 'text': 'first', 'start': 4, 'end': 9, 'value': {'value': 1}}, {'dim': 'ordinal', 'text': '2nd', 'start': 18, 'end': 21, 'value': {'value': 2}}]
# [{'dim': 'phone-number', 'text': '424-242-4242 ', 'start': 0, 'end': 13, 'value': {'value': '424-242-4242 '}}]
# [{'dim': 'quantity', 'text': '5 cups of sugar', 'start': 0, 'end': 15, 'value': {'value': 5, 'unit': 'cup', 'product': 'sugar'}}]
# [{'dim': 'temperature', 'text': '65 degrees', 'start': 56, 'end': 66, 'value': {'value': 65.0, 'unit': 'degree'}}, {'dim': 'temperature', 'text': 'thirty two celsius', 'start': 34, 'end': 52, 'value': {'value': 32.0, 'unit': 'celsius'}}]
# [{'dim': 'time', 'text': 'at 11:45am', 'start': 11, 'end': 21, 'value': {'value': '2020-05-14T11:45:00.000+08:00', 'grain': 'minute', 'others': [{'grain': 'minute', 'value': '2020-05-14T11:45:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-15T11:45:00.000+08:00'}, {'grain': 'minute', 'value': '2020-05-16T11:45:00.000+08:00'}]}}]
# [{'dim': 'timezone', 'text': 'pdt', 'start': 15, 'end': 18, 'value': {'value': 'PDT'}}]
# []
# []
# [{'dim': 'url', 'text': 'http://frank-blechschmidt.com', 'start': 0, 'end': 29, 'value': {'value': 'http://frank-blechschmidt.com'}}, {'dim': 'url', 'text': 'github.com/FraBle', 'start': 81, 'end': 98, 'value': {'value': 'github.com/FraBle'}}, {'dim': 'url', 'text': 'http://frank-blechschmidt.com', 'start': 0, 'end': 29, 'value': {'value': 'http://frank-blechschmidt.com'}}]
# [{'dim': 'volume', 'text': '3785ml', 'start': 12, 'end': 18, 'value': {'value': 3785.0, 'unit': 'millilitre', 'latent': False}}, {'dim': 'volume', 'text': '1 gallon', 'start': 0, 'end': 8, 'value': {'value': 1.0, 'unit': 'gallon', 'latent': False}}]
函数列表
函数 | 描述 | 例子 |
---|---|---|
parse | 对所有维度进行解析 | Let’s meet at 11:45am |
parse_cycle | 解析出现的周期(失效) | coming week |
parse_distance | 解析距离 | I commute 5 miles everyday |
parse_duration | 解析时长 | I ran for 2 hours today |
parse_email | 解析邮箱 | Shoot me an email at contact@frank-blechschmidt.com |
parse_leven_product | 解析产品 | 5 cups of sugar |
parse_leven_unit | 解析单位 | two pounds of meat |
parse_money | 解析金钱 | You owe me 10 dollars |
parse_number | 解析数值 | I’m 25 years old |
parse_ordinal | 解析序数 | I’m first, you’re 2nd |
parse_phone_number | 解析号码 | 424-242-4242 is obviously a fake number |
parse_quantity | 解析总量 | 5 cups of sugar |
parse_temperature | 解析温度 | Let’s change the temperature from thirty two celsius to 65 degrees |
parse_time | 解析时间 | Let’s meet at 11:45am |
parse_timezone | 解析时区 | My timezone is pdt |
parse_unit | 解析单位(失效) | 6 degrees outside |
parse_unit_of_duration | 解析时长的单位(失效) | 1 second |
parse_url | 解析URL | http://frank-blechschmidt.com is under construction, but you can check my github github.com/FraBle |
parse_volume | 解析体积 | 1 gallon is 3785ml |
参考文献
- FraBle/python-duckling: Python wrapper for wit.ai’s Duckling Clojure library
Python常见实体提取库Duckling,多语言,实体如日期、金额、距离相关推荐
- python日历gui_python GUI库图形界面开发之PyQt5日期时间控件QDateTimeEdit详细使用方法与实例...
PyQt5日期时间控件QDateTimeEdit介绍 QDateTimeEdit是一个允许用户编辑日期时间的控件,可以使用键盘上的上下键头按钮来增加或减少日期的时间值,QDateTimeEdit通过s ...
- python的库在哪_你知道python常见的库有哪些吗?五大python库
大家都知道,现在python是一门非常不错的编程,各行各业都开始使用python进行编程,而且python每个功能模块,都有对应的python库,那么你知道python常见的库有哪些吗?今天为大家介绍 ...
- Python语言学习:Python常用自带库(imageio、pickle)简介、使用方法之详细攻略
Python语言学习:Python常用自带库(imageio.pickle)简介.使用方法之详细攻略 目录 imageio简介及其常见使用方法 pickle简介及其常见使用方法 简介 使用方法 简介及 ...
- python常见库集合
库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...
- 什么是python的第三方库_python学习(十九)常见的第三方库
介绍几个python中常见的第三方库. Pillow Pillow简称PIL,是python中常用的图形图像处理模块.写一个简单的例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- python常见开源库整理
看到一个整理比较好饿 python常见开源库,先收藏一下 python 各种开源库 - 星辰虎贲 - 博客园
- Python常见库matplotlib之多个子图绘图
系列文章目录 第一章 Python常见库matplotlib之画图文字的中文显示 第二章 Python常见库matplotlib之画图中各个模块的含义及修改方式 第三章 Python常见库matplo ...
- python 根据gdb省库提取属性,输出房地一体申请表
python 根据gdb省库提取属性,输出房地一体申请表 -- coding: utf-8 -- import win32com.client from PyQt5.QtWidgets import ...
- Python常见库matplotlib之画图文字的中文显示
系列文章目录 第一章 Python常见库matplotlib之画图文字的中文显示 第二章 Python常见库matplotlib之画图中各个模块的含义及修改方式 第三章 Python常见库matplo ...
最新文章
- 用python创建一个目录
- 如何查看和停止Linux启动的服务
- oracle11g memory_target,oracle11g MEMORY_MAX_TARGET设置成0 问题处理
- 资深项目经理的10条项目管理心得
- 在Eclipse 中打开当前文件夹
- C# 微信服务号模板消息中如何换行
- 解析字符串获取路径_node学习--path 路径模块
- 问题1:VS2017:找不到 Windows SDK 版本10.0.17134.0
- 吴恩达机器学习视频学习笔记(2)
- 计算机网络安全 单词
- 解决python安装包无法正常安装问题
- 世界所有国家的信息(2)
- ROC曲线下面积的相关计算和检验
- 腾达便携无线路由 无法建立到192.168.2.1的服务器连接,Tenda腾达路由器5G信号设置步骤...
- inv在线计算机,INV3062A
- 分布式系统之-我的书单
- 【labview】限幅子vi +源程序
- TensorFlow搭建CNN实现时间序列预测(风速预测)
- 一个渣渣对OLSR的简单理解
- PAT 1100. Mars Numbers (20)
热门文章
- 触屏笔和电容笔哪个好?非常值得入手的电容笔推荐
- 有关Unity3D的OnRenderImage()和Blit()的一些问题
- 主页被改为www.n220.com www.129yy.cn
- 我所知道的中国NLP「破圈」十年
- 云开发:微信小程序开发-组件化开发
- 在电脑上剪辑视频用什么软件 如何在电脑上剪辑视频
- 思科模拟器Cisco Packet Tracer交换机的端口聚合配置
- 【Python】用字母生成图像
- 让电代替人工去计算——机电时期的权宜之计
- 从‘心’出发,乐跑向前——德州站健心跑公益活动盛大开跑