1

我想替换存储在基于 Jena 的三重存储中的所有主题的服务器。

我试过这种方式,但服务器没有被更换......

DELETE { ?s ?p ?o }
INSERT { ?s1 ?p ?o }
WHERE { 
    { SELECT (uri(concat('http://localhost:8080/', SUBSTR(str(?s),22))) AS ?s1) 
        { 
          ?s ?p ?o . 
          FILTER regex(str(?s), '^https://somedomain.org/')
        }
     }
}

当我只运行以下查询时

SELECT (uri(concat('http://localhost:8080/', SUBSTR(str(?s),22)) ) AS ?s1) ?s 
{ 
  ?s ?p ?o . 
  FILTER regex(str(?s), '^https://somedomain.org/')
}

'?s' 和 '?s1' 确实有正确的值。

似乎“?s”和“?s1”在 DELETE/INSERT 块中不可用。我的更新查询有什么问题?

4

1 回答 1

1

您的问题是您在更新中使用了子查询,并且您仅从子查询中进行投影?s1

这意味着?s,?p并且?o在子查询之外不可见。因此,当DELETEINSERT模板尝试构建三元组以删除和插入它们构建的所有三元组时是无效的(因为并非所有变量都是可见的),因此没有任何变化。

要解决此问题,您应该投影所有相关变量:

DELETE { ?s ?p ?o }
INSERT { ?s1 ?p ?o }
WHERE 
{ 
  {
    SELECT ?s ?p ?o (uri(concat('http://localhost:8080/', SUBSTR(str(?s),22))) AS ?s1) 
    { 
      ?s ?p ?o . 
      FILTER regex(str(?s), '^https://somedomain.org/')
    }
  }
}

或从评论中遵循Joshua Taylor 的建议。这实际上更好,因为它简化了整体查询:

DELETE { ?s ?p ?o }
INSERT { ?s1 ?p ?o }
WHERE 
{ 
  ?s ?p ?o . 
  FILTER regex(str(?s), '^https://somedomain.org/')
  BIND(uri(concat('http://localhost:8080/', SUBSTR(str(?s),22))) AS ?s1)
}
于 2015-09-09T10:35:26.483 回答