Page 169 - 《软件学报》2026年第3期
P. 169
1132 软件学报 2026 年第 37 卷第 3 期
运算符用于计算距离. 该运算符与 ORDER BY 子句一起集成到查询中, 便于根据计算的距离按升序对结果排序.
为了进一步细化输出, 应用了 LIMIT 子句, 将结果限制为前 k 个空间对象.
表 3 SECONDO 和 PostGIS 的结构化语言模型
结构化语言模型要素 SECONDO PostGIS
query <value expression>; SELECT <value expression>;
数据库查询语言L let <identifier> = <value expression>; CREATE <object> <identifier>;
delete <identifier>; DROP <object> <identifier>;
distance ST_Distance
area ST_Area
运算符O
intersects ST_Intersects
intersection ST_Intersection
实体E E = E k ∪ E d ∪ E rel ∪ E loc
query distance (<location1>, <location2>); SELECT ST_Distance (<location1>, <location2>);
结构化语言模型SLM query <relation> feed filter [.GeoData intersects SELECT * FROM <relation> WHERE ST_Intersects
<location>] consume; (<relation> .GeoData, <location>);
4.3 可执行语言生成案例
基于自然语言理解阶段识别的查询类型选择匹配的结构化语言模型, 然后通过映射规则将空间数据查询实
体 E 中的每个元素对应到模型实体槽集合{<k>, <d>, <relation>, <location>}中相应的元素, 生成可执行语言. 最近
邻居数 k、距离阈值 d 和查询地点 location 在查询中是唯一的, 所以唯一对应于模型中的<k>, <d>和<location>. 空
间关系 relation 在最近邻居查询和范围查询中只有一个, 在空间 Join 查询和聚合查询中有多个. 当查询涉及多个
不同的空间关系时, 要根据关系的空间属性和运算符确定映射规则. 每类查询的可执行语言生成示例详见附录 A.
在生成空间数据库可执行语言后, 通过结合空间索引和查询计划优化技术, 能够显著提高查询的执行效率和
性能. 在 SECONDO 系统中, 使用 derive 命令创建空间索引, 使用 delete 命令删除索引, 语法如下.
derive <r-tree name> = <relation> creatertree[<attribute>];
delete <r-tree name>;
其中, <relation> 为索引的空间关系, <r-tree name> 为索引名称, <attribute> 为 <relation> 用于索引的属性.
以南京市地理信息数据集为例, 空间关系如下.
district(Name:string, GeoData:region)
university(Name:string, GeoData:region)
road(Name:string, GeoData:line, Rid:int)
junction(R1id:int, R2id:int, GeoData:point)
poi(Name:string, Type:string, GeoData:point)
park(Name:string, GeoData:point)
案例 1: What are the roads that intersect the Zhixing Road?
自然语言理解阶段得到的类型为范围查询, 空间关系为 road, 查询地点为 Zhixing Road. 基于映射规则, 将关
键实体信息映射到结构化语言模型中, 生成可执行语言为:
query road feed filter [.GeoData intersects (road feed filter [.Name = “Zhixing Road”] extract[GeoData])] consume;
在该查询中, road 的空间属性和 Zhixing Road 的数据类型均为 line, 所以使用运算符 intersects 判断是否相交.
由地点知识库可得 Zhixing Road 存储于关系 road 中, 那么使用 (road feed filter [.Name = “Zhixing Road”] extract[GeoData])
映射到结构化语言模型中的<location>, 而不是 Zhixing Road.
接下来进行查询优化, 先为空间关系创建 R 树索引, 用于快速定位可能与查询地点相交的空间对象.
derive tmp_rtree = road creatertree[GeoData];
然后使用 bbox 运算符返回查询地点的边界框, 使用 windowintersects 运算符基于 R 树索引查找空间关系中

