“or” in a SPARQL query

前端 未结 2 1831
野趣味
野趣味 2021-02-02 09:35

I don\'t quite understand why in SPARQL they haven\'t implemented the basic logic operators. However in most of the cases is possible to obtain the same result in a number of wa

2条回答
  •  温柔的废话
    2021-02-02 09:55

    If you want to trace which predicate lead to which object then this is universal solution for "OR" :

    SELECT DISTINCT ?s ?o1 ?o2 
    WHERE {
      {
         ?s p1 ?o1 .
         OPTIONAL
         {
            ?s p2 ?o2 .
         }
      } 
      UNION 
      {
         ?s p2 ?o2 .
         OPTIONAL
         {
            ?s p1 ?o1 .
         }
      }
    }
    

提交回复
热议问题