4

有没有办法在使用 SPARQL 时使用一种占位符变量而不返回它SELECT *

例如:

SELECT * WHERE { 
   ?s dcterms:title ?title; 
      foaf:person ?name. 
   ?s2 :inProject ?s. 
}

在我不想返回?s变量的地方,只返回?title?name?s2变量,同时离开SELECT *.

我知道我可以通过使用来限制选择结果SELECT ?title ?name ...,但我只是好奇是否有某种占位符变量的表示法或某种方式来管理它。


编辑:

我了解您可以在某些情况下使用空白节点来完成此操作,例如:

SELECT * WHERE { 
   _:s dcterms:title ?title; 
       foaf:person ?name. 
   ?s2 :inProject _:s. 
}

但是,由于空白节点不能跨基本图形模式使用,这不会引起问题吗?例如,这在这种情况下会中断:

SELECT * WHERE { 
   _:s dcterms:title ?title; 
       foaf:person ?name. 
   OPTIONAL { ?s2 :inProject _:s. }
}

谢谢!

4

1 回答 1

2

For variables scoped to a single pattern yes, use the blank node variable syntax as you demonstrated in your question

In the general case no, if you use a variable then SELECT * will return it.

One possible workaround is to use sub-queries where you do list variables and leave out the variables you don't want e.g.

SELECT * WHERE
{ 
  {
    SELECT ?title ?name ?s2 WHERE 
    {
      ?s dcterms:title ?title; 
      foaf:person ?name. 
      OPTIONAL{ ?s2 :inProject ?s. }
    }
  }
}

But then I assume this is exactly what you are trying to avoid since you end up listing variables anyway.

于 2013-02-21T22:59:00.590 回答