插入有序列表中的位置 Ontology
Insert into position in Ordered List Ontology
我有一个 Ordered List Ontology 的列表实现,我想编写 SPARQL 查询以插入到列表的特定位置。我的想法是这是 2 个步骤的过程。鉴于我的列表是基于 0 的,我想插入位置 N:
- 将 index 的项目 index >= N 更改为 index +1
- 插入新的插槽到位置N
我正在为应该为插槽重新编制索引的更新而苦苦挣扎。我正在尝试的是:
DELETE {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?index .
?slot <http://purl.org/ontology/olo/core#item> ?item
}
INSERT {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?newIndex .
?slot <http://purl.org/ontology/olo/core#item> ?item
}
WHERE {
FILTER(?index >= TARGET_INDEX) # Here would be the numeric value of target index
BIND((?index + 1) AS ?newIndex)
}
即使查询运行完成,插槽的索引也不会更新。任何关于我做错的建议将不胜感激。
注意: Slots 是空白节点,不确定这是否重要,但只是为了确保您了解所有详细信息。
您的 WHERE 没有三重模式,因此它不会产生任何绑定,因此 INSERT 和 DELETE 无事可做。 WHERE 部分需要找到项目、索引等的绑定。仅对于索引部分,您需要 select 所有需要更新索引的插槽及其新索引,然后使用 WHERE 部分执行此操作.然后删除具有旧索引的单个三元组,并插入具有新索引的单个三元组。请注意,您甚至不需要 select ?item 的值,只需要插槽和索引。它看起来像这样:
DELETE {
?slot <http://purl.org/ontology/olo/core#index> ?index .
}
INSERT {
?slot <http://purl.org/ontology/olo/core#index> ?newIndex .
}
WHERE {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?index .
FILTER(?index >= TARGET_INDEX) # Here would be the numeric value of target index
BIND((?index + 1) AS ?newIndex)
}
我有一个 Ordered List Ontology 的列表实现,我想编写 SPARQL 查询以插入到列表的特定位置。我的想法是这是 2 个步骤的过程。鉴于我的列表是基于 0 的,我想插入位置 N:
- 将 index 的项目 index >= N 更改为 index +1
- 插入新的插槽到位置N
我正在为应该为插槽重新编制索引的更新而苦苦挣扎。我正在尝试的是:
DELETE {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?index .
?slot <http://purl.org/ontology/olo/core#item> ?item
}
INSERT {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?newIndex .
?slot <http://purl.org/ontology/olo/core#item> ?item
}
WHERE {
FILTER(?index >= TARGET_INDEX) # Here would be the numeric value of target index
BIND((?index + 1) AS ?newIndex)
}
即使查询运行完成,插槽的索引也不会更新。任何关于我做错的建议将不胜感激。
注意: Slots 是空白节点,不确定这是否重要,但只是为了确保您了解所有详细信息。
您的 WHERE 没有三重模式,因此它不会产生任何绑定,因此 INSERT 和 DELETE 无事可做。 WHERE 部分需要找到项目、索引等的绑定。仅对于索引部分,您需要 select 所有需要更新索引的插槽及其新索引,然后使用 WHERE 部分执行此操作.然后删除具有旧索引的单个三元组,并插入具有新索引的单个三元组。请注意,您甚至不需要 select ?item 的值,只需要插槽和索引。它看起来像这样:
DELETE {
?slot <http://purl.org/ontology/olo/core#index> ?index .
}
INSERT {
?slot <http://purl.org/ontology/olo/core#index> ?newIndex .
}
WHERE {
<http://listTest> <http://purl.org/ontology/olo/core#slot> ?slot .
?slot a <http://purl.org/ontology/olo/core#Slot> .
?slot <http://purl.org/ontology/olo/core#index> ?index .
FILTER(?index >= TARGET_INDEX) # Here would be the numeric value of target index
BIND((?index + 1) AS ?newIndex)
}