SPARQL query with/without asterisk

16 views
Skip to first unread message

timmy....@gmail.com

unread,
Jan 23, 2015, 4:41:15 AM1/23/15
to sta...@clarkparsia.com
Hi,

Please check the following SPARQL query:

PREFIX : <http://prefix#>
SELECT
(count(distinct ?subject) as ?amount)
WHERE
{
 
?subject rdf:type :Patient .
 
?subject :has_gender ?gender .
 
?gender rdf:type :MALE .
}

This query returns 0 while in my humble opinion it should not. ?gender is of type "http://prefix#MALE" as verified by the query below. This query does return the correct amount of patients.

PREFIX : <http://prefix#>
SELECT
(count(distinct ?subject) as ?amount)
WHERE
{
 
?subject rdf:type :Patient .
 
?subject :has_gender ?gender .
  FILTER
(str(?gender) = "http://prefix#MALE")
}

The only way I can get my original query to work, is by adding an asterisk after rdf:type. Why is this necessary? Thanks!

Héctor Pérez-Urbina

unread,
Jan 23, 2015, 9:19:44 AM1/23/15
to stardog
Hello,

Can you send us the ontology you're querying?

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en



--
Best,
Héctor

Timmy Storms

unread,
Jan 23, 2015, 10:30:19 AM1/23/15
to sta...@clarkparsia.com
Hi Héctor,

Actually, all triples are derived from an odba file, as we were testing ontop previously. We also have an ontology in place, but it is not needed for this basic query.

Don't you agree that the query should work? Is there some more info you'd require?

Thanks,
Timmy

Héctor Pérez-Urbina

unread,
Jan 23, 2015, 11:02:47 AM1/23/15
to stardog
Timmy,

Since the second query is giving you some results, I assume your data is of the form

:a1 a :Patient ;
:has_gender :MALE .

Therefore, the query binds ?gender to :MALE.

Your first query, however, assumes that the underlying data is of the form

:m a :MALE .

:a1 a :Patient ;
:has_gender :m .

That is, the query is trying to bind ?gender to something that is of type :MALE, which explains the empty results. 

By the way, given the usual semantics of gender, I would suggest to do something like

:a1 a :Patient, :Male .

and use the query

PREFIX : <http://prefix#>
SELECT (count(distinct ?subject) as ?amount)
WHERE {
  ?subject a :Patient, :Male .
}
Reply all
Reply to author
Forward
0 new messages