SPARQL equivalence for the SQL IN() operator

好久不见. 提交于 2019-12-08 17:02:23

问题


Is there a SPARQL equivalence for the SQL IN() operator? I filter my results and now use:

FILTER ( lang(?label) = 'en' )

I want something like:

FILTER ( lang(?label) IN ('en', 'de') )

Is this possible with SPARQL?


回答1:


In SPARQL 1.1 yes.

FILTER ( lang(?label) IN ('en', 'de') )

should work.

Pre-1.1 you'll need a big disjunction:

FILTER ( (lang(?label) = 'en') || (lang(?label) = 'de') )



回答2:


As per official W3C documentation,

IN

boolean  rdfTerm IN (expression, ...)

The IN operator tests whether the RDF term on the left-hand side is found in the values of list of expressions on the right-hand side. The test is done with "=" operator, which tests for the same value, as determined by the operator mapping.

A list of zero terms on the right-hand side is legal.

Errors in comparisons cause the IN expression to raise an error if the RDF term being tested is not found elsewhere in the list of terms.

The IN operator is equivalent to the SPARQL expression:

(lhs = expression1) || (lhs = expression2) || ...

Examples:

So, IN operator accepts list of vales. Hence below is an example, you can try with SPARQL using FILTER +IN syntax:

SELECT ?s1 
WHERE 
{
      ?s1 rdf:type dbpedia-owl:Scientist.
      FILTER (?s1 IN (<http://example.com/#1>,<http://example.com/#2>, <http://example.com/#3>)) 
 }


来源:https://stackoverflow.com/questions/7214868/sparql-equivalence-for-the-sql-in-operator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!