First, it's much easier to help if you provide complete SPARQL queries, including prefixes (especially since you're using some non-standard ones), or if you use the same prefixes that the public endpoint UI does (see http://dbpedia.org/sparql?nsdecl). It's not immediately clear what dbpedia2
is, etc. (although I realize now that dbpedia2
is defined in the SNORQL explorer that you linked to).
Also, note that while Virtuoso may accept your queries, they're not all actually legal SPARQL. E.g., if you take your first query and go to http://sparql.org/validate/query, you'll see that the variable projection syntax isn't legal. It needs to be
select (count(distinct(?ma)) as ?people) ?University where
where the … as ?people
is wrapped in parentheses, and there is no comma between the variables. (It's not a problem, but you can also use count(distinct ?ma)
and save two parentheses.)
Next, since DBpedia data is based on Wikipedia, and that means that it can be a bit mixed up at times, it's always a good idea to browse the data a bit to find the best way to identify things. In this case, by looking at http://dbpedia.org/page/Angela_Perez_Baraquio, it appears that a good way to identify Miss America winners it to look for persons that have dcterms:subject category:Miss_America_winners
. Thus, we have a query like:
select ?person where {
?person a dbpedia-owl:Person ;
dcterms:subject category:Miss_America_winners
}
Now, not all of these will have clean education/alma mater/etc., information, but you can use an alternation property path with |
to use any number of properties. Then you'd end up with a query like this (for three properties):
select ?education (count(distinct ?person) as ?numWinners) where {
?person a dbpedia-owl:Person ;
dcterms:subject category:Miss_America_winners .
optional {
?person dbpprop:education|dbpprop:almaMater|dbpedia-owl:almaMater ?education
}
}
group by ?education
It's not particularly enlightening; the biggest commonality is of people without values for those properties. For the other values, there's a mix of strings and resources. If nothing else, there are two for the University of Mississippi.
Selecting values of properties where there's a preference among the properties is actually not entirely trivial in SPARQL, and it's been discussed in this answers.semanticweb.com question: Preference patterns for SPARQL (1.1). There are a few ways to do it, but I think the easiest here is to match all the properties in optional blocks, and then coalesce
them into one:
select ?person ?education where {
?person a dbpedia-owl:Person ;
dcterms:subject category:Miss_America_winners .
optional { ?person dbpedia-owl:almaMater ?ed1 }
optional { ?person dbpprop:almaMater ?ed2 }
optional { ?person dbpprop:education ?ed3 }
bind( coalesce(?ed1,?ed2,?ed3) as ?education )
}
For individuals who have values for more than one of these properties, we get the preferred property. E.g., for http://dbpedia.org/resource/Angela_Perez_Baraquio we get the dbpedia-owl:almaMater
, http://dbpedia.org/resource/University_of_Hawaii. For cases there there are multiple values for the best property, we still get all of them. E.g., for http://dbpedia.org/resource/Kylene_Barker, we get both http://dbpedia.org/resource/Virginia_Tech and http://dbpedia.org/resource/Carroll_County_High_School_(Hillsville,_Virginia).