SPARQL functions in CONSTRUCT/WHERE

时间秒杀一切 提交于 2019-11-27 09:43:47
RobV

Yes this is possible

You can't use expressions directly in a CONSTRUCT template but you can assign the variable in the WHERE clause either via a SELECT expression in a sub-query or using BIND.

In your case as GROUP_CONCAT is an aggregate it can only be a SELECT expression so you just need to put your entire SELECT as a sub-query e.g.

PREFIX dc: <http://purl.org/dc/elements/1.1/>    

CONSTRUCT
{
  <http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163> <http://fancyTitle> ?fancytitle
}
WHERE
{
  SELECT (group_concat(?title ; separator = " ") AS ?fancytitle) WHERE { 
    GRAPH ?graph {
      <http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163>  dc:relation+ ?relation .
      ?relation dc:title ?title .
    }
  }
}

The above works fine on your endpoint

With the help of my colleague we got it to work, UNION and GROUP BY are essential. This query puts the string together for all locah:ArchivalResource in the graphs:

CONSTRUCT
{
  ?archresource skos:hiddenLabel ?supertitle
}
WHERE
{
  SELECT ?archresource  (group_concat(?title ; separator = ", ") AS ?supertitle) WHERE {
    GRAPH ?graph {
      {
        SELECT ?title ?archresource WHERE {
          GRAPH ?graph {
            {
              ?archresource a locah:ArchivalResource ;
              dc:title ?title .
            } UNION
            {
              ?archresource dc:relation+ ?relation .
              ?relation dc:title ?title .
            }
          }
        }
      }
    }
  } GROUP BY ?archresource
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!