Select SPARQL 中的文字?

Select literal in SPARQL?

我想构建一个 SPARQL 查询,其中填充了我设置为文字的值。

例如

SELECT 'A', 'B', attribute
FROM 
    TABLE

return table 会像这样吗:

  A    |    B    |    attribute
-------|---------|--------------
  A    |    B    |    Mary
  A    |    B    |    has
  A    |    B    |    a
  A    |    B    |    little
  A    |    B    |    lamb

我想要做的是运行这样的查询来获取三元组中的所有对象类型:

select distinct ?o ("class" as ?item_type) 
where {
    ?s rdf:type ?o.
} 

然后(理想情况下)将其与第二个查询联合起来,提取所有不同的谓词值:

select distinct ?p ("predicate" as ?item_type) 
where {
    ?s ?p ?o.
} 

其结果可能如下所示:

  item           |    item_type    
-----------------|-----------------
 a_thing         |    class
another_thing    |    class
a_relation       |    predicate
another_relation |    predicate

但是 SPARQL 中的 UNION 仅在附加的 where 子句中链接,这意味着我无法指定要注入结果集中的 item_type 文字。

我认为以下应该能满足您的需求:

SELECT DISTINCT ?item ?item_type
WHERE {
   { ?s a ?item .
     BIND("class" AS ?item_type)
   }
   UNION
   { ?s ?item ?o
     BIND("predicate" AS ?item_type)
   }

}