[IR] XPath for Search Query
XPath 1.0
XPath Containment
Distributed Query Evaluation
RE and DFA
XPath 1.0
-- 在XML中的使用
XPath 语法: http://www.w3school.com.cn/xpath/xpath_syntax.asp
XPath (红色字体) 示例:
/bib/book/year
Result: <year> 1995 </year>
<year> 1998 </year> /bib/paper/year
Result: empty
XPath: Restricted Kleene Closure 暴力查找node的感觉
//author
Result: <author> Serge Abiteboul </author>
<author> <first-name> Rick </first-name>
<last-name> Hull </last-name>
</author>
<author> Victor Vianu </author>
<author> Jeffrey D. Ullman </author> /bib//first-name
Result: <first-name> Rick </first-name>
XPath: Text Nodes 提取 (无子结构的) elem
/bib/book/author/text()
Result: Serge Abiteboul
Victor Vianu
Jeffrey D. Ullman
XPath: Text Nodes 提取 (有子结构的) elem
//author/*
Result: <first-name> Rick </first-name>
<last-name> Hull </last-name>
XPath: Attribute Nodes 提取属性的内容
/bib/book/@price
Result: “55”
XPath: Qualifiers 只要有firstname子节点的元素
/bib/book/author[firstname]
Result: <author> <first-name> Rick </first-name>
<last-name> Hull </last-name>
</author>
XPath: Qualifiers 只要条件为:有firstname子节点和address子节点,且address中下的某一level中有zip节点,以及下一level就得有city。满足如此条件的author下的lastname的内容。
/bib/book/author[firstname][address[//zip][city]]/lastname
Result: <lastname> ... </lastname>
<lastname> ... </lastname>
XPath: 子节点的属性满足指定条件
/bib/book[@price < “60”]
/bib/book[author/@age < “25”]
XPath: author下的elem只允许有txt。
/bib/book[author/text()]
XPath 轴: 轴可定义相对于当前节点的节点集
轴可定义相对于当前节点的节点集。
轴名称 | 结果 |
---|---|
ancestor | 选取当前节点的所有先辈(父、祖父等)。 |
ancestor-or-self | 选取当前节点的所有先辈(父、祖父等)以及当前节点本身。 |
attribute | 选取当前节点的所有属性。 |
child | 选取当前节点的所有子元素。 |
descendant | 选取当前节点的所有后代元素(子、孙等)。 |
descendant-or-self | 选取当前节点的所有后代元素(子、孙等)以及当前节点本身。 |
following | 选取文档中当前节点的结束标签之后的所有节点。 |
namespace | 选取当前节点的所有命名空间节点。 |
parent | 选取当前节点的父节点。 |
preceding | 选取文档中当前节点的开始标签之前的所有节点。 |
preceding-sibling | 选取当前节点之前的所有同级节点。 |
self | 选取当前节点。 |
XPath Containment
Return Node: [[name]] 使用double circles表示。
任意深度子目录存在:双斜线。
表达式解释:
root下的任意未知结点person,满足孩子中有name,任意子孙中需有属性zip = "12345"的结点。
满足以上条件,则返回这个person的phone。
Equivalence, Containment
- E = E’ if they return the same result
- E ⊆ E’ if the result returned by E is a subset of that returned by E’.
返回的结果总是一致的,我们认为这是一个query。
这个比较复杂,所以我们引入一种方法来解决:
Practical Algorithm for Linear XPath *,//
关键在于找到mapping。
第一个例子:
第二个例子:
第三个例子:
为何不等价?
应该是前者包含后者!
注意1:/*// 转化为双线。
注意2://name 这里没有*,所以是>=0,这导致了两者不等价!
Branching XPath *,//
-- 难度加大,计算量大
视情况而定,此处略。
Distributed Query Evaluation
a.b*.c // any num of b, here we regard it as a Query.
a.b+.c // at least one num of b
Review 正则表达式 与 DFA 的关系
在分布式环境下的Query,如下:(如用在下图中查询这个Query)
A naïve approach takes too many communication steps
=> we have to do more work locally
A better approach needs to
1. identify all external references
2. identify targets of external references
Algorithm:
1. Given a query, we compute its automaton 计算出某一个query的对应的一个东西
2. Send it to each site 将这个东西分发给各个site
3. Start an identical process at each site 各个site分别处理这个东西
4. Compute two sets Stop(n, s) and Result(n, s) 计算出这两个结果
5. Transmits the relations to a central location and get their union 合并所有结果
Detail:
每个site都会有自己的一个《进出表》,如下:
Site 1:
In | x1, x4 |
Out | y1, y3 |
Site 2:
In | y1, y3 |
Out | z2 |
Site 3:
In | z2 |
Out | x4 |
相对于Query: a.b+.c
以 Site 2 为例,该site将处理query并得到如下两个table:
《搞不定表》- Stop Table
Start | End |
(y1, s2) | (z2, s2) |
(y3, s2) | (z2, s2) |
这里的z2怎么得来?Site 2虽然不晓得其他site的信息,但起码知道
与自己有直接连接的node信息。比如:
与y3直接相连接的z2有可能作为s2。
《能搞定表》- Result Table
Start | End |
(y1, s2) | (y3, s3) |
(y1, s3) | (y1, s3) |
(y3, s3) | (y3, s3) |
然后,每个site都应该返回了针对该query的俩表。
接下来就是如何合并这么些个表的问题。
让我们将整个表都列出来,做一次傻瓜式的demo。
Union:
Start | Stop | Start | Result | ||
(x1, s1) | (y1, s2) | stop1 | (x1, s3) | x1 | result1 |
(x4, s2) | (y3, s3) | stop2 | (x4, s2) | x3 | result2 |
(y1, s2) | (z2, s2) | stop3 | (x4, s3) | x4 | result3 |
(y3, s2) | (z2, s2) | stop4 | (y1, s2) | y3 | result4 |
(z2, s2) | (x4, s2) | stop5 | (y1, s3) | y1 | result5 |
(y3, s3) | y3 | result6 | |||
(z2, s1) | z3 | result7 | |||
(z2, s2) | z2 | result8 | |||
(z2, s3) | z2 | result9 |
解说:
root | ||
stop1 | 在其他site能直接终止么? | |
result4 | 还真有,可以直接结束! | 匹配到了(y1,s2) |
stop3 | 不结束,绕一绕,其他site或许能给出新的sol | 匹配到了(y1,s2) |
result8 | 确实有,可以直接结束! | 匹配到了(z2,s2) |
stop5 | 不结束,绕一绕,其他site或许能给出新的sol | 匹配到了(z2,s2) |
result2 | 还真有,可以直接结束! | 匹配到了(x4,s2) |
stop2 | 不结束,绕一绕,其他site或许能给出新的sol | 匹配到了(x4,s2) |
result6 | 有的啦,可以直接结束! | |
n/a | 不结束,绕一绕,其他site或许能给出新的sol | 匹配不到了! |
Answer:
{y3, z2, x3}
Regular Expression (正则表达式)
定义:
This definition may seem circular, but 1-3 form the basis
Precedence: Parentheses have the highest precedence,
followed by *, concatenation, and then union.
RE Examples (表达形式 = 实际的集合形式)
-- 当search时希望return results in this kind of pattern.
• L(001) = {001}
• L(0+1*) = { 0, 1, 10, 100, 1000, 10000, … } // union: or; * any number of
• L(0*1*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has exactly a single 1}
• L( |- |- )* = {w | w is a string of even length}
• L((0(0+1))*) = { ε, 00, 01, 0000, 0001, 0100, 0101, …}
• L((0+ε)(1+ ε)) = {ε, 0, 1, 01}
• L(1Ø) = Ø ; concatenating the empty set to any set yields the empty set.
• Rε = R // ε就像1
• R+Ø = R // 空集就像0
Exercise 1
∑ = {10, 11}, ∑* = {є, 10, 11, 1010, 1011, 1110, 1111, …}
表示集合里元素的数量各自都是任意的,然后组合在一起。
Exercise 2
L1 = {10, 1}, L2 = {011, 11}, L1L2 = {10011, 1011, 111}
哄小孩的题。
Exercise 3
Write RE for
– All strings of 0’s and 1’s (其实就是任意0与1的组合)
• (0|1)*
– All strings of 0’s and 1’s with at least 2 consecutive 0’s (需要至少有连续的0)
• (0|1)*00(0|1)*
– All strings of 0’s and 1’s beginning with 1 and not having two consecutive 0’s (不能有连续的0)
• (1+10)* // {1, 10} 其中的元素任意组合确实不会有连续的0出现,技巧哉!
More exercises
1) (0|1)*
• Answer: all strings of 0’s and 1’s ending in 011
2) 0*1*2*
• Answer: any number of 0’s followed by any number of 1’s followed by any number of 2’s
3) 00*11*22*
• Answer: strings in 0*1*2 with at least one of each symbo
Link: 百度百科
起源:
引擎
这里只简单瞧瞧 DFA (Deterministic Finite Automata),"确定有限状态自动机"。
b*a*b*a*b* 有循环,可见是个环。
Duality: RE与DFA的等价性
局限性:
Which languages CANNOT be described by any RE?
• Set of all bit strings with equal number of 0s and 1s. // 没有计数相关功能
• Set of all decimal strings that represent prime numbers. // 又不是人工智能,:p
ab*a
可见,b有环。
a(a|b)*a
可见,(a|b)有环。思考环的构造,如下:
DFA to RE: State Elimination
• Eliminates states of the automaton and replaces the edges with regular expressions that includes the behavior of the eliminated states.
• Eventually we get down to the situation with just a start and final node, and this is easy to express as a RE
We can describe this automaton as: (R | SU*T)*SU*
分析:
对于第一个node来说,有两条路径:
- R自循环
- SU*T绕一圈后再回来
然后考虑end node:也是两条路径:
- U自循环
- “SU*T绕一圈后再回来”+S
于是便构成了: (R | SU*T)*SU*
We can describe this automaton as simply R*
标准的elimination过程
Example One:
1) First convert the edges to RE’s.
注意:简化的过程中不要丢失信息。
2) 有个环,精简它。
3) 3-->1-->2的过程不能丢失,所以保留"11"。
Answer: (0+10)*11(0+1)*
Example Two:
1) First convert the edges to RE’s.
注意:简化的过程中不要丢失信息。
2) 有个环,精简它。
3) 1-->2-->3的过程不能丢失,所以保留"10*1"。
注意:这里有两个end node。
策略:关掉node 1,计算;再关掉node 2,计算。
关掉node 3:
0*
关掉node 1:
0*10*1(0|10*1)*
合并结果(或操作):
0* | 0*10*1(0|10*1)*
[IR] XPath for Search Query的更多相关文章
- elastic search query & filter & query_string
一.基本概念 1.query时,如何指定返回哪些字段 希望返回name和date字段 希望返回以location.*为前缀的字段以及date字段:不希望返回location.geolocation字段 ...
- [IR] Open Source Search Engines
From:http://blog.csdn.net/xum2008/article/details/8740063 本文档是对现有的开源的搜索引擎的一个简单介绍 1. Lucene Lucene ...
- [IR] What is XML
Concept: http://www.w3school.com.cn/xml/xml_cdata.asp Semistructured: 和普通纯文本相比,半结构化数据具有一定的结构性.OEM(Ob ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- [Python] 02 - String
字符串 string 一.基本性质 不变性 Immutability 要变就 --> list --> string 二.功能函数 功能函数 S = 'Spam" S.find( ...
- lucene 3.0.2 search 各种各样的Query类型
http://blog.sina.com.cn/s/blog_61d2047c010195mo.html lucene的这种各种各样的查询类型 1.TermQuery 最简单的Qu ...
- lucene查询索引之Query子类查询——(七)
0.文档名字:(根据名字索引查询文档)
- SharePoint 2013 Search REST API 使用示例
前言:在SharePoint2013中,提供Search REST service搜索服务,你可以在自己的客户端搜索方法或者移动应用程序中使用,该服务支持REST web request.你可以使用K ...
- Query DSL for elasticsearch Query
Query DSL Query DSL (资料来自: http://www.elasticsearch.cn/guide/reference/query-dsl/) http://elasticsea ...
随机推荐
- JDBC(4)—Preparedstatement
功能:使用PreparedStatement操作数据表,其功能与Statement一致,但为何要使用PreparedStatement呢. 一.原因: 1.使用sql语句进行操作数据表时,需要拼写sq ...
- ArcGIS Pro 获得工具的个数
import arcgisscripting import string; gp = arcgisscripting.create(9.3); ##多少个工具箱 toolboxes = gp.list ...
- centos7 设置tomcat自启动
1 .vi /etc/init.d/tomcat8 #!/bin/bash # # tomcat startup script for the Tomcat server # # chkconfig ...
- Android四大组件应用系列5——使用AIDL实现跨进程调用Service
一.问题描述 Android应用程序的四大组件中Activity.BroadcastReceiver.ContentProvider.Service都可以进行跨进程.在上一篇我们通过ContentPr ...
- 微信小程序的同步操作
小程序里,大多数操作都是异步操作,一些重要的操作,如从网上获取重要变量值,必须要保证有值,后续操作才有意义.但异步操作,又必须把处理放到回调中,代码可读性降低,而且和大多数正常逻辑相背. 折腾了两天, ...
- 解决IDEA授权报错
今天打开电脑,猛然发现IDEA授权失效,然后重新用账号密码登陆,发现被拒绝,各种百度百思不得其解,抱着试试的态度,点击了重置密码 https://account.jetbrains.com/forgo ...
- 关于Android中EditText自动获取焦点并弹出键盘的相关设置
在android开发中,关于EditText自动获取焦点弹出键盘,我们可能又是会有让键盘自动弹出的需求,有时可能又会有不想让键盘自动弹出的需求,下面是我所总结的两种方法: 需求:EditText自动获 ...
- 【PMP】项目和运营的区别
运营管理关注产品的持续性生产和服务的持续运作. 项目与运营会存在产品生命周期的不同时点交叉,例如: 在产品开发.产品升级或提高产量时: 在改进运营或产品开发流程时: 在产品生命周期结束阶段: 在每个收 ...
- 【SqlServer】SqlServer的常规操作
创建一张新表,不负责任何数据(该表不会有原来表的主键.索引等等) select * into NewTable from OldTable where 1<>1; 创建一张新表,并且复制旧 ...
- CSS3 选择器 基本选择器介绍
CSS是一种用于屏幕上渲染html,xml等一种语言,CSS主要是在相应的元素中应用样式,来渲染相对应用的元素,那么这样我们选择相应的元素就很重要了,如何选择对应的元素,此时就需要我们所说的选择器.选 ...