扩展SPARQL的室内空间语义查询研究
作者简介:李灿(1992-),女,硕士生,河北石家庄人,研究方向为网络GIS。E-mail:lican1992@whu.edu.cn
收稿日期: 2015-10-08
要求修回日期: 2015-11-02
网络出版日期: 2015-12-20
基金资助
国家科技支撑计划项目(2012BAH35B03)
武汉市科技计划项目(2013010501010146)
Research on Indoor Semantic Query Based on Expansion of SPARQL
Received date: 2015-10-08
Request revised date: 2015-11-02
Online published: 2015-12-20
Copyright
针对室内空间特点以及人类对室内位置服务的迫切需求,探讨了适合室内空间语义查询的方法。基于全息位置地图室内空间本体模型,描述室内空间对象及与之相关的人、事的属性信息及其关系,以室内空间本体概念及其属性作为查询原语,增加查询函数实现室内特有的空间关系(如“对面”、“楼上”和“楼下”等)的计算与查询,扩展了SPARQL查询语言基本语法。设计了室内本体查询语言IndoorSPARQL,开发自定义查询语言解析器,初步实现了顾及空间计算的室内空间语义查询。最后,利用Protégé本体建模工具对试验区进行本体实例建模,采用自定义查询语言IndoorSPARQL进行室内语义查询,并将结果可视化。实验结果表明,基于自定义语言IndoorSPARQL的查询方法可有效地支持顾及室内空间计算的复杂语义查询。
关键词: IndoorSPARQL; 室内语义查询; 本体建模; 室内空间关系
李灿 , 朱欣焰 , 呙维 , 黄亮 , 杨龙龙 . 扩展SPARQL的室内空间语义查询研究[J]. 地球信息科学学报, 2015 , 17(12) : 1456 -1464 . DOI: 10.3724/SP.J.1047.2015.01456
Recently, human activity focuses have expanded from outdoor to indoor space. Since building construction is becoming more and more complex, in order to better support the indoor activities, there is an urgent need for the querying services of indoor space. According to the characteristics of indoor space, this paper puts forward a method suitable for the complex indoor semantic query. An ontology model describing the indoor space and the relavant information of humans, events and spaceobjects as well as their relations is adopted to meet the demand of indoor semantic query. This paper also designs the IndoorSPARQL ontology query language which is an extension of the SPARQL syntax to support the indoor semantic query. Ontology concepts and their attributes are used as query vocabularies. In addition, query functions are designed to compute unique indoor space relations, such as “opposite relation”, “upstairs relation” and “downstairs relation”. A method is proposed in analyzing IndoorSPARQL query language to support indoor ontology query, which considers the computation of indoor spatial relations. Finally, based on the ontology model, experiments within the study area are constructed using a software named Protégé. Examples of indoor semantic query that use the IndoorSPARQL query language are provided, with the visualization of their results. The results show that the proposed query method based on IndoorSPARQL could effectively support indoor space complex semantic query. This method has presented the following advantages: (1) the ontology model provides a complete and clear expression of the space related information on humans, events and indoor space objects (e.g. the “Storey” and “Room”) as well as their inner relations, which is taken as the basis of the complex semantic query; (2) the specific primitives for indoor query, including “Adjacent”, “Opposite”, “Vertical” and “Contain”, are defined as the query functions in IndoorSPARQL to support the quantitative indoor spatial computations; (3) th query language IndoorSPARQL is designed and testified in this paper to support the proposed method of indoor semantic query.
Key words: indoor space; ontology; semantic query; SPARQL; indoor spatial relation
Tab. 1 Query function of indoor spatial relation表1 室内空间关系查询函数 |
空间关系 | 查询函数 | 函数描述 |
---|---|---|
对面关系 | boolean Opposite(String iri1, String iri2) | 判断2个本体实例是否存在对面关系 |
楼下关系 | boolean DownStairs(String iri1,String iri2) | 判断iri2代表的本体实例是否在iri1代表的本体实例的楼下 |
楼上关系 | boolean UpStairs(String iri1,String iri2) | 判断iri2代表的本体实例是否在iri1代表的本体实例的楼上 |
相邻关系 | boolean Adjacent(String iri1, String iri2) | 判断2个本体实例是否有相邻关系 |
包含关系 | boolean Contain(String iri1,String iri2) | 判断iri1代表的本体实例在空间上是否包含iri2代表的本体实例 |
算法1 算法oppositeRoom(String roomID)伪代码 |
输入:roomID:室内空间对象在空间数据库中存储的ID |
---|
输出:List<String>:与ID为roomID的对象符合对面关系的空间对象的ID列表 |
room_IDs = List /*对面关系计算结果列表*/ door_IDs= found_doors(roomID) /*找到房间room_IDs的所有出 入口对象的ID列表*/ cooridor_ID=found_cooridor(roomID)/*找到房间roomID所在走 廊的ID*/ candidate_IDs = found_rooms(cooridor_ID)/*找到走廊上所有房 间作为候选结果*/ |
for each door_id in door_IDs do cooridor_dir = cooridor_direction(cooridor_ID,roomID)/*计算走 廊cooridor_ID 的出入口door_id所在一侧的方向*/ for each candidate_id in candidate_IDs do connect_dir = connectline_direction(roomID, candidate_id)/*计算 两个房间对象出入口连接线的方向*/ angle = cooridor_dir - connect_dir ifangle < 0 then angle = angle + 360 ifangle > 180 then angle = 360 - angle ifangle >= 45 ifangle <= 135 then room_IDs.add(connect_dir) |
Fig. 1 The process of parsing IndoorSPARQL language图1 IndoorSPARQL查询语言解析流程 |
算法2 算法panMapSearch(String queryStatement)伪代码 |
输入:queryStatement:符合IndoorSPARQL查询语言语法的查询表达式 |
---|
输出:Map<String, ArrayList<String>>: 查询结果,key值为查询变量名称,value值为查询结果实例IRI列表 |
lexer = SparqlLexer(queryStatement); tokens = CommonTokenStream(lexer) /*对查询表达式进行 词法分析*/ parser = SparqlParser(tokens) /*对查询表达式进行语法分析*/ treePackage = parser.query()/*生成查询表达式对应的抽象语法树*/ |
walker.walk(this, treePackage) /*遍历抽象语法树,walker为ParseTreeWalker类实例*/ excuteVar = ParseExcuteVar() /*保存查询过程中间变量*/ Triples = List<Triple> /*保存查询语句中的三元组语句信息,如主语、谓语、宾语等*/ Filters = List<Filters> /*保存查询语句中的约束语句信息,如空间关系计算函数、逻辑运算符等*/ if node为prefix节点do /*node 表示某一个语法树节点*/ variable = Variable(node) excuteVar.Vars.add(variable)/*保存查询IRI根地址,用于扩展解析相关节点的相对IRI*/ if node为select节点do variable = Variable(node) variable.IsSelected = true excuteVar. Vars.add(variable)/*保存查询语句需要返回的变量信息*/ if node为三元组语句节点do triple = Triple(node) Triples.add(triple)/*保存三元组语句信息,为其绑定三元组 语句处理逻辑*/ if node为filter约束语句节点do filter= Filter (node) Filters.add(triple)/*保存Filter语句信息,为其绑定filter 语句处理逻辑*/ foreach triple in Triples do triple. triple_excute() foreach filter in Filters do excuteVar.FilterVars.clear();// 进入新的filter 要清空此变量 excuteVar.FilterVars.add() /*保存约束语句中需要进行值 约束的变量*/ filter. triple_excute() filter_loop(excuteVar.FilterVars.size()-1, filter)/*嵌套循环处理filter约束语句*/ filter_excute_update();执行完一个filter约束语句后对约束的变量FilterVars进行更新到Vars变量中 for each triple in Triples do /*回溯三元组语句,从后往前遍历*/ if triple包含FilterVars中的变量then triple.tripleExcute() resultSet = SelectResult()/*得到最终查询语句需要的结果*/ |
算法3 算法filter_loop(int count, Filters filter)伪代码 |
输入:count:需要约束的变量在约束变量FilterVars数组中的位置;Filter:Filters类对象,保存filter约束语句信息,包括函数调用信息或者逻辑运算符等 |
---|
输出:无 |
Vars = excuteVar.FilterVars.get(count)/*当前层循环需要约束的变量值数组*/ for each var in vars do if count != 0 then Temp = count -1 filter_loop(Temp,filter) if count = 0 then /*到达最底层循环*/ if filter为空间关系判断函数then result = filter_excute_exper()/*根据函数名称调用相应的空间关系判断函数*/ elsefilter 逻辑操作符运算语句then result = filter_excute_exper() if result=true then 更新被约束变量 else if result = false then 剔除当前变量的当前值 |
Fig. 2 The results of example query 1图2 实例1查询结果 |
Fig. 3 The results of example query 2图3 实例2查询结果 |
The authors have declared that no competing interests exist.
[1] |
|
[2] |
|
[3] |
|
[4] |
|
[5] |
|
[6] |
|
[7] |
|
[8] |
|
[9] |
|
[10] |
|
[11] |
|
[12] |
|
[13] |
|
[14] |
|
[15] |
|
[16] |
|
[17] |
|
[18] |
|
/
〈 |
|
〉 |