-1

I am struggling with getting literal device names from my RDF base with smartphone data. Example data:

<rdf:Description rdf:about="https://lukasgorny.pro/devices#GioneeX1">
    <feature:device-name>Gionee X1</feature:device-name>
    <feature:screen-size>big</feature:screen-size>
    <feature:internal-memory-size>small</feature:internal-memory-size>
 </rdf:Description>
 <rdf:Description rdf:about="https://lukasgorny.pro/devices#SharpAquosS3">
    <feature:device-name>Sharp Aquos S3</feature:device-name>
    <feature:screen-size>big</feature:screen-size>
    <feature:internal-memory-size>big</feature:internal-memory-size>
 </rdf:Description>

Query:

PREFIX feature: <https://lukasgorny.pro/devices#>

SELECT ?device WHERE 
{ 
    ?device feature:device-name ?deviceName .
    OPTIONAL { ?x feature:screen-size ?screenSize . } 
    OPTIONAL { ?y feature:internal-memory-size ?memorySize . }
}

I want to extract all device names which screen-size is "big" and internal-memory-size is "small" (those are parametrized in my application, but I'm giving you an example here). Can you kindly point me in the right direction? I can't seem to find a solution.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Possible duplicate of [Exact matching of strings in SPARQL?](https://stackoverflow.com/questions/2591719/exact-matching-of-strings-in-sparql) – Jeen Broekstra Sep 18 '17 at 04:23
  • 2
    What is the goal of the `OPTIONAL` clauses? those are not connected to any variable of the outer triple pattern. – UninformedUser Sep 18 '17 at 06:53

1 Answers1

1

You can use a FILTER condition for this, like so:

 WHERE 
 { 
    ?x feature:screen-size ?screenSize . 
    FILTER(str(?screenSize) = "big") 
 } 
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • Works nice, but what about multi filters? Here's my code and it seems to be not working: https://pastebin.com/2J0vEVBB It always returns me 93 entries. – Łukaszov Pietriej Gornyov Sep 18 '17 at 08:09
  • 2
    It's the same as with the `OPTIONAL` clauses in your initial query. Why do you use different variables `?x` and `?y`? Triple patterns have to be "connected" by shared variables – UninformedUser Sep 18 '17 at 12:53
  • @ŁukaszovPietriejGornyov as @AKSW also suggested, you need to change the `?x` and the `?y` variables in your query to `?device`. The whole point is that you're querying three properties of the same subject, after all. Also: get rid of the OPTIONAL clauses. – Jeen Broekstra Sep 20 '17 at 00:58
  • Also, just `where { ?x feature:screen-size "big" }`, or (especially helpful if there are multiple values: `where { values ?screenSize { "big" "bigger" } ?x feature:screen-size ?screenSize }`. – Joshua Taylor Sep 22 '17 at 17:36