简体   繁体   English

从两个命名图插入?

[英]insert from two named graphs?

I'm looking for an easy way to insert triples from two or more named graphs (but not the entire unnamed default graph) into another named graph. 我正在寻找一种简单的方法,将两个或多个命名图(而不是整个未命名的默认图)中的三元组插入另一个命名图。 I'm using GraphDB. 我正在使用GraphDB。

I guess this could be done by writing out the same query multiple times in the WHERE section, wrapped in multiple GRAPH specifications, and then unioning them together, but my WHERE s are long and I'd prefer not to write them out multiple times. 我猜这可以通过在WHERE部分中多次写出相同的查询,然后将它们包装在多个GRAPH规范中,然后将它们合并在一起来完成,但是我的WHERE很长,我不希望多次写出它们。

Let's say I have loaded some data like this: 假设我已经加载了一些像这样的数据:

INSERT DATA {
  GRAPH <http://example.com/ngA> {
    <http://example.com/person1> <http://example.com/name> "Arthur" .
  }
  GRAPH <http://example.com/ngB> {
    <http://example.com/person1> <http://example.com/name> "Brian" .
  }
  GRAPH <http://example.com/ngC> {
    <http://example.com/person1> <http://example.com/name> "Charlie" .
  }
}

I can copy all of the triples of a certain pattern from the default unnamed graph into a new named graph with something like this: 我可以将某种模式的所有三元组从默认的未命名图复制到一个新的命名图中,如下所示:

INSERT {
  GRAPH <http://example.com/ngZ> {
    ?s <http://example.com/moniker> ?o .
  }
}
WHERE
  { ?s  <http://example.com/name>  ?o }

An easy way to SELECT for triples of a given pattern from two or more (but not all) named graphs is 从两个或多个(但不是全部)命名的图形中SELECT给定模式的三元组的简单方法是

SELECT  *
FROM <http://example.com/ngA>
FROM <http://example.com/ngB>
WHERE
  { ?s  <http://example.com/name>  ?o }

What if I want to copy those triples, from those specified graphs, into another graph? 如果我要将那些三元组从那些指定的图形复制到另一个图形怎么办?

I'm getting an error from GraphDB 8.3 (and from the sparql.org validator) when I try to 当我尝试从GraphDB 8.3(和sparql.org验证器)收到错误时,

INSERT {
  GRAPH <http://example.com/ngZ> {
    ?s <http://example.com/moniker> ?o .
  }
}
WHERE
  { SELECT  *
FROM <http://example.com/ngA>
FROM <http://example.com/ngB>
WHERE
  { ?s  <http://example.com/name>  ?o } }

Thanks, @Stanislav Kralin 谢谢@Stanislav Kralin

Come to think of it, this also works: 想一想,这也有效:

PREFIX ex: <http://example.com/>
INSERT {
    GRAPH ex:ngZ {
        ?s ex:moniker ?o 
    }
}
WHERE {
    values ?g {
        ex:ngA ex:ngB 
    }
    GRAPH ?g {
        ?s ex:name ?o 
    }  
}

Try this query: 试试这个查询:

PREFIX ex: <http://example.com/>

INSERT {
  GRAPH ex:ngZ { ?s ex:moniker ?o }
}
WHERE {
  GRAPH ?g { ?s ex:name ?o }  
  FILTER (?g IN ( ex:ngA, ex:ngB ) )
}

And then: 接着:

PREFIX ex: <http://example.com/>

SELECT * 
FROM NAMED ex:ngZ
WHERE { 
    GRAPH ?g { ?s ?p ?o }
} LIMIT 100 

Is it what you need? 是你需要的吗?

By the way, there exist COPY (use with caution!) and ADD . 顺便说一下,存在COPY (谨慎使用!)和ADD

SPARQL Update provides USING and USING NAMED analogous to FROM and FROM NAMED in queries: SPARQL Update在查询中提供类似于FROMFROM NAMED USINGUSING NAMED

The USING and USING NAMED clauses affect the RDF Dataset used while evaluating the WHERE clause. USING和USING NAMED子句影响在评估WHERE子句时使用的RDF数据集。 This describes a dataset in the same way as FROM and FROM NAMED clauses 此描述数据集的方式与FROM和FROM NAMED子句相同

You can express the requirement as an UPDATE like so: 您可以将需求表示为UPDATE,如下所示:

INSERT {
  GRAPH <http://example.com/ngZ> {
    ?s <http://example.com/moniker> ?o .
  }
}
USING <http://example.com/ngA>
USING <http://example.com/ngB>
WHERE
  {  ?s  <http://example.com/name>  ?o }

Also note that, according to the SPARQL query grammar , a subquery does not admit a dataset clause. 还要注意,根据SPARQL查询语法 ,子查询不接受数据集子句。 This is why the SPARQL parsers are rejecting your query. 这就是SPARQL解析器拒绝您的查询的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM