云服务器内容精选
-
常用方案比较 字符串动态键值对提取分为关键字提取、值提取、关键字加工和值加工,常用方案为采用e_kv函数、e_kv_delimit函数和e_regex函数等。不同提取场景的三种方案如下: 方案 关键字提取 值提取 关键字加工 值加工 e_kv 使用特定正则表达式 支持默认的字符集、特定分隔符或者带(、)或(")分隔 支持前后缀 支持文本escape e_kv_delimit 使用特定正则表达式 使用分隔符 支持前后缀 默认无 e_regex 组合自定义正则表达式和默认字符集过滤 完全自定义 自定义 自定义 大部分键值对的提取使用e_kv函数并配置特定参数就可以很好地满足,尤其是带括字符和反斜杠需要提取并转义时。其他复杂或高级的场景可以用e_regex函数来提取。部分特定场景下的键值对使用e_kv_delimit函数会更简单。
-
值提取 动态键值对之间以及关键字与值之间有明确标识,如a=b或a="cxxx"日志格式的,推荐用e_kv函数,示例如下。 原始日志 { "content":"k=\"helloworld\",the change world, k2=\"good\""} 加工规则 这种情况下使用e_kv函数,提取内容不包括the change world: e_kv("content")# e_regex函数写法e_regex("content",r"(\w+)=\"(\w+)",{r"\1": r"\2"}) 加工结果:提取后的日志为: {"k2": "good","k": "helloworld","content": "k=\"helloworld\",the change world, k2=\"good\""} 对带"的日志格式content:k1="v1=1"&k2=v2?k3=v3,推荐使用e_kv函数进行提取,例如: 原始日志 { "content":"k1=\"v1=1\"&k2=v2?k3=v3"} 加工规则 e_kv("content",sep="=", quote="'") 加工结果 处理后日志为: {"k1": "v1=1","k2": "v2","k3": "v3","content": "k1=\"v1=1\"&k2=v2?k3=v3"}
-
关键字加工 e_kv函数和e_kv_delimit函数都可以通过prefix="", suffix=""对关键字和值进行加工。 原始日志 { "content":"q=asd&a=1&b=2"} 加工规则(各语句分开执行,功能相同) e_kv("content", sep="=", quote='"', prefix="start_", suffix="_end")e_kv_delimit("content", pair_sep=r"&", kv_sep="=", prefix="start_", suffix="_end")e_regex("content",r"(\w+)=([a-zA-Z0-9]+)",{r"start_\1_end": r"\2"}) 加工结果 加工后的数据都是关键字加工形式,如下: {"start_b_end": 2,"start_a_end": 1,"start_q_end": "asd","content": "q=asd&a=1&b=2"} e_regex函数对关键字加工的能力更强,例如: 加工规则 e_regex("content",r"(\w+)=([a-zA-Z0-9]+)",{r"\1_\1": r"\2"}) 加工结果 加工后的数据都是关键字加工形式,如下: {"q_q": "asd","a_a": 1,"b_b": 2,"content": "q=asd&a=1&b=2"}
-
值加工 日志格式为k1:"v1\"abc"形式, 同时值加工的内容存在有双引号符号的情形,使用e_kv函数可正常进行提取。 原始日志 """这里的\只是普通的符号,不是转义符"""{ "content":"k1:\"v1\\\"abc\", k2:\"v2\", k3: \"v3\""} 加工规则: e_kv("content",sep=":", quote='"') 加工结果 提取后的日志为: {"k1": "v1\\","k2": "v2","k3": "v3","content": "k1:\"v1\\\"abc\", k2:\"v2\", k3: \"v3\""}
-
关键字提取 示例1 以k1: q=asd&a=1&b=2&__1__=3日志为例,如果要对该格式的日志作为关键字和值提取,三种方案如下: e_kv函数 原始日志 { "k1":"q=asd&a=1&b=2&__1__=3"} 加工规则 e_kv("k1") 加工结果 {"q": "asd","a": 1,"b": 2,"k1": "q=asd&a=1&b=2&__1__=3","__1__": 3} e_kv_delimit函数 原始日志 { "k1":"q=asd&a=1&b=2&__1__=3"} 加工规则 # 以&分隔键值后,用&分隔提取出关键字e_kv_delimit("k1", pair_sep=r"&") 加工结果 {"q": "asd","a": 1,"b": 2,"k1": "q=asd&a=1&b=2&__1__=3","__1__": 3} e_regex函数 原始日志 { "k1":"q=asd&a=1&b=2&__1__=3"} 加工规则 # 自行指定字符集提取关键字和值e_regex("k1",r"(\w+)=([a-zA-Z0-9]+)",{r"\1": r"\2"}) 加工结果 {"q": "asd","a": 1,"b": 2,"k1": "q=asd&a=1&b=2&__1__=3","__1__": 3} 示例2 以content:k1=v1&k2=v2?k3:v3为例,需要特定正则提取关键字,方案如下: e_kv_delimit函数 原始日志 { "content":"k1=v1&k2=v2?k3:v3"} 加工规则 e_kv_delimit("content",pair_sep=r"&?",kv_sep="(?:=|:)") 加工结果 {"k1": "v1","k2": "v2","k3": "v3","content": "k1=v1&k2=v2?k3:v3"} e_regex函数 原始日志 { "content":"k1=v1&k2=v2?k3:v3"} 加工规则 e_regex("content",r"([a-zA-Z0-9]+)[=|:]([a-zA-Z0-9]+)",{r"\1": r"\2"}) 加工结果 {"k1": "v1","k2": "v2","k3": "v3","content": "k1=v1&k2=v2?k3:v3"}
-
样式 尺寸位置 W:设置图表的宽,单位为px。 H:设置图表的高,单位px。 X:设置图表在画布中的位置。单位为px。 Y:设置图表在画布中的位置。单位为px。 不透明度:设置图表在画布上的透明度,可通过滑动条进行设置,也可手动输入百分比,比例越大透明程度越低。 图1 尺寸位置 全局样式:可设置组件的字体类型。 基础图表 合并数据为其他:勾选“合并数据为其他”,矩形树图显示数据区块为设置合并后区块数量;不勾选显示数据区块为字段中“查询返回数限制”的数量。 合并区块数量:用户可自定义设置,设置数量不能少于2个数据区块。如果设置的合并数量大于矩形树“查询返回数限制”的数值,矩形树显示数据块数则按照“查询返回数限制”数量显示。 区 域名 称:用户可根据使用场景自定义设置。 标签 文本:可设置标签的字号、颜色、字体粗细。字号设置范围10~100。 占比:支持矩形树图占比色设置。设置占比小数位显示范围0~10。 度量:支持矩形树图设置度量显示与不显示。 数值设置:支持对数值的语境、单位、科学计数法、使用千分位分割符、小数位的设置。 提示信息 显示/隐藏提示信息:勾选表示预览或查看发布组件时显示的提示信息;不勾选表示预览或查看发布组件时不显示提示信息。 可设置提示信息的字号大小、颜色、字体粗细。字号范围10~100。 系列 配色方案:支持默认色、经典、舒适、智能、数据、艺术、SaaS规范的配色方案。 图2 配色方案 系列:支持对系列颜色的配置(纯色)。 图3 系列颜色配置 总计 显示/隐藏总计:单击“显示总计”左侧的勾选框,表示显示总计,表示不显示总计。 自定义名称:用户可根据使用场景自定义总计名称。 可设置总计名称、数值的字号大小、颜色、字体粗细。字号范围10~100。
-
模型部署 模型部署操作即将模型部署为在线服务,并且提供在线的测试UI与监控能力。完成模型训练后,可选择准确率理想且训练状态为“运行成功”的版本部署上线。具体操作步骤如下。 在“运行总览”页面中,待服务部署节点的状态变为“等待输入”,双击“服务部署”节点,进入配置详情页,完成资源的参数配置操作。 在服务部署页面,选择模型部署使用的资源规格。 模型来源:默认为生成的模型。 选择模型版本:自动匹配当前使用的模型版本,支持选择版本。 资源池:默认公共资源池。 分流:默认为100,输入值必须是0-100之间。 计算节点规格:请根据界面显示的列表,选择可用的规格,置灰的规格表示当前环境无法使用。如果公共资源池下规格为空数据,表示当前环境无公共资源。建议使用专属资源池,或者联系系统管理员创建公共资源池。 计算节点个数:默认为1,输入值必须是1-5之间的整数。 是否自动停止:启用该参数并设置时间后,服务将在指定时间后自动停止。如果不启用此参数,在线服务将一直运行,同时一直收费,自动停止功能可以帮您避免产生不必要的费用。默认开启自动停止功能,且默认值为“1小时后”。 目前支持设置为“1小时后”、“2小时后”、“4小时后”、“6小时后”、“自定义”。如果选择“自定义”的模式,可在右侧输入框中输入1~24范围内的任意整数。 如果您购买了套餐包,计算节点规格可选择您的套餐包,同时在“配置费用”页签还可查看您的套餐包余量以及超出部分的计费方式,请您务必关注,避免造成不必要的资源浪费。 完成资源配置后,单击“继续运行”,在弹框中确认继续运行后,服务部署节点将继续运行,直至状态变为“运行成功”,至此,已将模型部署为在线服务。
-
服务测试 服务部署节点运行成功后,单击“实例详情”可跳转至对应的在线服务详情页面。单击“预测”页签,进行服务测试。 图1 服务测试 下面的测试,是您在自动学习文本分类项目页面将模型部署上线之后进行服务测试的操作步骤。 模型部署完成后,您可添加文本进行测试。在“自动学习”页面,选择目标项目,进入“模型部署”界面,选择状态为“运行中”的服务版本,在“服务测试”区域的文本框中,输入需测试的文本。 单击“预测”进行测试,预测完成后,右侧“预测结果”区域输出测试结果。如模型准确率不满足预期,可在“数据标注”页签中添加数据并进行标注,重新进行模型训练及模型部署。预测结果中的参数说明请参见表1。如果您对模型预测结果满意,可根据界面提示调用接口访问在线服务。 表1 预测结果中的参数说明 参数 说明 predicted_label 该段文本的预测类别。 score 预测为此类别的置信度。 由于“运行中”的在线服务将持续耗费资源,如果不需再使用此在线服务,建议在版本管理区域,单击“停止”,即可停止在线服务的部署,避免产生不必要的费用。如果需要继续使用此服务,可单击“启动”恢复。 如果您启用了自动停止功能,服务将在指定时间后自动停止,不再产生费用。
-
搜索表 本章节主要介绍如何使用文本搜索运算符搜索数据库表。 一个简单查询:将body字段中包含science的每一行打印出来。 1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132 DROP SCHEMA IF EXISTS tsearch CASCADE;CREATE SCHEMA tsearch;CREATE TABLE tsearch.pgweb(id int, body text, title text, last_mod_date date);INSERT INTO tsearch.pgweb VALUES(1, 'Philology is the study of words, especially the history and development of the words in a particular language or group of languages.', 'Philology', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(2, 'Mathematics is the science that deals with the logic of shape, quantity and arrangement.', 'Mathematics', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(3, 'Computer science is the study of processes that interact with data and that can be represented as data in the form of programs.', 'Computer science', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(4, 'Chemistry is the scientific discipline involved with elements and compounds composed of atoms, molecules and ions.', 'Chemistry', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(5, 'Geography is a field of science devoted to the study of the lands, features, inhabitants, and phenomena of the Earth and planets.', 'Geography', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(6, 'History is a subject studied in schools, colleges, and universities that deals with events that have happened in the past.', 'History', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(7, 'Medical science is the science of dealing with the maintenance of health and the prevention and treatment of disease.', 'Medical science', '2010-1-1');INSERT INTO tsearch.pgweb VALUES(8, 'Physics is one of the most fundamental scientific disciplines, and its main goal is to understand how the universe behaves.', 'Physics', '2010-1-1');SELECT id, body, title FROM tsearch.pgweb WHERE to_tsvector('english', body) @@ to_tsquery('english', 'science'); id | body | title ----+-------------------------------------------------------------------------------------------------------------------------+--------- 2 | Mathematics is the science that deals with the logic of shape, quantity and arrangement. | Mathematics 3 | Computer science is the study of processes that interact with data and that can be represented as data in the form of programs. | Computer science 5 | Geography is a field of science devoted to the study of the lands, features, inhabitants, and phenomena of the Earth and planets. | Geography 7 | Medical science is the science of dealing with the maintenance of health and the prevention and treatment of disease. | Medical science(4 rows) 像science这样的相关词都会被找到,因为这些词都被处理成了相同标准的词条。 上面的查询指定english配置来解析和规范化字符串。也可以省略此配置,通过default_text_search_config进行配置设置: 1 2 3 4 5 6 7 8 910111213141516 SHOW default_text_search_config; default_text_search_config ---------------------------- pg_catalog.english(1 row)SELECT id, body, title FROM tsearch.pgweb WHERE to_tsvector(body) @@ to_tsquery('science'); id | body | title ----+-------------------------------------------------------------------------------------------------------------------------+--------- 2 | Mathematics is the science that deals with the logic of shape, quantity and arrangement. | Mathematics 3 | Computer science is the study of processes that interact with data and that can be represented as data in the form of programs. | Computer science 5 | Geography is a field of science devoted to the study of the lands, features, inhabitants, and phenomena of the Earth and planets. | Geography 7 | Medical science is the science of dealing with the maintenance of health and the prevention and treatment of disease. | Medical science(4 rows) 一个复杂查询:检索出在title或者body字段中包含treatment和science的最近10篇文档: 12345 SELECT title FROM tsearch.pgweb WHERE to_tsvector(title || ' ' || body) @@ to_tsquery('treatment & science') ORDER BY last_mod_date DESC LIMIT 10; title --------Medical science(1 rows) 为了清晰,举例中没有调用coalesce函数在两个字段中查找包含NULL的行。 以上例子均在没有索引的情况下进行查询。对于大多数应用程序来说,这个方法很慢。因此除了偶尔的特定搜索,文本搜索在实际使用中通常需要创建索引。 父主题: 在数据库表中搜索文本
-
解析器测试 函数ts_parse可以直接测试文本搜索解析器。 12 ts_parse(parser_name text, document text, OUT tokid integer, OUT token text) returns setof record ts_parse解析指定的document并返回一系列的记录,一条记录代表一个解析生成的token。每条记录包括标识token类型的tokid,及token文本。比如: 1 2 3 4 5 6 7 8 910 SELECT * FROM ts_parse('default', '123 - a number'); tokid | token-------+-------- 22 | 123 12 | 12 | - 1 | a 12 | 1 | number(6 rows) 12 ts_token_type(parser_name text, OUT tokid integer, OUT alias text, OUT description text) returns setof record ts_token_type返回一个表,这个表描述了指定解析器可以识别的每种token类型。对于每个token类型,表中给出了整数类型的tokid--用于解析器标记对应的token类型;alias——命名分词器命令中的token类型;及简单描述。比如: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627 SELECT * FROM ts_token_type('default'); tokid | alias | description -------+-----------------+------------------------------------------ 1 | asciiword | Word, all ASCII 2 | word | Word, all letters 3 | numword | Word, letters and digits 4 | email | Email address 5 | url | URL 6 | host | Host 7 | sfloat | Scientific notation 8 | version | Version number 9 | hword_numpart | Hyphenated word part, letters and digits 10 | hword_part | Hyphenated word part, all letters 11 | hword_asciipart | Hyphenated word part, all ASCII 12 | blank | Space symbols 13 | tag | XML tag 14 | protocol | Protocol head 15 | numhword | Hyphenated word, letters and digits 16 | asciihword | Hyphenated word, all ASCII 17 | hword | Hyphenated word, all letters 18 | url_path | URL path 19 | file | File or path name 20 | float | Decimal notation 21 | int | Signed integer 22 | uint | Unsigned integer 23 | entity | XML entity(23 rows) 父主题: 测试和调试文本搜索
-
解析文档 GaussDB (DWS)中提供了to_tsvector函数把文档处理成tsvector数据类型。 1 to_tsvector([ config regconfig, ] document text) returns tsvector to_tsvector将文本文档解析为token,再将token简化到词素,并返回一个tsvector。其中tsvector中列出了词素及它们在文档中的位置。文档是根据指定的或默认的文本搜索分词器进行处理的。这里有一个简单的例子: 1234 SELECT to_tsvector('english', 'a fat cat sat on a mat - it ate a fat rats'); to_tsvector----------------------------------------------------- 'ate':9 'cat':3 'fat':2,11 'mat':7 'rat':12 'sat':4 通过以上例子可发现结果tsvector不包含词a、on或者it,rats变成rat,并且忽略标点符号-。 to_tsvector函数内部调用一个解析器,将文档的文本分解成token并给每个token指定一个类型。对于每个token,有一系列词典可供查询。词典系列因token类型的不同而不同。识别token的第一本词典将发出一个或多个标准词素来表示token。例如: rats变成rat因为词典认为词rats是rat的复数形式。 有些词被作为停用词(请参考停用词),这样它们就会被忽略,因为它们出现得太过频繁以致于搜索中没有用处。比如例子中的a、on和it。 如果没有词典识别token,那么它也被忽略。在这个例子中,符号“-”被忽略,因为词典没有给它分配token类型(空间符号),即空间符号永远不会被索引。 语法解析器、词典和要索引的token类型由选定的文本搜索分词器决定。可以在同一个数据库中有多种不同的分词器,以及提供各种语言的预定义分词器。在以上例子中,使用缺省分词器english。 函数setweight可以给tsvector的记录加权重,权重是字母A、B、C、D之一。这通常用于标记来自文档不同部分的记录,比如标题、正文。之后,这些信息可以用于排序搜索结果。 因为to_tsvector(NULL)会返回空,当字段可能是空的时候,建议使用coalesce。以下是推荐的为结构化文档创建tsvector的方法: 1 2 3 4 5 6 7 8 910 CREATE TABLE tsearch.tt (id int, title text, keyword text, abstract text, body text, ti tsvector);INSERT INTO tsearch.tt(id, title, keyword, abstract, body) VALUES (1, 'book', 'literature', 'Ancient poetry','Tang poem Song jambic verse');UPDATE tsearch.tt SET ti = setweight(to_tsvector(coalesce(title,'')), 'A') || setweight(to_tsvector(coalesce(keyword,'')), 'B') || setweight(to_tsvector(coalesce(abstract,'')), 'C') || setweight(to_tsvector(coalesce(body,'')), 'D');DROP TABLE tsearch.tt; 上例使用setweight标记已完成的tsvector中的每个词的来源,并且使用tsvector连接操作符||合并标记过的tsvector值,处理tsvector一节详细介绍了这些操作。 父主题: 控制文本搜索
-
ts_token_type(parser_name text, OUT tokid integer, OUT alias text, OUT description text) 描述:获取分析器定义的记号类型。 返回类型:setof record 示例: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627 SELECT ts_token_type('default'); ts_token_type -------------------------------------------------------------- (1,asciiword,"Word, all ASCII") (2,word,"Word, all letters") (3,numword,"Word, letters and digits") (4,email,"Email address") (5,url,URL) (6,host,Host) (7,sfloat,"Scientific notation") (8,version,"Version number") (9,hword_numpart,"Hyphenated word part, letters and digits") (10,hword_part,"Hyphenated word part, all letters") (11,hword_asciipart,"Hyphenated word part, all ASCII") (12,blank,"Space symbols") (13,tag,"XML tag") (14,protocol,"Protocol head") (15,numhword,"Hyphenated word, letters and digits") (16,asciihword,"Hyphenated word, all ASCII") (17,hword,"Hyphenated word, all letters") (18,url_path,"URL path") (19,file,"File or path name") (20,float,"Decimal notation") (21,int,"Signed integer") (22,uint,"Unsigned integer") (23,entity,"XML entity")(23 rows)
-
ts_stat(sqlquery text, [ weights text, ] OUT word text, OUT ndoc integer, OUT nentry integer) 描述:获取tsvector列的统计数据。 返回类型:setof record 示例: 123456 SELECT ts_stat('select ''hello world''::tsvector'); ts_stat ------------- (world,1,1) (hello,1,1)(2 rows)
-
ts_debug([ config regconfig, ] document text, OUT alias text, OUT description text, OUT token text, OUT dictionaries regdictionary[], OUT dictionary regdictionary, OUT lexemes text[]) 描述:测试一个配置。 返回类型:setof record 示例: 123456789 SELECT ts_debug('english', 'The Brightest supernovaes'); ts_debug ----------------------------------------------------------------------------------- (asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) (blank,"Space symbols"," ",{},,) (asciiword,"Word, all ASCII",Brightest,{english_stem},english_stem,{brightest}) (blank,"Space symbols"," ",{},,) (asciiword,"Word, all ASCII",supernovaes,{english_stem},english_stem,{supernova})(5 rows)
-
ts_parse(parser_name text, document text, OUT tokid integer, OUT token text) 描述:测试一个解析。 返回类型:setof record 示例: 12345678 SELECT ts_parse('default', 'foo - bar'); ts_parse ----------- (1,foo) (12," ") (12,"- ") (1,bar)(4 rows)
更多精彩内容
CDN加速
GaussDB
文字转换成语音
免费的服务器
如何创建网站
域名网站购买
私有云桌面
云主机哪个好
域名怎么备案
手机云电脑
SSL证书申请
云点播服务器
免费OCR是什么
电脑云桌面
域名备案怎么弄
语音转文字
文字图片识别
云桌面是什么
网址安全检测
网站建设搭建
国外CDN加速
SSL免费证书申请
短信批量发送
图片OCR识别
云数据库MySQL
个人域名购买
录音转文字
扫描图片识别文字
OCR图片识别
行驶证识别
虚拟电话号码
电话呼叫中心软件
怎么制作一个网站
Email注册网站
华为VNC
图像文字识别
企业网站制作
个人网站搭建
华为云计算
免费租用云托管
云桌面云服务器
ocr文字识别免费版
HTTPS证书申请
图片文字识别转换
国外域名注册商
使用免费虚拟主机
云电脑主机多少钱
鲲鹏云手机
短信验证码平台
OCR图片文字识别
SSL证书是什么
申请企业邮箱步骤
免费的企业用邮箱
云免流搭建教程
域名价格