SPARQL Query multiple ORs in the same filter

Ok suggests that I have 5 data type properties with integers. These properties are approved by persons belonging to the class "WWS". This class has 4 people. But only some of the properties of a data type exist in these people. How can I request individuals of this class that satisfy as a value of 5. I want the variable to display only those individuals whose properties are satisfied, rest shouldnt be displayed.

Hope this gets clearer!

Thank!

Data:

datatype properties (range:integers): #greaterthantoc #lessthantoc #lowerlimtoc #upperlimtoc #equalstoc

individuals: #ww1, #ww2, #ww3 , #ww4 belong to class #WWS

#ww1 has #greaterthantoc "0"^^xsd:integer
#ww2 has #lessthantoc "5"^^xsd:integer
#ww3 has #greaterthantoc "5"^^xsd:integer
#ww4 has #lowerlimtoc "9"^^xsd:integer and #upperlimtoc "10"^^xsd:integer

Conditions for each property (filter?):
#greaterthantoc <= "a number" 
#lessthantoc >= "a number" 
#lowerlimtoc <= "a number" && #upperlimtoc >= "a number"
#equalstoc = "a number"

Results must be WWS individuals who satisfy some of these conditions. For example, when the number is 4, then the results should be WW1 and WW2

, - , :

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ww:<#>


SELECT ?str

WHERE {?str rdf:type ww:WWS  .

OPTIONAL { ?str ww:greaterthantoc ?gr; ww:lessthantoc ?les ; ww:lowerlimtoc ?low ; ww:upperlimtoc ?up  ; ww:equalstoc ?eq  . } 

FILTER ( ?les >= 3 || ?gr <= 3 || (?low <= 3 && ?up >=3)  || ?eq = 3) 

  } 
+4
1

, (, URI ww:), , , . , , || SPARQL-.

values, , ||:

prefix : <http://stackoverflow.com/q/23561351/1281433/>

select ?s where { 
  values (?s ?gr ?les ?eq ?low ?up) {
    (:s1 3 0 0 0 0)
    (:s2 0 3 0 0 0)
    (:s3 0 0 3 0 0)
    (:s4 0 0 0 3 0)
    (:s5 0 0 0 0 3)
    (:s6 0 0 0 0 0)
    (:s7 1 1 1 1 1)
  }

  filter ( ?eq > 2 || ?les > 2 || ?gr > 2 || ?low > 2 || ?up > 2 )
}

, , :s6 :s7, , . , . :

-------
| s   |
=======
| :s1 |
| :s2 |
| :s3 |
| :s4 |
| :s5 |
-------

, , . , values. , :

select ?s where { 
  ?s :prop1|:prop2|:prop3|:prop4 ?value 
  filter ( ?value > 2 )
}

, :

select ?s where { 
  values ?prop { :prop1 :prop2 :prop3 :prop4 }
  ?s ?prop ?value 
  filter ( ?value > 2 )
}

optional, , , ?s , , , ?s . , ,

?s :prop1 ?value1 ;
   :prop2 ?value2 ;
   :prop3 ?value3 .

?s , :prop1, :prop2 :prop3.

, , , , . . , optional:

select ?s where { 

  ?s a :desiredType .
  optional { ?s :prop1 ?value1 }
  optional { ?s :prop2 ?value2 }
  optional { ?s :prop3 ?value3 }

  filter ( ?value1 > 2 || ?value2 < 5 || ?value3 = 42 )
}
+8

Source: https://habr.com/ru/post/1539897/


All Articles