Count entities without labels
Info |
---|
|
This material pertains to outdated versions of VIVO. Rather than archiving the material, it should be updated to reflect current versions of VIVO. |
These examples show how to count the entities in your VIVO that do not have labels. In each query, the entities of interest are selected using type, then OPTIONAL is used to include entities with and without labels, FILTER is used to select only those results for which there is no label value, that is, ?label is not bound.
The resulting collection of entities is counted using COUNT(DISTINCT ?s) in the SELECT statement.
The same pattern can be used to count grants (vivo:Grant), organizations (foaf:Organization), or people (foaf:Person) with labels.
Code Block |
---|
title | Count agents without labels |
---|
|
SELECT count(COUNT(DISTINCT ?s) AS ?count)
WHERE {
?s rdf:type foaf:Agent .
OPTIONAL {?s rdfs:label ?label .}
FILTER(!bound(?label))
} |
Code Block |
---|
title | Count grants information resources without labels |
---|
|
SELECT count(COUNT(DISTINCT ?s) AS ?count)
WHERE {
?s rdf:type vivo:GrantInformationResource .
OPTIONAL {?s rdfs:label ?label .}
FILTER(!bound(?label))
} |
Using a nested query to get multiple counts
The above queries can be combined in a single query which returns multiple counts.
Code Block |
---|
title | Count positions without labelsUsing a nested query to get multiple counts |
---|
|
SELECT ?count_agents ?count_information_resources
WHERE {
{
SELECT (COUNT(DISTINCT ?s) AS ?count_agents)
WHERE {
?s rdf:type vivofoaf:PositionAgent .
OPTIONAL {?s rdfs:label ?label .}
FILTER(!bound(?label))
}
} |
Code Block |
---|
title | Count publications without labels |
---|
|
SELECT count(?s)
}
{
SELECT (COUNT(DISTINCT ?s) AS ?count_information_resources)
WHERE {
?s rdf:type vivo:InformationResource .
OPTIONAL {?s rdfs:label ?label .}
FILTER(!bound(?label))
}
}
} |