与SELECT查询用于获取一组变量绑定相似,CONSTRUCT查询用于获取模型。与在SELECT结果集中绑定的变量不会放入任何模型或持久绑定集合中一样,由CONSTRUCT构建的模型也不会存储在任何地方。您需要使用SPARQL 1.1 INSERT。更新功能在3 SPARQL 1.1 Update Language中描述。因此,您的更新请求可以编写为:
INSERT {
GRAPH <http:
?s ?p ?o
}
}
WHERE {
GRAPH <http:
?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.
COPY
的替代方案当然是ADD
,这会将源数据复制到目标位置并保留目标图形的现有数据。 - RobV