SPARQL 是否可以将两个变量及其标签与静态文本绑定在一起?

SPARQL is it possible to bind two variables with their labels with a static text?

这是我的查询

PREFIX : <http://example.org/rs#>

select ?item (SUM(?similarity) as ?summedSimilarity) 
(group_concat(distinct ?becauseOf ; separator = " , ") as ?reason) where
{
  values ?x {:instance1}
  {
    ?x  ?p  ?instance.
    ?item   ?p  ?instance.
    ?p  :hasSimilarityValue ?similarity
      bind (?p as ?becauseOf)
  }
  union
  {
    ?x  a   ?class.
    ?item   a   ?class.
    ?class  :hasSimilarityValue ?similarity
      bind (?class as ?becauseOf)
  }
  filter (?x != ?item)
}
group by ?item

在我的第一个bind 子句中,我不仅要绑定变量?p,还要绑定变量?instance。另外,添加像 that is why.

这样的文本

所以第一次绑定应该产生以下结果: ?p that is why ?instance

在 SPARQL 中可能吗?

请不要在意数据是否合理,这只是向您展示我的问题的查询

如果我没理解错的话,您只是在寻找 concat function. As I've mentioned before, you should really browse through the SPARQL 1.1 standard,至少是通过 table 的内容。你不需要记住它,但它会让你知道什么是可能的,以及在哪里寻找的想法。此外,如果您提供我们可以使用的示例数据,非常有帮助,因为它更清楚弄清楚您在尝试什么去做。您标题的措辞不是特别清楚,而且这个问题并没有真正提供您要完成的任务的示例。只是因为我看过你过去的一些问题,我才知道你的目标是什么。无论如何,这里有一些数据:

@prefix : <urn:ex:>

:p :hasSimilarity 0.3 .
:A :hasSimilarity 0.6 .

:a :p :b ;  #-- is is related to :b
   a  :A .  #-- and is an :A .

:c :p :b .  #-- :c is also related to :b

:d a :A .   #-- :d is also an :A .

:e :p :b ;  #-- :e is related to :b 
   a  :A .  #-- and is also an :A .

这是查询及其结果。您只需使用 concat 将变量的 str 形式与适当的字符串连接起来,然后 bind结果到变量。

prefix : <urn:ex:>

select ?item
       (sum(?factor_) as ?factor)
       (group_concat(distinct ?reason_; separator=", ") as ?reason)
{
  values ?x { :a }

  { ?x    ?p ?instance .
    ?item ?p ?instance .
    ?p :hasSimilarity ?factor_ .
    bind(concat("has common ",str(?p)," value ",str(?instance)) as ?reason_) }
  union
  { ?x     a ?class.
    ?item  a ?class.
    ?class :hasSimilarity ?factor_ .
    bind(concat("has common class ",str(?class)) as ?reason_)
  }
  filter (?x != ?item)
}
group by ?item
-----------------------------------------------------------------------------------
| item | factor | reason                                                          |
===================================================================================
| :c   | 0.3    | "has common urn:ex:p value urn:ex:b"                            |
| :d   | 0.6    | "has common class urn:ex:A"                                     |
| :e   | 0.9    | "has common urn:ex:p value urn:ex:b, has common class urn:ex:A" |
-----------------------------------------------------------------------------------