Rdf SPARQL,逗号分隔的参数,用于多个查询对象

Rdf SPARQL,逗号分隔的参数,用于多个查询对象,rdf,sparql,virtuoso,Rdf,Sparql,Virtuoso,我有IRI http://localhost:8080/drinks/coke,百事可乐,芬达 它是自动生成的,我想在下面的对象中重新格式化它,这样我将得到一个如下所示的查询 SELECT * WHERE { ?person ?p <http://localhost:8080/drinks/coke> . ?person ?p <http://localhost:8080/drinks/pepsi> . ?person ?p

我有IRI

http://localhost:8080/drinks/coke,百事可乐,芬达

它是自动生成的,我想在下面的对象中重新格式化它,这样我将得到一个如下所示的查询

SELECT * WHERE 
    {
      ?person ?p <http://localhost:8080/drinks/coke> .
      ?person ?p <http://localhost:8080/drinks/pepsi> .
      ?person ?p <http://localhost:8080/drinks/fanta> .
    }
选择*WHERE
{
人。
人。
人。
}

SPARQL在表达式上没有循环,也没有变量的序列值。 您可以在创建查询字符串或使用字符串操作时设置格式

SELECT * WHERE 
    {
      ?person ?p ?o .
      FILTER STRSTARTS(str(?o), "http://localhost:8080/drinks/") 
    }

如果您想在查询中计算“”,请参见
REPLACE
等。

AndyS的回答是正确的,没有方便的方法可以做到这一点,但是如果您真的必须使用像现有的IRI,则有一些选项。使用正则表达式,可以将IRI的字符串分解为包含所需三个IRI的IRI字符串的字符串:

select ?url ?urls where {
  values ?url { <http://localhost:8080/drinks/coke,pepsi,fanta> }
  bind(replace(str(?url), "(^.*/).*$","$1") as ?prefix)
  bind(concat(",",strafter(str(?url),?prefix)) as ?parts)
  bind(replace(?parts,",",concat(" ",?prefix)) as ?urls)
}

所以基本上这意味着逗号分隔参数的数量应该是固定的?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
| url                                             | urls                                                                                                       |
================================================================================================================================================================
| <http://localhost:8080/drinks/coke,pepsi,fanta> | " http://localhost:8080/drinks/coke http://localhost:8080/drinks/pepsi http://localhost:8080/drinks/fanta" |
----------------------------------------------------------------------------------------------------------------------------------------------------------------
?s ?p ?o .
filter contains(?urls,str(?s))