gpt4 book ai didi

sparql - 构造成命名图

转载 作者:行者123 更新时间:2023-12-03 20:27:47 24 4
gpt4 key购买 nike

我正在尝试使用 SPARQL Construct 查询从现有的命名图创建一个新的命名图。我正在查询的数据库包含 http://graph.com/old作为现有的命名图。我正在使用 耶拿 TDB 作为数据库,通过 访问Jena Fuseki 端点。下面的查询给了我一个错误:

CONSTRUCT
{
GRAPH <http://graph.com/new> {
?s ?p ?o
}
}

WHERE
{
GRAPH <http://graph.com/old> {
?s ?p ?o
}
}

如果我从 CONSTRUCT block 中删除图形语句,查询将完美运行,但我想将三元组放入我指定的命名图形中,而不是默认图形。

据我所知, SPARQL 1.1 section on CONSTRUCT没有说任何关于构建命名图的内容。有没有办法做到这一点?

最佳答案

就像当您有兴趣返回一组变量绑定(bind)时使用 SELECT 查询一样,使用 CONSTRUCT 查询您有兴趣返回一个模型。就像绑定(bind)在 SELECT 结果集中的变量不会放入任何模型或持久绑定(bind)集一样,由 CONSTRUCT 构建的模型也不会存储在任何地方。您想使用 SPARQL 1.1 INSERT。 3 SPARQL 1.1 Update Language 中描述了更新功能.因此,您的更新请求可以写成:

INSERT {
GRAPH <http://graph.com/new> {
?s ?p ?o
}
}
WHERE {
GRAPH <http://graph.com/old> {
?s ?p ?o
}
}

不过,对于这种特殊情况,您也许可以使用 3.2.3 COPY 中描述的 COPY 操作。 . COPY 首先从目标图中删除所有数据,因此它可能不适用于您的实际情况(请理解您提供的代码可能是一个最小示例,不一定是您尝试执行的实际更新)。关于 COPY 标准说:

The COPY operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, but data from the destination graph, if any, is removed before insertion.

COPY ( SILENT )? ( ( GRAPH )? IRIref_from | DEFAULT) TO ( ( GRAPH )? IRIref_to | DEFAULT )

is similar in operation to:

DROP SILENT (GRAPH IRIref_to | DEFAULT);
INSERT { ( GRAPH IRIref_to )? { ?s ?p ?o } } WHERE { ( GRAPH IRIref_from )? { ?s ?p ?o } }

The difference between COPY and the DROP/INSERT combination is that if COPY is used to copy a graph onto itself then no operation will be performed and the data will be left as it was. Using DROP/INSERT in this situation would result in an empty graph.

If the destination graph does not exist, it will be created. By default, the service may return failure if the input graph does not exist. If SILENT is present, the result of the operation will always be success.



如果 COPY 不合适,那么 ADD可能是您正在寻找的:

3.2.5 ADD

The ADD operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, and initial data from the destination graph, if any, is kept intact.

ADD ( SILENT )? ( ( GRAPH )? IRIref_from | DEFAULT) TO ( ( GRAPH )? IRIref_to | DEFAULT)

is equivalent to:

INSERT { ( GRAPH IRIref_to )? { ?s ?p ?o } } WHERE { ( GRAPH IRIref_from )? { ?s ?p ?o } }

If the destination graph does not exist, it will be created. By default, the service may return failure if the input graph does not exist. If SILENT is present, the result of the operation will always be success.

关于sparql - 构造成命名图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18345908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com